Skip to content

Commit 8733d13

Browse files
authored
fix: Combo mouse select is not working (#4564)
## Description I'm afraid that fix can introduce new bugs. Must be very carefully tested. Also fixed jumps https://github.com/user-attachments/assets/33af39d4-7ac1-4eb7-8c49-c474f6a9aae7 ## Steps for reproduction 1. click button 2. expect xyz ## 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 ea30909 commit 8733d13

File tree

2 files changed

+15
-19
lines changed

2 files changed

+15
-19
lines changed

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

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ import {
3939
import { useUnitSelect } from "./unit-select";
4040
import { parseIntermediateOrInvalidValue } from "./parse-intermediate-or-invalid-value";
4141
import { toValue } from "@webstudio-is/css-engine";
42-
import { useDebouncedCallback } from "use-debounce";
4342
import {
4443
declarationDescriptions,
4544
isValidDeclaration,
@@ -656,16 +655,6 @@ export const CssValueInput = ({
656655

657656
const menuProps = getMenuProps();
658657

659-
/**
660-
* useDebouncedCallback without wait param uses Request Animation Frame
661-
* here we wait for 1 tick until the "blur" event will be completed by Downshift
662-
**/
663-
const callOnCompleteIfIntermediateValueExists = useDebouncedCallback(() => {
664-
if (props.intermediateValue !== undefined) {
665-
onChangeComplete({ value, type: "blur" });
666-
}
667-
});
668-
669658
const handleOnBlur: KeyboardEventHandler = (event) => {
670659
inputProps.onBlur(event);
671660
// When unit select is open, onBlur is triggered,though we don't want a change event in this case.
@@ -675,10 +664,7 @@ export const CssValueInput = ({
675664

676665
// If the menu is open and visible we don't want to trigger onChangeComplete
677666
// as it will be done by Downshift
678-
// There is situation that Downshift will not call omCompleted if nothing is selected in menu
679667
if (isOpen && menuProps.empty === false) {
680-
// There is a situation that Downshift will not call onChangeComplete if nothing is selected in the menu
681-
callOnCompleteIfIntermediateValueExists();
682668
return;
683669
}
684670

@@ -745,6 +731,8 @@ export const CssValueInput = ({
745731
valueForDescription
746732
)}` as keyof typeof declarationDescriptions;
747733
description = declarationDescriptions[key];
734+
} else if (highlightedValue?.type === "var") {
735+
description = "CSS custom property (variable)";
748736
}
749737

750738
const descriptions = items
@@ -894,11 +882,10 @@ export const CssValueInput = ({
894882
</ComboboxListboxItem>
895883
))}
896884
</ComboboxScrollArea>
897-
{description && (
898-
<ComboboxItemDescription descriptions={descriptions}>
899-
<Description>{description}</Description>
900-
</ComboboxItemDescription>
901-
)}
885+
886+
<ComboboxItemDescription descriptions={descriptions}>
887+
<Description>{description}</Description>
888+
</ComboboxItemDescription>
902889
</ComboboxListbox>
903890
</ComboboxContent>
904891
)}

packages/design-system/src/components/combobox.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,15 @@ export const useCombobox = <Item,>({
287287
onIsOpenChange(state) {
288288
const { type, isOpen, inputValue } = state;
289289

290+
// Tab from the input with menu opened should reset the input value if nothing is selected
291+
if (type === comboboxStateChangeTypes.InputBlur) {
292+
onChange?.(undefined);
293+
// If the input is blurred, we want to close the menu and reset the value to the selected item.
294+
setIsOpen(false);
295+
setMatchedItems([]);
296+
return;
297+
}
298+
290299
// Don't open the combobox if the input is a number and the user is using the arrow keys.
291300
// This prevents the combobox from opening when the user is trying to increment or decrement a number.
292301
if (

0 commit comments

Comments
 (0)