Skip to content

Commit

Permalink
feat: added filter options (#252)
Browse files Browse the repository at this point in the history
  • Loading branch information
ktorlakonda-eightfold authored Jul 22, 2022
1 parent f1256e8 commit 5d14a7c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/components/Select/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export const Select: FC<SelectProps> = React.forwardRef(
size={SpinnerSize.Small}
/>
),
filterOption = null,
style,
'data-test-id': dataTestId,
},
Expand Down Expand Up @@ -148,7 +149,9 @@ export const Select: FC<SelectProps> = React.forwardRef(
setOptions(
options.map((option) => ({
...option,
hideOption: !option.text.toLowerCase().includes(value),
hideOption: filterOption
? !filterOption(option, value)
: !option.text.toLowerCase().includes(value),
}))
);
} else {
Expand Down
6 changes: 6 additions & 0 deletions src/components/Select/Select.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,10 @@ export interface SelectProps extends OcBaseProps<HTMLSelectElement> {
* @default {}
*/
spinner?: React.ReactNode;

/**
* Custom method to filter whether an option should be displayed in the menu.
* @default null
*/
filterOption?: (option: any, query: any) => boolean;
}

0 comments on commit 5d14a7c

Please sign in to comment.