Hvis du svarer ja, lagrer og analyserer vi informasjon som hjelper oss å forbedre nettsiden. Du kan når som helst endre valget ditt nederst på siden. Mer om hva vi lagrer og hvorfor.

Vi lagrer også nødvendig informasjon som ikke kan velges bort. Dette gjør at nettsiden fungerer og er trygg.

Hopp til hovedinnhold

Hva leter du etter?

Prøv å søke etter…

Komponenter

Pagination

Pagination er en liste med knapper som brukes for å navigere mellom ulike sider med innhold, for eksempel søkeresultater eller tabeller.

Trykk Enter for å redigere
<ds-pagination
  class="ds-pagination"
  aria-label="pagineringsmeny"
>
  <ul>
    <li>
      <button
        class="ds-button"
        type="button"
        aria-label="Forrige side"
      >Forrige</button>
    </li>
    <li>
      <button class="ds-button" type="button" aria-label="Side 1">1</button>
    </li>
    <li>
      <button
        class="ds-button"
        type="button"
        aria-label="Side 2"
        aria-current="true"
      >2</button>
    </li>
    <li></li>
    <li>
      <button class="ds-button" type="button" aria-label="Side 9">9</button>
    </li>
    <li>
      <button class="ds-button" type="button" aria-label="Side 10">10</button>
    </li>
    <li>
      <button
        class="ds-button"
        type="button"
        aria-label="Neste side"
      >Neste</button>
    </li>
  </ul>
</ds-pagination>
const Preview = () => {
  return (
    <Pagination aria-label='pagineringsmeny'>
      <Pagination.List>
        <Pagination.Item>
          <Pagination.Button aria-label='Forrige side'>
            Forrige
          </Pagination.Button>
        </Pagination.Item>

        <Pagination.Item>
          <Pagination.Button aria-label='Side 1'>1</Pagination.Button>
        </Pagination.Item>

        <Pagination.Item>
          <Pagination.Button aria-label='Side 2' aria-current='true'>
            2
          </Pagination.Button>
        </Pagination.Item>

        <Pagination.Item />

        <Pagination.Item>
          <Pagination.Button aria-label='Side 9'>9</Pagination.Button>
        </Pagination.Item>

        <Pagination.Item>
          <Pagination.Button aria-label='Side 10'>10</Pagination.Button>
        </Pagination.Item>

        <Pagination.Item>
          <Pagination.Button aria-label='Neste side'>Neste</Pagination.Button>
        </Pagination.Item>
      </Pagination.List>
    </Pagination>
  );
};

render(<Preview />)

Bruk

Legg klassenavnet ds-pagination på <ds-pagination>-elementet. Webkomponenten fyller automatisk knappene med tekst basert på attributtene data-current og data-total.

Dersom du ønsker å lage dine egne knapper kan du legge inn <a> eller <button>-elementer inni <ds-pagination>. Dersom du fyller disse med tekst, og ikke sender noen attributter, vil ikke webkomponenten endre på knappene.

Med lenker

Du kan bruke pagination med lenker (anchor tags).

CSS variabler og data-attributter

Størrelser styres med data-size og farger med data-color. Komponenten vil arve nærmeste forelder med disse satt.

CSS-variabler
NavnVerdi
--dsc-button-backgroundtransparent
--dsc-button-background--activevar(--ds-color-surface-active)
--dsc-button-background--hovervar(--ds-color-surface-hover)
--dsc-button-colorvar(--ds-color-text-subtle)
--dsc-button-color--activevar(--dsc-button-color)
--dsc-button-color--hovervar(--dsc-button-color)
--dsc-pagination-ellipsis"\2026"
--dsc-pagination-gapvar(--ds-size-2)
--dsc-pagination-icon-sizevar(--ds-icon-size)
--dsc-pagination-icon-urlurl("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24'%3E%3Cpath d='M9.47 5.97a.75.75 0 0 1 1.06 0l5.5 5.5a.75.75 0 0 1 0 1.06l-5.5 5.5a.75.75 0 1 1-1.06-1.06L14.44 12 9.47 7.03a.75.75 0 0 1 0-1.06'/%3E%3C/svg%3E")
--dsc-pagination-label"Bla i sider"
--dsc-pagination-label-next"Neste side"
--dsc-pagination-label-prev"Forrige side"
Data-attributter
NavnVerdi
data-varianttertiary

React

Pagination er en komponent uten state, og du må selv styre hvilke sider som er vist.

Bruk usePagination for paginering-logikk sammen med de enkle delkomponentene. Les mer om usePagination.

Pagination

aria-label
Description

Sets the screen reader label for the Pagination area

Type
string
Default
'Bla i sider'
data-current
Description

Current page number

Type
string
data-total
Description

Total number of pages

Type
string
asChild
Description

Change the default rendered element for the one passed as a child, merging their props and behavior. @deprecated This is not supported anymore, as the element needs to be `ds-pagination`

Type
boolean
Default
false
NameTypeDefaultDescription
aria-labelstring'Bla i sider'

Sets the screen reader label for the Pagination area

data-currentstring-

Current page number

data-totalstring-

Total number of pages

asChildbooleanfalse

Change the default rendered element for the one passed as a child, merging their props and behavior. @deprecated This is not supported anymore, as the element needs to be `ds-pagination`

PaginationButton

aria-current
Description

Toggle button as active Indicates the element that represents the current item within a container or set of related elements.

Type
boolean | "false" | "true" | "page" | "step" | "location" | "date" | "time"
Default
false
type
Description

Specify the type of button. Unset when `asChild` is true

Type
"submit" | "reset" | "button"
Default
'button'
variant
Description

Specify which variant to use

Type
"primary" | "secondary" | "tertiary"
Default
'primary'
asChild
Description

Change the default rendered element for the one passed as a child, merging their props and behavior.

Type
boolean
Default
false
NameTypeDefaultDescription
aria-currentboolean | "false" | "true" | "page" | "step" | "location" | "date" | "time"false

Toggle button as active Indicates the element that represents the current item within a container or set of related elements.

type"submit" | "reset" | "button"'button'

Specify the type of button. Unset when `asChild` is true

variant"primary" | "secondary" | "tertiary"'primary'

Specify which variant to use

asChildbooleanfalse

Change the default rendered element for the one passed as a child, merging their props and behavior.

PaginationItem

asChild
Description

Change the default rendered element for the one passed as a child, merging their props and behavior.

Type
boolean
Default
false
NameTypeDefaultDescription
asChildbooleanfalse

Change the default rendered element for the one passed as a child, merging their props and behavior.

PaginationList

asChild
Description

Change the default rendered element for the one passed as a child, merging their props and behavior.

Type
boolean
Default
false
NameTypeDefaultDescription
asChildbooleanfalse

Change the default rendered element for the one passed as a child, merging their props and behavior.

Ekstra logikk for å lage paginering med lenker

Under ser du usePagination brukt sammen med pagination for å lage paginering med lenker. Du bruker asChild for å endre Pagination.Button til <a>.

Rediger denne siden på github.com (åpnes i ny fane)