Skip to content

Commit 2bb6e9d

Browse files
authored
fix: restore focus after closing dropdown via Esc in CSS Value input (#5002)
## Description ## Steps for reproduction 1. focus any style value 2. type to open dropdown 3. hit ESC 4. see the input is still focused 5. hit ESC again 6. see the change is resetted ## Code Review - [ ] hi @kof, I need you to do - conceptual review (architecture, feature-correctness) - detailed review (read every line) - test it on preview ## Before requesting a review - [ ] made a self-review - [ ] added inline comments where things may be not obvious (the "why", not "what") ## Before merging - [ ] tested locally and on preview environment (preview dev login: 0000) - [ ] updated [test cases](https://github.com/webstudio-is/webstudio/blob/main/apps/builder/docs/test-cases.md) document - [ ] added tests - [ ] if any new env variables are added, added them to `.env` file
1 parent d7bb114 commit 2bb6e9d

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

apps/builder/app/builder/features/style-panel/shared/css-value-input/css-value-input.tsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -929,7 +929,21 @@ export const CssValueInput = ({
929929
}, [inputRef]);
930930

931931
const inputPropsHandleKeyDown = composeEventHandlers(
932-
[handleUpDownNumeric, inputProps.onKeyDown, handleEnter, handleDelete],
932+
[
933+
handleUpDownNumeric,
934+
inputProps.onKeyDown,
935+
handleEnter,
936+
handleDelete,
937+
(event: KeyboardEvent) => {
938+
// When dropdown is open - we are loosing focus to the combobox.
939+
// When menu gets closed via Escape - we want to restore the focus.
940+
if (event.key === "Escape" && isOpen) {
941+
requestAnimationFrame(() => {
942+
inputRef.current?.focus();
943+
});
944+
}
945+
},
946+
],
933947
{
934948
// Pass prevented events to the combobox (e.g., the Escape key doesn't work otherwise, as it's blocked by Radix)
935949
checkForDefaultPrevented: false,

0 commit comments

Comments
 (0)