Skip to content

Commit

Permalink
fix: Clean up use hook for select item
Browse files Browse the repository at this point in the history
  • Loading branch information
manuel.carrera committed Sep 7, 2023
1 parent 2e7d661 commit 6b41512
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
3 changes: 2 additions & 1 deletion modules/react/select/lib/hooks/useSelectInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export const useSelectInput = composeHooks(

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

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

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

Expand Down
3 changes: 1 addition & 2 deletions modules/react/select/lib/hooks/useSelectItem.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import {createElemPropsHook} from '@workday/canvas-kit-react/common';
import {useSelectModel} from './useSelectModel';

/** Adds aria role `option` for the select item and `aria-disabled` if an item is disabled by `nonInteractiveIds` */

export const useSelectItem = createElemPropsHook(useSelectModel)(
(_model, _, elemProps: {disabled: boolean | undefined} = {disabled: undefined}) => {
(_model, _, elemProps: {disabled?: boolean} = {}) => {
return {
role: 'option',
'aria-disabled': elemProps?.disabled,
Expand Down

0 comments on commit 6b41512

Please sign in to comment.