TextInputWithTokens: announce selected token values for screen readers#7618
TextInputWithTokens: announce selected token values for screen readers#7618liuliu-dev merged 3 commits intomainfrom
Conversation
🦋 Changeset detectedLatest commit: c8a87d4 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
There was a problem hiding this comment.
Pull request overview
Improves accessibility of the deprecated TextInputWithTokens component by adding a screen-reader-only description of currently selected token values and wiring it into aria-describedby when the input is used with role="combobox" (e.g., with Autocomplete).
Changes:
- Add a VisuallyHidden “Selected: …” description and append its id to
aria-describedbywhenrole="combobox". - Add a unit test verifying the combobox is described by the selected token values.
- Add a patch changeset for
@primer/react.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| packages/react/src/TextInputWithTokens/TextInputWithTokens.tsx | Derives a selected-values description and conditionally links it via aria-describedby for combobox usage. |
| packages/react/src/TextInputWithTokens/TextInputWithTokens.test.tsx | Adds a test asserting selected values are present in the element(s) referenced by aria-describedby. |
| .changeset/three-suns-move.md | Declares a patch release note for the accessibility change. |
Comments suppressed due to low confidence (3)
packages/react/src/TextInputWithTokens/TextInputWithTokens.tsx:123
selectedTokenTexts/selectedValuesDescriptionare recomputed on every render (including whenroleis notcombobox). Since this component rerenders on keystrokes, this creates avoidable O(n) work and string allocation proportional to the token count. Consider guarding the computation behindrole === 'combobox'and memoizing the derived description (e.g., viauseMemokeyed ontokens/role).
const selectedTokenTexts = tokens
.map(token => {
if ('text' in token && typeof token.text === 'string' && token.text.trim().length) {
return token.text
}
return null
})
.filter((tokenText): tokenText is string => tokenText !== null)
const selectedValuesDescription = selectedTokenTexts.length ? `Selected: ${selectedTokenTexts.join(', ')}` : ''
packages/react/src/TextInputWithTokens/TextInputWithTokens.tsx:124
- The generated
aria-describedbytext lists every selected token value. With large token sets this can become extremely verbose for screen readers and may negatively affect usability/performance. Consider truncating the announcement (e.g., first N tokens + “and X more”) or aligning it withvisibleTokenCountwhen provided.
const selectedValuesDescription = selectedTokenTexts.length ? `Selected: ${selectedTokenTexts.join(', ')}` : ''
const shouldExposeSelectedValuesDescription = role === 'combobox' && Boolean(selectedValuesDescription)
.changeset/three-suns-move.md:5
- Changeset message references
TextInputTokens, but the exported component isTextInputWithTokens(and the PR title uses that name). For clarity in the changelog and searchability, consider updating the changeset text to match the public export name.
TextInputTokens: announce selected token values for screen readers.
llastflowers
left a comment
There was a problem hiding this comment.
Looks great! I tested the storybook preview and the SR behavior appears as expected. Just one super minor nitpick in the changeset that I noticed
.changeset/three-suns-move.md
Outdated
| '@primer/react': patch | ||
| --- | ||
|
|
||
| TextInputTokens: announce selected token values for screen readers. |
There was a problem hiding this comment.
| TextInputTokens: announce selected token values for screen readers. | |
| TextInputWithTokens: announce selected token values for screen readers. |
|
👋 Hi from github/github-ui! Your integration PR is ready: https://github.com/github/github-ui/pull/15163 |
Related issue: https://github.com/github/accessibility-audits/issues/15031
Changelog
Fixes an accessibility issue so screen readers can announce selected tokens in the input. Added a hidden selected values description use it for
aria-describedbywhen the input role is combobox.Rollout strategy
Testing & Reviewing
Merge checklist