Expandable section 컴포넌트
Expandable section은 사용자가 한 섹션을 펼치거나 접을 수 있게 해주는 컴포넌트예요. 기본, 푸터, 컨테이너, 스택형 등 여러 변형을 제공하며 페이지 길이를 줄이기 위해 보조 콘텐츠를 담는 데 사용된답니다.
출처: 문서
본문
개발 가이드라인
상태 관리
기본적으로 expandable section 컴포넌트는 클릭하면 자동으로 펼쳐지고 접힙니다.
이 동작을 제어하려면 expanded 속성을 명시적으로 설정하고 onChange 리스너를 제공해야 해요.
기본 펼침 상태만 설정하려면 defaultExpanded 속성을 설정할 수 있습니다. 그러면 컴포넌트는 클릭 시 자동으로 펼쳐지고 접힙니다.
Cloudscape 컴포넌트의 상태 관리에 대해 자세히 알아보세요.
단위 테스트 예제
Expandable section 선택하기
import { render } from '@testing-library/react';
import createWrapper from '@cloudscape-design/components/test-utils/dom';
import ExpandableSection from '@cloudscape-design/components/expandable-section';
describe('<ExpandableSection />', () => {
it('renders the expandable-section component', () => {
const { container } = render(<ExpandableSection />);
const wrapper = createWrapper(container);
expect(wrapper.findExpandableSection()).toBeTruthy();
});
it('selects all expandable-section components', () => {
const { container } = render(<>
<ExpandableSection />
<ExpandableSection />
<ExpandableSection />
</>);
const wrapper = createWrapper(container);
const components = wrapper.findAllExpandableSections();
expect(components).toHaveLength(3)
});
});
Expandable section 펼치기
import ExpandableSection from '@cloudscape-design/components/expandable-section';
import createWrapper from '@cloudscape-design/components/test-utils/dom';
import { render } from '@testing-library/react';
function Component() {
return <ExpandableSection defaultExpanded={false}>Expandable content</ExpandableSection>;
}
describe('<ExpandableSection />', () => {
it('expands the expandable section', async () => {
const { container } = render(<Component />);
const wrapper = createWrapper(container);
wrapper.findExpandableSection()!.findExpandButton().click();
const expandableContent = wrapper.findExpandableSection()!.findExpandedContent()!;
expect(expandableContent.getElement().textContent).toBe('Expandable content');
});
});
Expandable section 접기
import ExpandableSection from '@cloudscape-design/components/expandable-section';
import createWrapper from '@cloudscape-design/components/test-utils/dom';
import { render } from '@testing-library/react';
function Component() {
return <ExpandableSection defaultExpanded={true}>Expandable content</ExpandableSection>;
}
describe('<ExpandableSection />', () => {
it('collapses the expandable section', async () => {
const { container } = render(<Component />);
const wrapper = createWrapper(container);
wrapper.findExpandableSection()!.findExpandButton().click();
const expandableContent = wrapper.findExpandableSection()!.findExpandedContent();
expect(expandableContent).toBeNull();
});
});
헤더 선택하기
import ExpandableSection from '@cloudscape-design/components/expandable-section';
import createWrapper from '@cloudscape-design/components/test-utils/dom';
import { render } from '@testing-library/react';
function Component() {
return <ExpandableSection headerText="Test header text">Test content</ExpandableSection>;
}
describe('<ExpandableSection />', () => {
it('renders the header text', () => {
const { container } = render(<Component />);
const wrapper = createWrapper(container);
const headerText = wrapper.findExpandableSection()!.findHeaderText()!;
expect(headerText.getElement().textContent).toBe('Test header text');
});
});
단위 테스트 API
ExpandableSectionWrapper
| 이름 | 반환 타입 | 설명 | 파라미터 |
|---|---|---|---|
| findContent | ElementWrapper | - | - |
| findExpandButton | ElementWrapper | - | - |
| findExpandedContent | ElementWrapper | null | - | - |
| findExpandIcon | ElementWrapper | - | - |
| findHeader | ElementWrapper | - | - |
| findHeaderDescription | ElementWrapper | null | - | - |
| findHeaderText | ElementWrapper | null | - | - |
통합 테스트 예제
Expandable section 펼치기
import createWrapper from '@cloudscape-design/components/test-utils/selectors';
/**
* browser - is a global object representing your testing framework.
* The exact API could be different for your stack.
*/
describe('ExpandableSection', () => {
it('expands the expandable section', async () => {
/**
* This code tests the <ExpandableSection defaultExpanded={false} />
* Check the playground: /components/expandable-section/?tabId=playground&example=default
*/
await browser.url('your-test-page');
const wrapper = createWrapper();
const expandButtonSelector = wrapper.findExpandableSection().findExpandButton().toSelector();
await browser.$(expandButtonSelector).click();
const expandableContentSelector = wrapper.findExpandableSection().findExpandedContent().toSelector();
const expandableContent = await browser.$(expandableContentSelector).getText();
expect(expandableContent).toBe('Expandable content');
});
});
Expandable section 접기
import createWrapper from '@cloudscape-design/components/test-utils/selectors';
/**
* browser - is a global object representing your testing framework.
* The exact API could be different for your stack.
*/
describe('ExpandableSection', () => {
it('collapses the expandable section', async () => {
/**
* This code tests the <ExpandableSection defaultExpanded={true} />
* Check the playground: /components/expandable-section/?tabId=playground&example=default
*/
await browser.url('your-test-page');
const wrapper = createWrapper();
const expandButtonSelector = wrapper.findExpandableSection().findExpandButton().toSelector();
await browser.$(expandButtonSelector).click();
const expandableContent = wrapper.findExpandableSection().findExpandedContent().toSelector();
const isExpanded = await browser.$(expandableContent).isExisting();
expect(isExpanded).toBe(false);
});
});
헤더 선택하기
import createWrapper from '@cloudscape-design/components/test-utils/selectors';
/**
* browser - is a global object representing your testing framework.
* The exact API could be different for your stack.
*/
describe('ExpandableSection', () => {
it('renders the header text', async () => {
/**
* This code tests the <ExpandableSection headerText="Test header text" />
* Check the playground: /components/expandable-section/?tabId=playground&example=default
*/
await browser.url('your-test-page');
const wrapper = createWrapper();
const headerTextSelector = wrapper.findExpandableSection()!.findHeaderText().toSelector();
const headerText = await browser.$(headerTextSelector).getText();
expect(headerText).toBe('Test header text');
});
});
통합 테스트 API
ExpandableSectionWrapper
| 이름 | 반환 타입 | 설명 | 파라미터 |
|---|---|---|---|
| findContent | ElementWrapper | - | - |
| findExpandButton | ElementWrapper | - | - |
| findExpandedContent | ElementWrapper | - | - |
| findExpandIcon | ElementWrapper | - | - |
| findHeader | ElementWrapper | - | - |
| findHeaderDescription | ElementWrapper | - | - |
| findHeaderText | ElementWrapper | - | - |
일반 가이드라인
권장 사항
- 사용자가 한 번에 하나 이상의 섹션을 볼 수 있도록 expandable section을 사용하세요.
- Expandable section에는 보조 콘텐츠만 포함하세요.
- 페이지 길이를 줄이기 위해 인터페이스의 관련 항목 아래에 expandable section을 사용하세요. 예로는 폼의 고급 구성이 있어요. 인접한 모든 콘텐츠는 페이지 아래로 세로로 밀려납니다.
- Expandable section은 기본적으로 접혀 있습니다.
권장하지 않는 사항
- 오류 메시지나 중요한 정보를 expandable section 아래에 숨기지 마세요.
- Expandable section을 중첩하지 마세요.
- 테이블 안에서 expandable section을 사용하지 마세요. 대신 확장 가능한 행이 있는 테이블을 사용하세요.
- 기본 expandable section 헤더에 액션을 두 개 이상 사용하지 마세요. 더 필요하다면 인라인 아이콘 버튼 드롭다운을 사용하세요.
기능
-
변형(Variant)
- Default: 페이지 수준이나 container 안에 배치할 수 있어요. 헤더에 설명과 액션 같은 추가 선택 요소도 허용합니다.
- Footer: 폼 내 container의 푸터용입니다.
- Container: 자체 시각적 container를 가져요. 리소스 생성 흐름 같은 다른 container의 맥락에서 사용됩니다. 헤더에 설명, 카운터, 정보 링크, 액션 같은 추가 선택 요소도 허용합니다.
- Stacked: 다른 스택형 컴포넌트 옆에 표시되도록 최적화되었습니다.
-
액션 - 선택 사항
액션은 default 및 container 변형에서 사용할 수 있어요.
- Default: 인라인 버튼과 인라인 버튼 드롭다운을 사용하세요. 예를 들어 섹션을 제거하는 액션 같은 것에요.
- Container: 헤더의 액션에 대한 가이드라인을 따르세요.
작성 가이드라인
일반 작성 가이드라인
-
문장형 대소문자(sentence case)를 사용하되, 고유 명사와 브랜드 이름은 맥락에 맞게 대문자를 계속 사용하세요.
-
현재 시제 동사와 능동태를 사용하세요.
-
글에서 please, thank you, 줄임표( ...), 앰퍼샌드( &), e.g., i.e., *etc.*를 사용하지 마세요.
-
방향을 암시하는 언어를 피하세요.
- 예: above 대신 previous를 사용하고, below 대신 following을 사용하세요.
-
기기에 독립적인 언어를 사용하세요.
- 예: click 대신 choose 또는 select를 사용하세요.
접근성 가이드라인
일반 접근성 가이드라인
- 각 컴포넌트에 대한 대체 텍스트 및 ARIA(Accessible Rich Internet Applications) 영역의 가이드라인을 따르세요.
- 애플리케이션의 언어 맥락에 맞는 ARIA 레이블을 정의하세요.
- 역할(role)과 랜드마크에 불필요한 마크업을 추가하지 마세요. 각 컴포넌트의 가이드라인을 따르세요.
- 모든 콘텐츠에 대해 논리적이고 예측 가능한 순서로 키보드 기능을 제공하세요. 정보의 흐름이 이해하기 쉬워야 해요.
컴포넌트별 가이드라인
대체 텍스트
- 불필요한 대체 텍스트나 역할을 제공하지 마세요. 캐럿 아이콘은 이미 컴포넌트의 일부입니다.