Skip to content

Commit

Permalink
refactor(SelectTypeahead template)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamviktora committed Apr 30, 2024
1 parent d148532 commit 9914996
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions packages/react-templates/src/components/Select/SelectTypeahead.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,15 @@ export const SelectTypeaheadBase: React.FunctionComponent<SelectTypeaheadProps>
textInputRef?.current?.focus();
};

const onClearButtonClick = () => {
setSelected('');
setInputValue('');
onInputChange && onInputChange('');
setFilterValue('');
resetActiveAndFocusedItem();
textInputRef?.current?.focus();
};

const toggle = (toggleRef: React.Ref<MenuToggleElement>) => (
<MenuToggle
ref={toggleRef}
Expand Down Expand Up @@ -261,18 +270,7 @@ export const SelectTypeaheadBase: React.FunctionComponent<SelectTypeaheadProps>
/>

<TextInputGroupUtilities {...(!inputValue ? { style: { display: 'none' } } : {})}>
<Button
variant="plain"
onClick={() => {
setSelected('');
setInputValue('');
onInputChange && onInputChange('');
setFilterValue('');
resetActiveAndFocusedItem();
textInputRef?.current?.focus();
}}
aria-label="Clear input value"
>
<Button variant="plain" onClick={onClearButtonClick} aria-label="Clear input value">
<TimesIcon aria-hidden />
</Button>
</TextInputGroupUtilities>
Expand Down

0 comments on commit 9914996

Please sign in to comment.