Skip to content

Commit

Permalink
🎨 Expand Autocomplete api with onClear (#3679)
Browse files Browse the repository at this point in the history
  • Loading branch information
arkadiy93 authored Nov 13, 2024
1 parent 88d811e commit 51c1547
Showing 1 changed file with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,10 @@ export type AutocompleteProps<T> = {
* Method that is used to compare objects by value. If omitted, objects are matched by reference.
*/
itemCompare?: (value: T, compare: T) => boolean
/**
* Callback for clear all button
*/
onClear?: () => void
} & HTMLAttributes<HTMLDivElement>

// MARK: component
Expand Down Expand Up @@ -352,6 +356,7 @@ function AutocompleteInner<T>(
helperIcon,
noOptionsText = 'No options',
variant,
onClear,
...other
} = props

Expand Down Expand Up @@ -839,6 +844,7 @@ function AutocompleteInner<T>(
}, [isOpen, refs.floating])

const clear = () => {
if (onClear) onClear()
resetCombobox()
//dont clear items if they are selected and disabled
setSelectedItems([...selectedDisabledItemsSet])
Expand Down

0 comments on commit 51c1547

Please sign in to comment.