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.

fix: restore focus after closing dropdown via Esc in CSS Value input (#5002)

Oleg Isonen2bb6e9d5c2c4
diff --git a/apps/builder/app/builder/features/style-panel/shared/css-value-input/css-value-input.tsx b/apps/builder/app/builder/features/style-panel/shared/css-value-input/css-value-input.tsx
index 899fb7463e..7c750f6661 100644
--- a/apps/builder/app/builder/features/style-panel/shared/css-value-input/css-value-input.tsx
+++ b/apps/builder/app/builder/features/style-panel/shared/css-value-input/css-value-input.tsx
@@ -929,7 +929,21 @@ export const CssValueInput = ({
}, [inputRef]);
const inputPropsHandleKeyDown = composeEventHandlers(
- [handleUpDownNumeric, inputProps.onKeyDown, handleEnter, handleDelete],
+ [
+ handleUpDownNumeric,
+ inputProps.onKeyDown,
+ handleEnter,
+ handleDelete,
+ (event: KeyboardEvent) => {
+ // When dropdown is open - we are loosing focus to the combobox.
+ // When menu gets closed via Escape - we want to restore the focus.
+ if (event.key === "Escape" && isOpen) {
+ requestAnimationFrame(() => {
+ inputRef.current?.focus();
+ });
+ }
+ },
+ ],
{
// Pass prevented events to the combobox (e.g., the Escape key doesn't work otherwise, as it's blocked by Radix)
checkForDefaultPrevented: false,