-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[combo-box / dropdown] Improve accessibility (#11421)
### Related Ticket(s) Closes #11268 [Jira ticket](https://jsw.ibm.com/browse/ADCMS-4401) ### Description Fixes accessibility issues with Combo-box, and by extension Dropdown. Used both React package (which uses [Downshift](https://www.downshift-js.com/)), and [ARIA APG](https://www.w3.org/WAI/ARIA/apg/patterns/combobox/) as references. Tested with VoiceOver on Mac OS. ### Testing * Use both dropdown and combo-box components. Ensure there are no regressions for sighted users * Using a screenreader, test both dropdown and combo-box components. Should work well. See [Select-Only Combobox Example](https://www.w3.org/WAI/ARIA/apg/patterns/combobox/examples/combobox-select-only/) and [Editable Combobox With List Autocomplete Example](https://www.w3.org/WAI/ARIA/apg/patterns/combobox/examples/combobox-autocomplete-list/) are great reference examples. * Regression test the Multi select component (it extends the Dropdown component) ### Changelog **Changed** - Improved dropdown and combo-box accessibility. <!-- React and Web Component deploy previews are enabled by default. --> <!-- To enable additional available deploy previews, apply the following --> <!-- labels for the corresponding package: --> <!-- *** "test: e2e": Codesandbox examples and e2e integration tests --> <!-- *** "package: services": Services --> <!-- *** "package: utilities": Utilities --> <!-- *** "RTL": React / Web Components (RTL) --> <!-- *** "feature flag": React / Web Components (experimental) -->
- Loading branch information
Showing
9 changed files
with
134 additions
and
370 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
/** | ||
* @license | ||
* | ||
* Copyright IBM Corp. 2019, 2023 | ||
* Copyright IBM Corp. 2019, 2024 | ||
* | ||
* This source code is licensed under the Apache-2.0 license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
|
@@ -17,6 +17,8 @@ import CDSDropdown, { DROPDOWN_KEYBOARD_ACTION } from '../dropdown/dropdown'; | |
import CDSComboBoxItem from './combo-box-item'; | ||
import styles from './combo-box.scss'; | ||
import { carbonElement as customElement } from '../../globals/decorators/carbon-element'; | ||
import { ifDefined } from 'lit/directives/if-defined'; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
m4olivei
Author
Contributor
|
||
import ifNonEmpty from '../../globals/directives/if-non-empty'; | ||
|
||
export { DROPDOWN_DIRECTION, DROPDOWN_SIZE } from '../dropdown/dropdown'; | ||
|
||
|
@@ -200,11 +202,12 @@ class CDSComboBox extends CDSDropdown { | |
), | ||
(item) => { | ||
(item as CDSComboBoxItem).selected = false; | ||
item.setAttribute('aria-selected', 'false'); | ||
} | ||
); | ||
if (itemToSelect) { | ||
itemToSelect.selected = true; | ||
this._assistiveStatusText = this.selectedItemAssistiveText; | ||
itemToSelect.setAttribute('aria-selected', 'true'); | ||
} | ||
this._handleUserInitiatedToggle(false); | ||
} | ||
|
@@ -214,8 +217,10 @@ class CDSComboBox extends CDSDropdown { | |
disabled, | ||
inputLabel, | ||
label, | ||
open, | ||
readOnly, | ||
value, | ||
_activeDescendant: activeDescendant, | ||
_filterInputValue: filterInputValue, | ||
_handleInput: handleInput, | ||
} = this; | ||
|
@@ -225,17 +230,29 @@ class CDSComboBox extends CDSDropdown { | |
[`${prefix}--text-input--empty`]: !value, | ||
}); | ||
|
||
let activeDescendantFallback: string | undefined; | ||
if (open && !activeDescendant) { | ||
const constructor = this.constructor as typeof CDSDropdown; | ||
const items = this.querySelectorAll(constructor.selectorItem); | ||
activeDescendantFallback = items[0]?.id; | ||
} | ||
|
||
return html` | ||
<input | ||
id="trigger-label" | ||
id="trigger-button" | ||
class="${inputClasses}" | ||
?disabled=${disabled} | ||
placeholder="${label}" | ||
.value=${filterInputValue} | ||
role="combobox" | ||
aria-label="${inputLabel}" | ||
aria-label="${ifNonEmpty(inputLabel)}" | ||
aria-controls="menu-body" | ||
aria-haspopup="listbox" | ||
aria-autocomplete="list" | ||
aria-expanded="${String(open)}" | ||
aria-activedescendant="${ifDefined( | ||
open ? activeDescendant ?? activeDescendantFallback : '' | ||
)}" | ||
?readonly=${readOnly} | ||
@input=${handleInput} /> | ||
`; | ||
|
@@ -268,7 +285,7 @@ class CDSComboBox extends CDSDropdown { | |
* The `aria-label` attribute for the icon to clear selection. | ||
*/ | ||
@property({ attribute: 'clear-selection-label' }) | ||
clearSelectionLabel = ''; | ||
clearSelectionLabel = 'Clear selection'; | ||
|
||
/** | ||
* The `aria-label` attribute for the `<input>` for filtering. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
@m4olivei @kennylam
.js
extension is missing fromifDefined
import.