From caead40bface9eaeea567cc76b504f41c07eb6ef Mon Sep 17 00:00:00 2001 From: OsamaAbdellateef Date: Wed, 17 Jan 2024 19:18:49 +0200 Subject: [PATCH 1/3] Adding onClear prop to Autocomplete Component --- packages/components/src/Autocomplete/Autocomplete.tsx | 11 ++++++++--- packages/components/src/Autocomplete/ClearButton.tsx | 11 +++++++++-- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/packages/components/src/Autocomplete/Autocomplete.tsx b/packages/components/src/Autocomplete/Autocomplete.tsx index c894f2a72c..51864373ae 100644 --- a/packages/components/src/Autocomplete/Autocomplete.tsx +++ b/packages/components/src/Autocomplete/Autocomplete.tsx @@ -18,9 +18,10 @@ import { AutocompleteClearButton } from './ClearButton'; //---------------- interface SearchInputProps { onSubmit?: (key: Key | null, value: string | null) => void; + onClear?: () => void; ref?: Ref | undefined; } -const SearchInput = ({ onSubmit, ref }: SearchInputProps) => { +const SearchInput = ({ onSubmit, onClear, ref }: SearchInputProps) => { const state = React.useContext(ComboBoxStateContext); return ( @@ -28,7 +29,9 @@ const SearchInput = ({ onSubmit, ref }: SearchInputProps) => { ref={ref} icon={} action={ - state?.inputValue !== '' ? : undefined + state?.inputValue !== '' ? ( + + ) : undefined } onKeyDown={e => { if (e.key === 'Enter' || e.key === 'Escape') { @@ -81,6 +84,7 @@ export interface AutocompleteProps defaultValue?: RAC.ComboBoxProps['defaultInputValue']; value?: RAC.ComboBoxProps['inputValue']; onChange?: RAC.ComboBoxProps['onInputChange']; + onClear?: () => void; disabled?: RAC.ComboBoxProps['isDisabled']; required?: RAC.ComboBoxProps['isRequired']; error?: RAC.ComboBoxProps['isInvalid']; @@ -113,6 +117,7 @@ const _Autocomplete = forwardRef( defaultValue, value, onChange, + onClear, onSubmit, disabled, error, @@ -138,7 +143,7 @@ const _Autocomplete = forwardRef( return ( <> - + {children} diff --git a/packages/components/src/Autocomplete/ClearButton.tsx b/packages/components/src/Autocomplete/ClearButton.tsx index c808076f15..1e2e592971 100644 --- a/packages/components/src/Autocomplete/ClearButton.tsx +++ b/packages/components/src/Autocomplete/ClearButton.tsx @@ -7,16 +7,23 @@ import { Button } from '../Button'; export interface ClearButtonProps { className?: string; + onClear?: () => void; } -export const AutocompleteClearButton = ({ className }: ClearButtonProps) => { +export const AutocompleteClearButton = ({ + className, + onClear, +}: ClearButtonProps) => { let state = React.useContext(ComboBoxStateContext); return (