Skip to content

Commit

Permalink
fix: open select,combobox, multiselect when disabled (#734)
Browse files Browse the repository at this point in the history
* Add disabled to check if dropdown is visible

* Fix disable select color
  • Loading branch information
poulch authored Jan 22, 2024
1 parent e3ee3d8 commit 18e52d6
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/components/BaseSelect/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
export const getListDisplayMode = ({
isOpen,
disabled,
hasItemsToSelect,
showEmptyState,
loading,
}: {
isOpen: boolean;
disabled: boolean;
hasItemsToSelect: boolean;
showEmptyState: boolean;
loading?: boolean;
}) => {
if (disabled) {
return "none";
}

if (isOpen && hasItemsToSelect) {
return "block";
}
Expand Down
1 change: 1 addition & 0 deletions src/components/Combobox/Dynamic/DynamicCombobox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ const DynamicComboboxInner = <T extends Option>(
position="relative"
display={getListDisplayMode({
isOpen,
disabled,
loading,
hasItemsToSelect,
showEmptyState: hasNoOptions(children),
Expand Down
1 change: 1 addition & 0 deletions src/components/Combobox/Static/Combobox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ const ComboboxInner = <T extends Option, V extends Option | string>(
<Box
position="relative"
display={getListDisplayMode({
disabled,
hasItemsToSelect,
isOpen,
showEmptyState: hasNoOptions(children),
Expand Down
1 change: 1 addition & 0 deletions src/components/Multiselect/Dynamic/DynamicMultiselect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ const DynamicMultiselectInner = <T extends Option>(
isOpen,
loading,
hasItemsToSelect,
disabled,
showEmptyState: hasNoOptions(children),
})}
className={listWrapperRecipe({ size })}
Expand Down
20 changes: 17 additions & 3 deletions src/components/Select/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import {
InputHTMLAttributes,
ReactNode,
forwardRef,
useMemo,
} from "react";

import { useFloating } from "~/hooks/useFloating";
import { isString } from "~/utils";
import { Box, List, PropsWithBox, Text } from "..";
import { Box, List, PropsWithBox, Text, TextProps } from "..";
import { HelperText, InputVariants } from "../BaseInput";
import {
NoOptions,
Expand Down Expand Up @@ -104,6 +105,18 @@ const SelectInner = <T extends Option, V extends Option | string>(

const { refs, floatingStyles } = useFloating();

const labelColor = useMemo((): TextProps["color"] => {
if (error) {
return "critical1";
}

if (disabled) {
return "defaultDisabled";
}

return "default1";
}, [disabled, error]);

return (
<Box display="flex" flexDirection="column">
<SelectWrapper
Expand All @@ -130,7 +143,7 @@ const SelectInner = <T extends Option, V extends Option | string>(
<Text
size={size}
variant="body"
color={error ? "critical1" : "default1"}
color={labelColor}
title={selectedItem?.label}
>
{selectedItem?.label}
Expand All @@ -141,7 +154,8 @@ const SelectInner = <T extends Option, V extends Option | string>(
<Box
position="relative"
display={getListDisplayMode({
isOpen,
isOpen: isOpen,
disabled,
hasItemsToSelect,
showEmptyState: hasNoOptions(children),
})}
Expand Down

1 comment on commit 18e52d6

@vercel
Copy link

@vercel vercel bot commented on 18e52d6 Jan 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.