Skip to content

Commit 6b41512

Browse files
author
manuel.carrera
committed
fix: Clean up use hook for select item
1 parent 2e7d661 commit 6b41512

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

modules/react/select/lib/hooks/useSelectInput.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ export const useSelectInput = composeHooks(
9898

9999
// Prevent the keys from being enter in the input
100100
event.preventDefault();
101+
const keysToOpenSelect = ['Enter', 'Spacebar', 'ArrowUp', 'ArrowDown'];
101102

102103
// Select should open if Enter, ArrowUp, ArrowDown and Spacebar is typed
103104
if (
@@ -115,7 +116,7 @@ export const useSelectInput = composeHooks(
115116

116117
// If the dropdown is NOT visible and ArrowUp, ArrowDown, Enter and Spacebar is typed, when the dropdown opens
117118
// it should go to the current selected item in the dropdown.
118-
if (event.key === 'Spacebar' || event.key === ' ') {
119+
if (keysToOpenSelect.includes(event.key) || event.key === ' ') {
119120
if (model.state.visibility === 'hidden') {
120121
model.events.goTo({id: model.state.items[foundIndex].id});
121122

modules/react/select/lib/hooks/useSelectItem.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import {createElemPropsHook} from '@workday/canvas-kit-react/common';
22
import {useSelectModel} from './useSelectModel';
3-
43
/** Adds aria role `option` for the select item and `aria-disabled` if an item is disabled by `nonInteractiveIds` */
54

65
export const useSelectItem = createElemPropsHook(useSelectModel)(
7-
(_model, _, elemProps: {disabled: boolean | undefined} = {disabled: undefined}) => {
6+
(_model, _, elemProps: {disabled?: boolean} = {}) => {
87
return {
98
role: 'option',
109
'aria-disabled': elemProps?.disabled,

0 commit comments

Comments
 (0)