From f032235a616d72020fabac9363b8ce0932c3871a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Chy=C5=82a?= Date: Tue, 16 Jul 2024 10:24:00 +0200 Subject: [PATCH] Handle disable option in Select, Combobox and Multiselect (#826) * Add disabled to Option type * Handle disabled item state in Select component * Handle disabled in Combobox and Multiselect --- src/components/BaseSelect/types.ts | 1 + .../Combobox/Dynamic/DynamicCombobox.tsx | 8 ++++++- src/components/Combobox/Static/Combobox.tsx | 8 ++++++- .../Static/StaticCombobox.stories.tsx | 20 +++++++++++++++++ .../Dynamic/DynamicMultiselect.tsx | 8 ++++++- .../Static/Multiselect.stories.tsx | 22 +++++++++++++++++++ .../Multiselect/Static/Multiselect.tsx | 8 ++++++- src/components/Select/Select.stories.tsx | 21 ++++++++++++++++++ src/components/Select/Select.tsx | 7 +++++- 9 files changed, 98 insertions(+), 5 deletions(-) diff --git a/src/components/BaseSelect/types.ts b/src/components/BaseSelect/types.ts index 014285cf..303ae4ae 100644 --- a/src/components/BaseSelect/types.ts +++ b/src/components/BaseSelect/types.ts @@ -3,6 +3,7 @@ import { ReactNode } from "react"; export type Option = { label: string; value: string; + disabled?: boolean; startAdornment?: ReactNode; endAdornment?: ReactNode; }; diff --git a/src/components/Combobox/Dynamic/DynamicCombobox.tsx b/src/components/Combobox/Dynamic/DynamicCombobox.tsx index cce2ce00..281f3e1e 100644 --- a/src/components/Combobox/Dynamic/DynamicCombobox.tsx +++ b/src/components/Combobox/Dynamic/DynamicCombobox.tsx @@ -172,11 +172,17 @@ const DynamicComboboxInner = ( {...getItemProps({ item, index, + disabled: item.disabled, })} active={highlightedIndex === index} > {item?.startAdornment} - {item.label} + + {item.label} + {item?.endAdornment} ))} diff --git a/src/components/Combobox/Static/Combobox.tsx b/src/components/Combobox/Static/Combobox.tsx index 4f800ebf..874fb2cc 100644 --- a/src/components/Combobox/Static/Combobox.tsx +++ b/src/components/Combobox/Static/Combobox.tsx @@ -164,11 +164,17 @@ const ComboboxInner = ( {...getItemProps({ item, index, + disabled: item.disabled, })} active={highlightedIndex === index} > {item?.startAdornment} - {item.label} + + {item.label} + {item?.endAdornment} ))} diff --git a/src/components/Combobox/Static/StaticCombobox.stories.tsx b/src/components/Combobox/Static/StaticCombobox.stories.tsx index 5c09377b..405ecf8d 100644 --- a/src/components/Combobox/Static/StaticCombobox.stories.tsx +++ b/src/components/Combobox/Static/StaticCombobox.stories.tsx @@ -233,6 +233,26 @@ export const WithEllipsis = () => { ); }; +export const WithDisabledOption = () => { + const values = options.map((option) => ({ + ...option, + disabled: option.value === "color-green", + })); + const [value, setValue] = useState