Skip to content

feat(ui-pagination): add prop to customize screenreader label on buttons#2027

Merged
matyasf merged 1 commit into
masterfrom
pagination_button_sr
Jul 4, 2025
Merged

feat(ui-pagination): add prop to customize screenreader label on buttons#2027
matyasf merged 1 commit into
masterfrom
pagination_button_sr

Conversation

@matyasf

@matyasf matyasf commented Jun 16, 2025

Copy link
Copy Markdown
Collaborator

The new prop, called screenReaderLabelPageButton allows to customize screenreader messages on the page buttons (e.g. 1,2,3,4...)

To test: Add this new prop to some of the new examples, and test with various screenreaders, that the given text is announced not the one on the button

INSTUI-4602

@matyasf matyasf requested review from HerrTopi, ToMESSKa and Copilot June 16, 2025 12:28
@matyasf matyasf self-assigned this Jun 16, 2025

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Adds a new screenReaderLabelPageButton prop to let users customize the aria-label for individual page buttons.

  • Defines the new prop in props.ts, updates prop types and allowed props
  • Passes the custom label into Pagination.Page and the base button component
  • Adds a focused test for the new behavior and updates documentation with examples

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
packages/ui-pagination/src/Pagination/props.ts Introduce screenReaderLabelPageButton to props
packages/ui-pagination/src/Pagination/index.tsx Spread screenReaderLabel onto <Pagination.Page>
packages/ui-pagination/src/Pagination/tests/Pagination.test.tsx Test aria-label behavior for page buttons
packages/ui-pagination/src/Pagination/README.md Document new prop with usage example
packages/ui-pagination/src/Pagination/PaginationButton/props.ts Accept screenReaderLabel in button props
packages/ui-pagination/src/Pagination/PaginationButton/index.tsx Apply aria-label when screenReaderLabel is set
Comments suppressed due to low confidence (4)

packages/ui-pagination/src/Pagination/tests/Pagination.test.tsx:1132

  • Remove .only to ensure the full test suite runs and avoid accidentally skipping other tests.
it.only('should add aria-label when screenReaderLabelPageButton is set', async () => {

packages/ui-pagination/src/Pagination/README.md:66

  • [nitpick] Avoid using backslashes for line breaks in Markdown; use blank lines or proper paragraph breaks to ensure consistent rendering.
You can set any `totalPageNumber`, the component can handle it easily.\

packages/ui-pagination/src/Pagination/props.ts:100

  • [nitpick] The parameter name was changed to totalPageNumber, but the default prop still refers to numberOfPages. Consider aligning naming for consistency.
labelNumberInput?: (totalPageNumber: number) => React.ReactNode

packages/ui-pagination/src/Pagination/tests/Pagination.test.tsx:1143

  • [nitpick] The regex match on the button name may miss aria-label comparisons; using getAllByLabelText or asserting directly on aria-label may yield a more robust test.
const paginationButtons = screen.getAllByRole('button', { name: /\d$/ })

@github-actions

github-actions Bot commented Jun 16, 2025

Copy link
Copy Markdown
PR Preview Action v1.6.2
Preview removed because the pull request was closed.
2025-07-04 07:28 UTC

@matyasf matyasf force-pushed the pagination_button_sr branch from e1383ed to d6adbfd Compare June 16, 2025 12:37
@instructure instructure deleted a comment from Copilot AI Jun 16, 2025

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add this please to the functional example too

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@HerrTopi HerrTopi Jul 3, 2025

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be cleaner if you'd use the ...(predicate?{}:{}) pattern. The current pattern with the && could result in undesirable behaviour.
When the predicate is false, the result will be the boolean false. Which in this case would not matter much, but ...false is not an intended expression

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@matyasf matyasf force-pushed the pagination_button_sr branch from d6adbfd to cd5c3b6 Compare July 3, 2025 11:52
@matyasf matyasf requested review from HerrTopi and ToMESSKa July 3, 2025 11:53
@matyasf matyasf force-pushed the pagination_button_sr branch from cd5c3b6 to 2547b50 Compare July 3, 2025 12:15

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I missed one. Could you do the same pred?{}:{} pattern here as well?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

The new prop, called screenReaderLabelPageButton allows to customize screenreader messages on the
page buttons (e.g. 1,2,3,4...)

INSTUI-4602
@matyasf matyasf force-pushed the pagination_button_sr branch from 2547b50 to bce1039 Compare July 3, 2025 14:50
@matyasf matyasf merged commit 66e222c into master Jul 4, 2025
11 checks passed
@matyasf matyasf deleted the pagination_button_sr branch July 4, 2025 07:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants