diff options
| author | Haishan <[email protected]> | 2020-08-06 16:26:01 +0800 |
|---|---|---|
| committer | Haishan <[email protected]> | 2020-08-06 22:40:26 +0800 |
| commit | 2c9ee574ddd5d242021e5954ca6f6144f99eb7f2 (patch) | |
| tree | f085d8083f106f2decd1156c6ba715c34acd38ed /src/components/Selection.js | |
| parent | 941224c13ba87d2c3f36fb86652f046a5c76e00d (diff) | |
refactor: improve a11y
Diffstat (limited to 'src/components/Selection.js')
| -rw-r--r-- | src/components/Selection.js | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/src/components/Selection.js b/src/components/Selection.js index 8302de3..764e7b3 100644 --- a/src/components/Selection.js +++ b/src/components/Selection.js @@ -11,21 +11,21 @@ export default function Selection({ onChange, }) { return ( - // TODO a11y - // tabIndex="0" <div className={s.root}> {optionPropsList.map((props, idx) => { const className = cx(s.item, { [s.itemActive]: idx === selectedIndex }); + const doSelect = (ev) => { + ev.preventDefault(); + if (idx !== selectedIndex) onChange(idx); + }; return ( <div key={idx} className={className} - onClick={(ev) => { - ev.preventDefault(); - if (idx !== selectedIndex) { - onChange(idx); - } - }} + tabIndex={0} + role="menuitem" + onKeyDown={doSelect} + onClick={doSelect} > <OptionComponent {...props} /> </div> |
