Skip to content

Commit c2ad867

Browse files
feat(ui): add picker searchable prop
1 parent 5c55d22 commit c2ad867

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

invokeai/frontend/web/src/common/components/Picker/Picker.tsx

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,10 @@ type PickerProps<T extends object> = {
194194
* as a text element with appropriate styling. If a React node is provided, it will be rendered as is.
195195
*/
196196
noMatchesFallback?: React.ReactNode;
197+
/**
198+
* Whether the picker should be searchable. If true, renders a search input.
199+
*/
200+
searchable?: boolean;
197201
};
198202

199203
type PickerContextState<T extends object> = {
@@ -478,6 +482,7 @@ export const Picker = typedMemo(<T extends object>(props: PickerProps<T>) => {
478482
noOptionsFallback,
479483
OptionComponent = DefaultOptionComponent,
480484
NextToSearchBar,
485+
searchable,
481486
} = props;
482487
const [$activeOptionId] = useState(() => {
483488
const initialValue = getFirstOptionId(rawOptions, getOptionId);
@@ -546,7 +551,7 @@ export const Picker = typedMemo(<T extends object>(props: PickerProps<T>) => {
546551
);
547552

548553
useEffect(() => {
549-
if (!debouncedSearchTerm) {
554+
if (!debouncedSearchTerm || !searchable) {
550555
$filteredOptions.set(options);
551556
$activeOptionId.set(getFirstOptionId(options, getOptionId));
552557
} else {
@@ -567,7 +572,16 @@ export const Picker = typedMemo(<T extends object>(props: PickerProps<T>) => {
567572
$filteredOptions.set(filtered as T[] | Group<T>[]);
568573
$activeOptionId.set(getFirstOptionId(filtered as T[] | Group<T>[], getOptionId));
569574
}
570-
}, [debouncedSearchTerm, $activeOptionId, props.options, options, getOptionId, isMatch, $filteredOptions]);
575+
}, [
576+
debouncedSearchTerm,
577+
$activeOptionId,
578+
props.options,
579+
options,
580+
getOptionId,
581+
isMatch,
582+
$filteredOptions,
583+
searchable,
584+
]);
571585

572586
const onSelectById = useCallback(
573587
(id: string) => {
@@ -641,7 +655,7 @@ export const Picker = typedMemo(<T extends object>(props: PickerProps<T>) => {
641655
return (
642656
<PickerContext.Provider value={ctx}>
643657
<PickerContainer>
644-
<PickerSearchBar value={searchTerm} onChange={onChangeSearchTerm} isDisabled={!hasOptions} />
658+
{searchable && <PickerSearchBar value={searchTerm} onChange={onChangeSearchTerm} isDisabled={!hasOptions} />}
645659
<Flex tabIndex={-1} w="full" flexGrow={1}>
646660
{!hasOptions && <NoOptionsFallback />}
647661
{hasOptions && !hasFilteredOptions && <NoMatchesFallback />}

invokeai/frontend/web/src/features/parameters/components/ModelPicker.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ export const ModelPicker = typedMemo(
223223
noMatchesFallback={t('modelManager.noMatchingModels')}
224224
NextToSearchBar={<NavigateToModelManagerButton />}
225225
getIsDisabled={getIsDisabled}
226+
searchable
226227
/>
227228
</PopoverBody>
228229
</PopoverContent>

0 commit comments

Comments
 (0)