본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

Paginator

원문 보기 위키 갱신

Paginator는 compound composition 방식으로 만들어진, styled가 없는 접근성 높은 페이지네이션 컴포넌트예요. 레이아웃, 페이지 렌더링, 내비게이션 스타일을 완전히 제어할 수 있어요.

출처: 문서

본문

기능 (Features)

  • 9개의 하위 컴포넌트(Root, Content, First, Prev, Pages, Page, Ellipsis, Next, Last)로 구성된 compound 컴포넌트 API
  • 설정 가능한 siblings와 edges를 통한 스마트 페이지 범위 계산
  • 페이지 범위 사이에 자동으로 말줄임표(ellipsis) 삽입
  • 페이지 아이템 렌더링을 완전히 제어할 수 있는 Pages의 렌더 함수 자식

사용법 (Usage)

import { Paginator } from 'primereact/paginator';
<Paginator.Root>
    <Paginator.Content>
        <Paginator.First></Paginator.First>
        <Paginator.Prev></Paginator.Prev>
        <Paginator.Pages></Paginator.Pages>
        <Paginator.Next></Paginator.Next>
        <Paginator.Last></Paginator.Last>
    </Paginator.Content>
</Paginator.Root>

동작 (Behavior)

다형적 렌더링 (Polymorphic Rendering)

아무 하위 컴포넌트에 as를 사용해 렌더링되는 HTML 요소를 바꿀 수 있어요.

<Paginator.Root as="div">
    <Paginator.Content as="section">
        <Paginator.First as="a" />
        <Paginator.Prev as="a" />
        <Paginator.Pages />
        <Paginator.Next as="a" />
        <Paginator.Last as="a" />
    </Paginator.Content>
</Paginator.Root>

기본 요소: Root=nav, Content=div, First=button, Prev=button, Pages=span, Page=button, Ellipsis=span, Next=button, Last=button.

렌더 함수 자식 (Render Function Children)

Pages는 렌더 함수를 자식으로 받아 컴포넌트 인스턴스에 접근할 수 있게 해 줘요. 인스턴스는 paginator(루트 인스턴스이며 pages 배열과 state를 가짐)를 노출해요.

<Paginator.Pages>{(instance) => instance.paginator?.pages.map((page, i) => (page.type === 'page' ? <Paginator.Page key={i} value={page.value} /> : <Paginator.Ellipsis key={i}>...</Paginator.Ellipsis>))}</Paginator.Pages>

패스 스루 (Pass Through)

<DocPTViewer name="paginator-pt" components={['PaginatorRoot']} />

API

PaginatorRoot

Attribute Value
data-scope "paginator"
data-part "root"
Label Type Description
root PaginatorRootPassThroughType<HTMLAttributes> Used to pass attributes to the root's DOM element.
content PaginatorRootPassThroughType<HTMLAttributes> Used to pass attributes to the content's DOM element.
first PaginatorRootPassThroughType<HTMLAttributes> Used to pass attributes to the first's DOM element.
prev PaginatorRootPassThroughType<HTMLAttributes> Used to pass attributes to the prev's DOM element.
next PaginatorRootPassThroughType<HTMLAttributes> Used to pass attributes to the next's DOM element.
last PaginatorRootPassThroughType<HTMLAttributes> Used to pass attributes to the last's DOM element.

PaginatorContent

Label Type Description
root PaginatorContentPassThroughType<HTMLAttributes> Used to pass attributes to the root's DOM element.

PaginatorFirst

Attribute Value
data-scope "paginator"
data-part "first"
data-disabled Present when disabled
Label Type Description
root PaginatorFirstPassThroughType<HTMLAttributes> Used to pass attributes to the root's DOM element.

PaginatorPrev

Attribute Value
data-scope "paginator"
data-part "prev"
data-disabled Present when disabled
Label Type Description
root PaginatorPrevPassThroughType<HTMLAttributes> Used to pass attributes to the root's DOM element.

PaginatorNext

Attribute Value
data-scope "paginator"
data-part "next"
data-disabled Present when disabled
Label Type Description
root PaginatorNextPassThroughType<HTMLAttributes> Used to pass attributes to the root's DOM element.

PaginatorLast

Attribute Value
data-scope "paginator"
data-part "last"
data-disabled Present when disabled
Label Type Description
root PaginatorLastPassThroughType<HTMLAttributes> Used to pass attributes to the root's DOM element.

PaginatorPages

Attribute Value
data-scope "paginator"
data-part "pages"
Label Type Description
root PaginatorPagesPassThroughType<HTMLAttributes> Used to pass attributes to the root's DOM element.

PaginatorPage

Attribute Value
data-scope "paginator"
data-part "page"
data-active Present on the current page
data-disabled Present when disabled
Label Type Description
root PaginatorPagePassThroughType<HTMLAttributes> Used to pass attributes to the root's DOM element.

PaginatorEllipsis

Label Type Description
root PaginatorEllipsisPassThroughType<HTMLAttributes> Used to pass attributes to the root's DOM element.

접근성 (Accessibility)

스크린 리더 (Screen Reader)

Paginator는 내비게이션 섹션을 나타내는 nav 요소 안에 배치돼요. 첫 페이지, 이전, 다음, 마지막 페이지 탐색 버튼은 각각 aria.firstPageLabel, aria.prevPageLabel, aria.nextPageLabel, aria.lastPageLabel locale 속성에서 파생된 aria-label 속성을 포함해요.

페이지 링크는 aria.pageLabel locale 속성에서 파생된 aria-label을 가진 버튼 요소예요. 현재 페이지는 aria-current="page"로 표시돼요.

키보드 지원 (Keyboard Support)

Key Function
tab Moves focus through the paginator elements.
enter Executes the paginator element action.
space Executes the paginator element action.

더 알아보기 (Learn more)