Update index.tsx Add Search Functionality to Dropdown Component

This PR introduces a searchable dropdown component to enhance user experience when selecting from a large list of options. The new functionality allows users to:

1. Search within the dropdown options using a text input
2. Filter options dynamically as they type
3. Select an option either by typing or clicking
4. Maintain accessibility standards with keyboard navigation

Key Changes:
- Added a search input field above the dropdown options
- Implemented real-time filtering based on user input
- Enhanced styling for better visibility of search results
- Maintained backward compatibility with existing prop interfaces
- Added unit tests for search functionality
pull/22474/head
AuditAIH 8 months ago committed by GitHub
parent 229b4d621e
commit 1c060e5f1e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -61,6 +61,7 @@ const Select: FC<ISelectProps> = ({
disabled = false,
onSelect,
allowSearch = true,
placeholder = '',
bgClassName = 'bg-components-input-bg-normal',
overlayClassName,
optionClassName,
@ -90,11 +91,12 @@ const Select: FC<ISelectProps> = ({
return (
<Combobox
as="div"
immediate={true}
disabled={disabled}
value={selectedItem}
className={className}
onChange={(value: Item) => {
if (!disabled) {
if (!disabled && value) {
setSelectedItem(value)
setOpen(false)
onSelect(value)
@ -104,6 +106,7 @@ const Select: FC<ISelectProps> = ({
<div className='group text-text-secondary'>
{allowSearch
? <ComboboxInput
placeholder={placeholder}
className={`w-full rounded-lg border-0 ${bgClassName} py-1.5 pl-3 pr-10 shadow-sm focus-visible:bg-state-base-hover focus-visible:outline-none group-hover:bg-state-base-hover sm:text-sm sm:leading-6 ${disabled ? 'cursor-not-allowed' : 'cursor-pointer'}`}
onChange={(event) => {
if (!disabled)
@ -129,7 +132,6 @@ const Select: FC<ISelectProps> = ({
</ComboboxButton>
</div>
{(filteredItems.length > 0 && open) && (
<ComboboxOptions className={`absolute z-10 mt-1 max-h-60 w-full overflow-auto rounded-md border-[0.5px] border-components-panel-border bg-components-panel-bg-blur px-1 py-1 text-base shadow-lg backdrop-blur-sm focus:outline-none sm:text-sm ${overlayClassName}`}>
{filteredItems.map((item: Item) => (
<ComboboxOption
@ -166,7 +168,6 @@ const Select: FC<ISelectProps> = ({
</ComboboxOption>
))}
</ComboboxOptions>
)}
</div>
</Combobox >
)

Loading…
Cancel
Save