Pagination 컴포넌트
Pagination은 컬렉션의 페이지 사이를 가로로 이동할 수 있게 해 주는 컴포넌트예요. 테이블, 카드, 목록 같은 다양한 컬렉션 뷰에서 흔히 사용돼요. 기본 컨트롤(화살표, 번호, 줄임표)과 함께 open end 방식, jump to page, compact 변형을 설명하고, 개발·단위 테스트 및 접근성 가이드라인을 함께 제공해요.
출처: 문서
본문
Pagination
Provides horizontal navigation between pages of a collection.
컬렉션의 페이지 사이를 가로로 이동할 수 있게 해 줘요.
Development guidelines
이 컴포넌트는 페이지네이션 UI만 표시해요. 실제 데이터 페이지네이션을 수행하려면 collection hooks를 사용하는 것을 고려하세요.
State management
페이지네이션 컴포넌트는 제어(controlled) 방식이에요. currentPageIndex 속성을 설정하고 onChange 리스너를 사용해서 그 값을 애플리케이션의 상태에 저장하세요. Cloudscape 컴포넌트의 상태 관리에 대해 더 자세히 알아보세요.
테스트 유틸리티 클래스가 처음이라면 소개 문서에서 더 자세히 알아볼 수 있어요.
Unit testing examples
페이지네이션 선택하기
import { render } from '@testing-library/react';
import createWrapper from '@cloudscape-design/components/test-utils/dom';
import Pagination from '@cloudscape-design/components/pagination';
describe('<Pagination />', () => {
it('renders the pagination component', () => {
const { container } = render(<Pagination />);
const wrapper = createWrapper(container);
expect(wrapper.findPagination()).toBeTruthy();
});
it('selects all pagination components', () => {
const { container } = render(<>
<Pagination />
<Pagination />
<Pagination />
</>);
const wrapper = createWrapper(container);
const components = wrapper.findAllPaginations();
expect(components).toHaveLength(3)
});
});
페이지 번호로 이동하기
import Box from '@cloudscape-design/components/box';
import Container from '@cloudscape-design/components/container';
import Pagination from '@cloudscape-design/components/pagination';
import createWrapper from '@cloudscape-design/components/test-utils/dom';
import { render } from '@testing-library/react';
import { useState } from 'react';
interface Item {
header: string;
content: string;
}
const pages: Item[] = [
{ header: 'First page', content: 'Page 1 content' },
{ header: 'Second page', content: 'Page 2 content' },
{ header: 'Third page', content: 'Page 3 content' },
{ header: 'Fourth page', content: 'Page 4 content' },
];
function Component() {
const [pageIndex, setPageIndex] = useState(1);
const page = pages[pageIndex - 1];
return (
<Box>
<Container header={page.header}>{page.content}</Container>
<Pagination
pagesCount={pages.length}
currentPageIndex={pageIndex}
onChange={({ detail }) => {
setPageIndex(detail.currentPageIndex);
}}
/>
</Box>
);
}
describe('<Pagination />', () => {
it('navigates to the third page by its number', () => {
const { container } = render(<Component />);
const wrapper = createWrapper(container);
wrapper.findPagination()!.findPageNumberByIndex(3)!.click();
const pageContent = wrapper.findContainer()!.findHeader()!.getElement();
expect(pageContent.textContent).toBe('Third page');
});
});
Unit testing APIs
PaginationWrapper
| Name | Return type | Description | Parameters |
|---|---|---|---|
| findCurrentPage | PaginationButtonWrapper | - | - |
| findJumpToPageButton | ButtonWrapper | null | 점프 투 페이지 제출 버튼을 반환합니다. | - |
| findJumpToPageInput | InputWrapper | null | 점프 투 페이지 입력 필드를 반환합니다. | - |
| findJumpToPagePopover | PopoverWrapper | null | 점프 투 페이지용 오류 팝오버를 반환합니다. | - |
| findNextPageButton | PaginationButtonWrapper | - | - |
| findPageNumberByIndex | PaginationButtonWrapper | null | 주어진 인덱스에 대한 페이지 번호를 반환합니다. | index:반환할 페이지 번호의 1 기반 인덱스. |
| findPageNumbers | Array<PaginationButtonWrapper> | - | - |
| findPagesCompactText | ElementWrapper | null | compact 페이지의 표시 텍스트를 반환합니다 (예: 3 of 12 또는 3 of 12+). | - |
| findPreviousPageButton | PaginationButtonWrapper | - | - |
| isDisabled | boolean | - | - |
| Name | Return type | Description | Parameters |
|---|---|---|---|
| isDisabled | boolean | - | - |
Integration testing APIs
PaginationWrapper
| Name | Return type | Description | Parameters |
|---|---|---|---|
| findCurrentPage | PaginationButtonWrapper | - | - |
| findJumpToPageButton | ButtonWrapper | null | 점프 투 페이지 제출 버튼을 반환합니다. | - |
| findJumpToPageInput | InputWrapper | 점프 투 페이지 입력 필드를 반환합니다. | - |
| findJumpToPagePopover | PopoverWrapper | 점프 투 페이지용 오류 팝오버를 반환합니다. | - |
| findNextPageButton | PaginationButtonWrapper | - | - |
| findPageNumberByIndex | PaginationButtonWrapper | 주어진 인덱스에 대한 페이지 번호를 반환합니다. | index:반환할 페이지 번호의 1 기반 인덱스. |
| findPageNumbers | MultiElementWrapper<PaginationButtonWrapper> | - | - |
| findPagesCompactText | ElementWrapper | compact 페이지의 표시 텍스트를 반환합니다 (예: 3 of 12 또는 3 of 12+). | - |
| findPreviousPageButton | PaginationButtonWrapper | - | - |
| Name | Return type | Description | Parameters |
|---|---|---|---|
| No methods availableThis wrapper does not provide any additional methods. |
General guidelines
Do
- 컬렉션의 페이지 사이를 가로로 이동할 수 있게 하려면 페이지네이션을 사용하세요. 가장 흔한 사용 사례는 테이블, 카드, 목록 같은 다양한 유형의 컬렉션 뷰예요.
- 크기가 변하지 않을 컬렉션에 단순한 페이지네이션 패턴이 필요할 때 기본 페이지네이션을 사용하세요.
- 페이지네이션이 잘릴 때, 일반적으로 데이터셋이 9페이지를 초과할 때 jump to page 기능 사용을 고려하세요. 이를 통해 사용자는 여러 번의 순차적 클릭에 의존하지 않고 특정 페이지로 빠르게 이동할 수 있어요.
- 번호가 매겨진 전체 페이지 버튼 행이 들어가지 않는 공간 제약이 있는 레이아웃에서는 compact pages 변형을 사용하세요.
Don't
- 사용자 대부분이 아주 작은 컬렉션(5개 미만 요소)에서 작업한다면 페이지네이션을 사용하지 마세요.
- 컬렉션의 전체 크기를 결정할 수 있다면 open end 페이지네이션을 사용하지 마세요.
Features
-
Basic controls
페이지네이션에는 페이지 사이를 이동하는 여러 메커니즘이 포함돼요:
Left arrow
- 한 페이지 뒤로 이동해요.
- 첫 번째 페이지가 선택되었을 때는 비활성 상태예요.
Numbers
- 특정 컬렉션 페이지로 직접 이동해요.
- 필터 결과에 따라 페이지 수가 달라져요.
Right arrow
- 한 페이지 앞으로 이동해요.
- 마지막 페이지가 선택되었을 때는 비활성 상태예요.
Ellipsis
-
전체 항목 수를 알 수 없을 때 페이지네이션 요소 끝에 줄임표가 포함돼요 (Open end pagination 참고).
-
Open end pagination
open end 페이지네이션은 데이터셋의 전체 크기를 결정할 수 없는 경우를 위한 페이지네이션 변형이에요. 예를 들어 API가 총 항목 수를 반환하지 않거나 페이지네이션되지 않았을 때 발생할 수 있어요. open end 변형은 항상 다음 페이지 아이콘 앞에 줄임표를 표시해요. 사용자가 다음 페이지의 항목을 로드할 수 있도록 다음 버튼은 항상 활성 상태예요.
-
Jump to page - optional
이를 통해 사용자는 페이지 번호를 입력해서 특정 페이지로 직접 이동할 수 있어요. 여러 페이지를 탐색하는 데 시간이 걸릴 수 있는 대용량 데이터셋에서 특히 유용해요. 요청한 페이지가 로드되는 동안(서버 측 페이지네이션) jump to page 기능을 "loading" 상태에 두어야 해요.
-
Compact - optional
번호가 매겨진 페이지 버튼 행 대신 현재 페이지와 전체 페이지 수를 단일 카운터로 표시해요. 전체 페이지 버튼 행이 들어가지 않는 공간 제약이 있는 레이아웃에 유용해요. 예를 들어, 1 of 3 . openEnd가 true이면 페이지 수 뒤에 더하기 기호가 더 많은 페이지가 있음을 나타내요.
Accessibility guidelines
General accessibility guidelines
- 각 컴포넌트의 대체 텍스트와 ARIA(Accessible Rich Internet Applications) 영역에 대한 가이드라인을 따르세요.
- 애플리케이션의 언어 맥락에 맞게 ARIA 라벨을 정의하세요.
- 역할(roles)과 랜드마크(landmarks)에 불필요한 마크업을 추가하지 마세요. 각 컴포넌트의 가이드라인을 따르세요.
- 모든 콘텐츠에 논리적이고 예측 가능한 순서로 키보드 기능을 제공하세요. 정보의 흐름이 자연스러워야 해요.
Component-specific guidelines
Alternative text
-
대체 텍스트 가이드라인에 따라
labels속성을 통해 페이지네이션 버튼의 라벨을 정의하세요. -
페이지에서 여러 개의
Pagination을 사용할 때는paginationLabel을 정의해서 사용자가 맥락을 파악하도록 도우세요. -
아이콘이 사용자를 어디로 데려가는지 명시하세요.
- 예를 들어 left 또는 right 가 아니라 이전 페이지(Previous page)나 Page 6 같은 페이지 번호를 사용하세요.