Loading
GlSorting: Fix toggle accessible label omitting selected sort option
Summary
Fixes #3627 (closed)
The GlSorting component's toggle-aria-labelled-by binding only referenced the hidden "Sort by:" span id (sortingListboxId), so screen readers announced only "Sort by:" with no selected option text.
Changes
sorting.vue
- Added
toggleId: uniqueId('sorting-toggle-')todata()alongside the existingsortingListboxId. - Added
:toggle-id="toggleId"to thegl-collapsible-listboxelement so the inner toggle span receives the id. - Changed
:toggle-aria-labelled-byfromsortingListboxIdalone to\${sortingListboxId} ${toggleId}`, so the button'saria-labelledby` references both the "Sort by:" label and the toggle text span. Screen readers will now announce "Sort by: [selected option]".
sorting.spec.js
- Added an
accessible labeldescribe block with three new assertions:- The toggle's inner span receives the generated
toggleIdas itsid. - The listbox
toggleAriaLabelledByprop contains bothsortingListboxIdandtoggleId. - The rendered toggle button's
aria-labelledbyattribute equals${sortingListboxId} ${toggleId}.
- The toggle's inner span receives the generated
.changeset/glsorting-accessible-label-fix.md
- Patch changeset for
@gitlab/ui.
Accessibility impact
This is an accessibility-only fix — no visual or behavioral change. No feature flag is required (confirmed by the reporter on the issue).
Testing
- Unit tests updated in
sorting.spec.jsto assert the correctidandaria-labelledbyvalues. - No visual regression expected; the change only affects ARIA attributes.
- Verified with screen reader + browser pairings including NVDA, JAWS, Narrator, and VoiceOver
Edited by Trevor Pierce
