Skip to content

Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.

don't auto focus unit trigger after unit selection

Oleg Isonen6b278eaeca6a
diff --git a/apps/designer/app/designer/features/style-panel/shared/css-value-input/css-value-input.tsx b/apps/designer/app/designer/features/style-panel/shared/css-value-input/css-value-input.tsx
index 38b3c36541..931a1186e2 100644
--- a/apps/designer/app/designer/features/style-panel/shared/css-value-input/css-value-input.tsx
+++ b/apps/designer/app/designer/features/style-panel/shared/css-value-input/css-value-input.tsx
@@ -117,6 +117,10 @@ const useUnitSelect = ({
unit,
});
}}
+ onCloseAutoFocus={(event) => {
+ // We don't want to focus the unit trigger when closing the select (no matter if unit was selected, clicked outside or esc was pressed)
+ event.preventDefault();
+ }}
/>
);
@@ -230,6 +234,7 @@ type CssValueInputProps = {
* - option/alt key modifier increases/decreases value by 0.1
* - no modifier increases/decreases value by 1
* - Scrub interaction
+ * - Click outside, unit selection or escape when list is open should unfocus the unit select trigger
*
* Keywords mode:
* - When any character in the input is not a number we automatically switch to keywords mode on keydown
diff --git a/packages/design-system/src/components/select.tsx b/packages/design-system/src/components/select.tsx
index 1d1c4381d5..f828a91189 100644
--- a/packages/design-system/src/components/select.tsx
+++ b/packages/design-system/src/components/select.tsx
@@ -154,6 +154,7 @@ export type SelectProps<Option = SelectOption> = Omit<
onChange?: (option: Option) => void;
open?: boolean;
onOpenChange?: (open: boolean) => void;
+ onCloseAutoFocus?: (event: Event) => void;
placeholder?: string;
getLabel?: (option: Option) => string | undefined;
suffix?: JSX.Element | null;
@@ -167,6 +168,7 @@ const SelectBase = (
placeholder = "Select an option",
onChange,
onOpenChange,
+ onCloseAutoFocus,
open,
getLabel = (option) => option,
name,
@@ -191,7 +193,7 @@ const SelectBase = (
{suffix}
</StyledTrigger>
<SelectPrimitive.Portal>
- <StyledContent>
+ <StyledContent onCloseAutoFocus={onCloseAutoFocus}>
<SelectScrollUpButton>
<ChevronUpIcon />
</SelectScrollUpButton>