Skip to content

Commit

Permalink
fix: Combo mouse select is not working (#4564)
Browse files Browse the repository at this point in the history
## 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
  • Loading branch information
istarkov committed Dec 12, 2024
1 parent 1d03bec commit 6ab0538
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import {
import { useUnitSelect } from "./unit-select";
import { parseIntermediateOrInvalidValue } from "./parse-intermediate-or-invalid-value";
import { toValue } from "@webstudio-is/css-engine";
import { useDebouncedCallback } from "use-debounce";
import {
declarationDescriptions,
isValidDeclaration,
Expand Down Expand Up @@ -656,16 +655,6 @@ export const CssValueInput = ({

const menuProps = getMenuProps();

/**
* useDebouncedCallback without wait param uses Request Animation Frame
* here we wait for 1 tick until the "blur" event will be completed by Downshift
**/
const callOnCompleteIfIntermediateValueExists = useDebouncedCallback(() => {
if (props.intermediateValue !== undefined) {
onChangeComplete({ value, type: "blur" });
}
});

const handleOnBlur: KeyboardEventHandler = (event) => {
inputProps.onBlur(event);
// When unit select is open, onBlur is triggered,though we don't want a change event in this case.
Expand All @@ -675,10 +664,7 @@ export const CssValueInput = ({

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

Expand Down Expand Up @@ -745,6 +731,8 @@ export const CssValueInput = ({
valueForDescription
)}` as keyof typeof declarationDescriptions;
description = declarationDescriptions[key];
} else if (highlightedValue?.type === "var") {
description = "CSS custom property (variable)";
}

const descriptions = items
Expand Down Expand Up @@ -894,11 +882,10 @@ export const CssValueInput = ({
</ComboboxListboxItem>
))}
</ComboboxScrollArea>
{description && (
<ComboboxItemDescription descriptions={descriptions}>
<Description>{description}</Description>
</ComboboxItemDescription>
)}

<ComboboxItemDescription descriptions={descriptions}>
<Description>{description}</Description>
</ComboboxItemDescription>
</ComboboxListbox>
</ComboboxContent>
)}
Expand Down
9 changes: 9 additions & 0 deletions packages/design-system/src/components/combobox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,15 @@ export const useCombobox = <Item,>({
onIsOpenChange(state) {
const { type, isOpen, inputValue } = state;

// Tab from the input with menu opened should reset the input value if nothing is selected
if (type === comboboxStateChangeTypes.InputBlur) {
onChange?.(undefined);
// If the input is blurred, we want to close the menu and reset the value to the selected item.
setIsOpen(false);
setMatchedItems([]);
return;
}

// Don't open the combobox if the input is a number and the user is using the arrow keys.
// This prevents the combobox from opening when the user is trying to increment or decrement a number.
if (
Expand Down

0 comments on commit 6ab0538

Please sign in to comment.