Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/neat-houses-think.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@digdir/designsystemet-css": patch
---

**pagination**: If direct child of `li` has `aria-hidden="true"` it sets `visibility: hidden;`
5 changes: 5 additions & 0 deletions .changeset/six-grapes-jump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@digdir/designsystemet-react": patch
---

**usePagination**: Hide prev/next buttons with `aria-hidden="true"` and `visibility: hidden;` instead of disabling
4 changes: 4 additions & 0 deletions packages/css/src/pagination.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
display: flex;
}

& > li > [aria-hidden='true'] {
visibility: hidden;
}

& > li:first-child > ::before,
& > li:last-child > ::before {
content: '';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,29 +37,29 @@ describe('usePagination', () => {
}
});

it('should prevet previous when at start', () => {
it('should prevent previous when at start', () => {
const { result } = renderHook(() =>
usePagination({ totalPages: 10, currentPage: 1 }),
);

expect(result.current.hasPrev).toBe(false);
expect(result.current.hasNext).toBe(true);
expect(result.current.prevButtonProps['aria-disabled']).toBe(true);
expect(result.current.nextButtonProps['aria-disabled']).toBe(false);
expect(result.current.prevButtonProps['aria-hidden']).toBe(true);
expect(result.current.nextButtonProps['aria-hidden']).toBe(false);
});

it('should prevet next when at end', () => {
it('should prevent next when at end', () => {
const { result } = renderHook(() =>
usePagination({ totalPages: 10, currentPage: 10 }),
);

expect(result.current.hasPrev).toBe(true);
expect(result.current.hasNext).toBe(false);
expect(result.current.prevButtonProps['aria-disabled']).toBe(false);
expect(result.current.nextButtonProps['aria-disabled']).toBe(true);
expect(result.current.prevButtonProps['aria-hidden']).toBe(false);
expect(result.current.nextButtonProps['aria-hidden']).toBe(true);
});

it('should trigger onChange when clickinging button', async () => {
it('should trigger onChange when clicking button', async () => {
const mockOnChange = vi.fn();
const event = { preventDefault: () => {} } as MouseEvent<HTMLButtonElement>;
const { result } = renderHook(() =>
Expand All @@ -71,7 +71,7 @@ describe('usePagination', () => {
expect(mockOnChange).toHaveBeenCalledWith(event, 2);
});

it('should not trigger onChange when clickinging previous button and in start', async () => {
it('should not trigger onChange when clicking previous button and in start', async () => {
const mockOnChange = vi.fn();
const event = { preventDefault: () => {} } as MouseEvent<HTMLButtonElement>;
const { result } = renderHook(() =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,13 @@ export const usePagination = ({
),
/** Properties to spread on Pagination.Button used for previous naviagation */
prevButtonProps: {
'aria-disabled': !hasPrev, // Using aria-disabled to support all HTML elements because of potential asChild
'aria-hidden': !hasPrev, // Using aria-hidden to support all HTML elements because of potential asChild
onClick: handleClick(currentPage - 1),
variant: 'tertiary',
} as PaginationButtonProps,
/** Properties to spread on Pagination.Button used for next naviagation */
nextButtonProps: {
'aria-disabled': !hasNext, // Using aria-disabled to support all HTML elements because of potential asChild
'aria-hidden': !hasNext, // Using aria-hidden to support all HTML elements because of potential asChild
onClick: handleClick(currentPage + 1),
variant: 'tertiary',
} as PaginationButtonProps,
Expand Down
Loading