-
Notifications
You must be signed in to change notification settings - Fork 65.8k
Description
Code of Conduct
- I have read and agree to the GitHub Docs project's Code of Conduct
What article on docs.github.com is affected?
Description
IBM Equal Access Accessibility Checker detected an accessibility violation on the GitHub Docs homepage: Accessible name does not match or contain element label.
An element has a visible label, but its accessible name (used by screen readers) does not match or contain it. This causes a mismatch between what sighted users see and what assistive technology users hear.
Why is this important?
Speech-input users navigate to an input field by speaking the visible field label (i.e., text displayed on the screen). Their verbal command activates the interactive component programmatic accessible name and sets focus to the component. A point of failure occurs when the visible label and the accessible name are different, or the visible label text string is not contained within the accessible name value.
What changes are you suggesting?
The accessibility bug report indicates a violation of WCAG 2.5.3 Label in Name. The visible label of the button is "Version: Free, Pro, & Team", but its accessible name (defined by aria-label) is "Select GitHub product version: current version is free-pro-team@latest". For speech input users and screen reader users, the accessible name must contain the visible label text.
To fix this, the aria-label attribute needs to be updated to include the visible text "Version: Free, Pro, & Team".
Looking at the provided code:
- In
src/tools/components/Picker.tsx, theActionMenu.Buttonreceives itsaria-labelfrom theariaLabelprop. The visible text is composed ofpickerLabelandselectedOption?.text || defaultText. - In
src/versions/components/VersionPicker.tsx, thePickercomponent is used, and itsariaLabelprop is set toSelect GitHub product version: current version is ${currentVersion}. ThepickerLabelprop is set toxs ?Version\n:Version: `` and thedefaultTextprop is `t('version_picker_default_text')`. The `selectedOption?.text` would correspond to `allVersions[currentVersion].versionTitle`.
Therefore, the full visible label text is constructed by concatenating the pickerLabel and the currently selected version's title (or the default text if no version is selected). This constructed visible label needs to be prepended to the existing ariaLabel value.
The visible label can be constructed as:
const visibleLabelText = ${xs ? 'Version\n' : 'Version: '}${allVersions[currentVersion]?.versionTitle || t('version_picker_default_text')}`
Then, the ariaLabel prop should be updated to:
`${visibleLabelText}, Select GitHub product version: current version is ${currentVersion}`
This ensures that the accessible name starts with the visible label text, followed by the additional descriptive information, satisfying WCAG 2.5.3.
### src/versions/components/VersionPicker.tsx
<<<<<<< SEARCH
descriptionFontSize={xs ? 6 : 5}
ariaLabel={`Select GitHub product version: current version is ${currentVersion}`}
renderItem={(item) => {
return (
<div data-testid="version-picker-item" className={styles.itemsWidth}>
=======
descriptionFontSize={xs ? 6 : 5}
ariaLabel={`${xs ? 'Version\n' : 'Version: '}${
allVersions[currentVersion]?.versionTitle || t('version_picker_default_text')
}, Select GitHub product version: current version is ${currentVersion}`}
renderItem={(item) => {
return (
<div data-testid="version-picker-item" className={styles.itemsWidth}>
>>>>>>> REPLACEAdditional information
N/A