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: Fix combobox first item focusing behavior (#5581)

Oleg Isonen599827f20bf4
diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md
index 713b912bf0..ff8da2f133 100644
--- a/.github/copilot-instructions.md
+++ b/.github/copilot-instructions.md
@@ -21,6 +21,17 @@
- Don't state the obvious that's already written clearly with code
- Explain WHY you do things, not WHAT you do
- Only explain WHAT when logic is non-trivial to clarify intent
+- WHY comments must describe concrete user scenario or failure mode, not abstract explanations
+- Bad: "Prevent accidental X" - Good: "User does Y and expects Z, without this they'd get W instead"
+
+## Response Style
+
+- Don't echo back what user said
+- Don't show code blocks when you can just edit
+- Before acting, state what you'll do in ~5 words (use bullet points if multiple actions)
+- Wait for confirmation before proceeding
+- Never summarize after editing
+- Never list multiple options - pick the best one
## UI Labels and Text
diff --git a/apps/builder/app/builder/features/settings-panel/props-section/props-section.tsx b/apps/builder/app/builder/features/settings-panel/props-section/props-section.tsx
index 3719a954df..7997545a5d 100644
--- a/apps/builder/app/builder/features/settings-panel/props-section/props-section.tsx
+++ b/apps/builder/app/builder/features/settings-panel/props-section/props-section.tsx
@@ -155,7 +155,6 @@ const AddPropertyOrAttribute = ({
justify="center"
>
<Combobox<Item>
- defaultHighlightedIndex={0}
autoFocus
color={isValid ? undefined : "error"}
placeholder="Select or create"
diff --git a/apps/builder/app/builder/features/style-panel/controls/font-family/font-family-control.tsx b/apps/builder/app/builder/features/style-panel/controls/font-family/font-family-control.tsx
index 025d72e5ed..d37cf28340 100644
--- a/apps/builder/app/builder/features/style-panel/controls/font-family/font-family-control.tsx
+++ b/apps/builder/app/builder/features/style-panel/controls/font-family/font-family-control.tsx
@@ -83,7 +83,6 @@ export const FontFamilyControl = () => {
<FontsManagerButton />
</FloatingPanel>
}
- defaultHighlightedIndex={0}
getItems={() => items}
itemToString={(item) => item?.label ?? item?.value ?? ""}
onItemHighlight={(item) => {
diff --git a/apps/builder/app/builder/features/style-panel/style-source/style-source-input.tsx b/apps/builder/app/builder/features/style-panel/style-source/style-source-input.tsx
index 2448f248b9..6ce8399839 100644
--- a/apps/builder/app/builder/features/style-panel/style-source/style-source-input.tsx
+++ b/apps/builder/app/builder/features/style-panel/style-source/style-source-input.tsx
@@ -392,7 +392,6 @@ export const StyleSourceInput = (
},
selectedItem: undefined,
match: matchOrSuggestToCreate,
- defaultHighlightedIndex: 0,
itemToString: (item) => (item ? item.label : ""),
onItemSelect(item) {
setLabel("");
diff --git a/apps/builder/app/builder/features/style-panel/style-source/style-source-menu.tsx b/apps/builder/app/builder/features/style-panel/style-source/style-source-menu.tsx
index 543660b3bd..f81c2b8077 100644
--- a/apps/builder/app/builder/features/style-panel/style-source/style-source-menu.tsx
+++ b/apps/builder/app/builder/features/style-panel/style-source/style-source-menu.tsx
@@ -204,7 +204,6 @@ const SelectorCombobox = ({
getItems={() => availableItems}
value={value}
itemToString={(item) => item ?? ""}
- defaultHighlightedIndex={0}
getDescription={getSelectorDescription}
onItemSelect={(item) => {
if (item) {
diff --git a/apps/builder/app/builder/shared/css-editor/add-style-input.tsx b/apps/builder/app/builder/shared/css-editor/add-style-input.tsx
index f6b042cdbf..438e75a474 100644
--- a/apps/builder/app/builder/shared/css-editor/add-style-input.tsx
+++ b/apps/builder/app/builder/shared/css-editor/add-style-input.tsx
@@ -177,7 +177,6 @@ export const AddStyleInput = forwardRef<
getItems: getAutocompleteItems,
itemToString: (item) => item?.label ?? "",
value: item,
- defaultHighlightedIndex: 0,
getItemProps: () => ({ text: "sentence" }),
match: matchOrSuggestToCreate,
onChange: (input) => {
diff --git a/packages/design-system/src/components/combobox.tsx b/packages/design-system/src/components/combobox.tsx
index 277fe08b2b..62b2084f2a 100644
--- a/packages/design-system/src/components/combobox.tsx
+++ b/packages/design-system/src/components/combobox.tsx
@@ -268,7 +268,7 @@ export const useCombobox = <Item,>({
onItemHighlight,
stateReducer = (_state, { changes }) => changes,
match = defaultMatch,
- defaultHighlightedIndex = -1,
+ defaultHighlightedIndex = 0,
...rest
}: UseComboboxProps<Item>) => {
const [isOpen, setIsOpen] = useState(false);
@@ -338,7 +338,7 @@ export const useCombobox = <Item,>({
if (
userChanges.isOpen === true &&
state.isOpen === false &&
- defaultHighlightedIndex !== -1
+ defaultHighlightedIndex >= 0
) {
return { ...userChanges, highlightedIndex: defaultHighlightedIndex };
}
@@ -514,13 +514,10 @@ export const Combobox = <Item,>({
</ComboboxAnchor>
<ComboboxContent
onOpenAutoFocus={(event) => {
- if (
- props.defaultHighlightedIndex === undefined ||
- props.defaultHighlightedIndex === -1
- ) {
+ event.preventDefault();
+ if ((props.defaultHighlightedIndex ?? 0) < 0) {
return;
}
- event.preventDefault();
if (event.currentTarget instanceof HTMLElement) {
focusFirstCollectionItem(event.currentTarget);
}