forked from jsx-eslint/eslint-plugin-jsx-a11y
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[fix] Refine implicit role of
select
to include combobox
scenarios
Encode implicit roles for `select` elements based on roles defined in https://www.w3.org/TR/html-aria/#el-select - `select` (with a multiple attribute or a size attribute having value greater than 1) will have the implicit role 'listbox' - `select` (with NO multiple attribute and NO size attribute having value greater than 1) will have the implicit role 'combobox' Fixes jsx-eslint#949
- Loading branch information
Showing
2 changed files
with
20 additions
and
3 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
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,6 +1,16 @@ | ||
import { getProp, getLiteralPropValue } from 'jsx-ast-utils'; | ||
|
||
/** | ||
* Returns the implicit role for a select tag. | ||
* Returns the implicit role for a select tag depending on attributes. | ||
* | ||
* @see https://www.w3.org/TR/html-aria/#el-select | ||
*/ | ||
export default function getImplicitRoleForSelect() { | ||
return 'listbox'; | ||
export default function getImplicitRoleForSelect(attributes) { | ||
const multiple = getProp(attributes, 'multiple'); | ||
if (multiple) return 'listbox'; | ||
|
||
const size = getProp(attributes, 'size') && getLiteralPropValue(getProp(attributes, 'size')); | ||
if (size && (Number(size) > 1)) return 'listbox'; | ||
|
||
return 'combobox'; | ||
} |