diff --git a/src/components/Select/components/SelectControl/SelectControl.tsx b/src/components/Select/components/SelectControl/SelectControl.tsx index 10a372ed76..b8bca6cdfd 100644 --- a/src/components/Select/components/SelectControl/SelectControl.tsx +++ b/src/components/Select/components/SelectControl/SelectControl.tsx @@ -85,6 +85,19 @@ export const SelectControl = React.forwardRef(( error: Boolean(error), }; + const handleControlClick = React.useCallback( + (e?: React.MouseEvent) => { + // Fix for Safari + // https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#clicking_and_focus + if (e && e.currentTarget !== document.activeElement && 'focus' in e.currentTarget) { + (e.currentTarget as HTMLButtonElement).focus(); + } + + toggleOpen(); + }, + [toggleOpen], + ); + const disableButtonAnimation = React.useCallback(() => { setIsDisabledButtonAnimation(true); }, []); @@ -118,7 +131,7 @@ export const SelectControl = React.forwardRef(( { onKeyDown, onClear: clearValue, - onClick: toggleOpen, + onClick: handleControlClick, renderClear: (arg) => renderClearIcon(arg), ref, open: Boolean(open), @@ -147,7 +160,7 @@ export const SelectControl = React.forwardRef(( } name={name} disabled={disabled} - onClick={toggleOpen} + onClick={handleControlClick} onKeyDown={onKeyDown} type="button" data-qa={qa} diff --git a/src/components/Select/types.ts b/src/components/Select/types.ts index b8433df9bf..68bc0f3648 100644 --- a/src/components/Select/types.ts +++ b/src/components/Select/types.ts @@ -12,7 +12,8 @@ export type SelectRenderClearArgs = { export type SelectRenderControlProps = { onClear: () => void; - onClick: () => void; + // FIXME: change "e" property to required in the next major + onClick: (e?: React.MouseEvent) => void; onKeyDown: (e: React.KeyboardEvent) => void; renderClear?: (args: SelectRenderClearArgs) => React.ReactNode; ref: React.Ref;