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.
TypeScript accessibilityalternativecloudflarecloudflare-workersdesignfreefrontendopen-sourceradix-uireactremixweb-developmentwebflowwebsite-builderwebsite-developmentwebsiteswebstudio
move text field to combobox as a ComboboxTextfield
Oleg Isonen30ed43f8bec7
diff --git a/apps/designer/app/designer/features/props-panel/props-panel.tsx b/apps/designer/app/designer/features/props-panel/props-panel.tsxindex 125d331f48..babbe57d51 100644--- a/apps/designer/app/designer/features/props-panel/props-panel.tsx+++ b/apps/designer/app/designer/features/props-panel/props-panel.tsx@@ -11,6 +11,7 @@ import {Box,Button,Combobox,+ ComboboxTextField,Grid,IconButton,TextField,@@ -64,18 +65,14 @@ const Property = ({onChange(id, "prop", value);}}disclosure={({ inputProps, toggleProps }) => (- <Flex>- <TextField- {...inputProps}- autoFocus={prop === ""}- readOnly={required}- variant="ghost"- placeholder="Property"- />- <IconButton variant="ghost" size="1" {...toggleProps}>- <ChevronDownIcon />- </IconButton>- </Flex>+ <ComboboxTextField+ toggleProps={toggleProps}+ inputProps={{+ ...inputProps,+ readOnly: required,+ placeholder: "Property",+ }}+ />)}/>{isInvalidProp ? (diff --git a/apps/designer/app/designer/features/style-panel/render-property.tsx b/apps/designer/app/designer/features/style-panel/render-property.tsxindex ccbbf589aa..2508e971e7 100644--- a/apps/designer/app/designer/features/style-panel/render-property.tsx+++ b/apps/designer/app/designer/features/style-panel/render-property.tsx@@ -180,7 +180,7 @@ const ComboboxControl = ({id={styleConfig.property}items={styleConfig.items}variant="ghost"- popperProps={{ align: "right", sideOffset: 5 }}+ popperProps={{ align: "end", sideOffset: 5 }}state={value.type === "invalid" ? "invalid" : undefined}value={String(value.value)}onValueSelect={setValue}diff --git a/apps/designer/app/shared/design-system/components/combobox.stories.tsx b/apps/designer/app/shared/design-system/components/combobox.stories.tsxindex 8f3f1a5647..8e1b707110 100644--- a/apps/designer/app/shared/design-system/components/combobox.stories.tsx+++ b/apps/designer/app/shared/design-system/components/combobox.stories.tsx@@ -1,10 +1,6 @@import { ComponentStory } from "@storybook/react";import React from "react";-import { Combobox } from "~/shared/design-system";-import { TextField } from "./text-field";-import { Flex } from "./flex";-import { ChevronDownIcon } from "~/shared/icons";-import { IconButton } from "./icon-button";+import { Combobox, ComboboxTextField } from "./combobox";export default {component: Combobox,@@ -40,27 +36,25 @@ export const CustomInput: ComponentStory<typeof Combobox> = () => {console.log(item);}}disclosure={({ inputProps, toggleProps }) => (- <Flex>- <TextField- {...inputProps}- onKeyDown={(event) => {- inputProps?.onKeyDown(event);+ <ComboboxTextField+ toggleProps={toggleProps}+ inputProps={{+ ...inputProps,+ onKeyDown: (event) => {+ inputProps.onKeyDown?.(event);switch (event.key) {case "Enter": {console.log(inputProps.value);break;}}- }}- onBlur={(event) => {- inputProps?.onBlur(event);+ },+ onBlur: (event) => {+ inputProps.onBlur?.(event);console.log(inputProps.value);- }}- />- <IconButton variant="ghost" size="1" {...toggleProps}>- <ChevronDownIcon />- </IconButton>- </Flex>+ },+ }}+ />)}/>);diff --git a/apps/designer/app/shared/design-system/components/combobox.tsx b/apps/designer/app/shared/design-system/components/combobox.tsxindex cddf480832..6c7ba50c59 100644--- a/apps/designer/app/shared/design-system/components/combobox.tsx+++ b/apps/designer/app/shared/design-system/components/combobox.tsx@@ -1,30 +1,24 @@-import { CheckIcon } from "@radix-ui/react-icons";-import { Popper, PopperAnchor, PopperContent } from "@radix-ui/react-popper";+import {+ useState,+ forwardRef,+ type ElementRef,+ type ComponentProps,+} from "react";+import { CheckIcon, ChevronDownIcon } from "~/shared/icons";+import { Popper, PopperContent, PopperAnchor } from "@radix-ui/react-popper";import { useCombobox } from "downshift";import { matchSorter } from "match-sorter";-import { ComponentProps, useState } from "react";-import { Box, Grid } from "..";-import { styled } from "../stitches.config";+import { styled, type CSS } from "../stitches.config";import { IconButton } from "./icon-button";import { itemCss } from "./menu";import { panelStyles } from "./panel";import { TextField } from "./text-field";+import { Box } from "./box";+import { Flex } from "./flex";+import { Grid } from "./grid";type BaseItem = { label: string; disabled?: boolean } | string;-type ComboboxProps<Item> = {- name: string;- items: Array<Item>;- value?: Item;- onItemSelect?: (value: Item) => void;- onItemHighlight?: (value?: Item) => void;- itemToString?: (item: Item) => string;- disclosure?: (items: {- inputProps: ComponentProps<typeof TextField>;- toggleProps: ComponentProps<typeof IconButton>;- }) => JSX.Element;-};-const Listbox = styled("ul", panelStyles, {padding: 0,margin: 0,@@ -38,14 +32,49 @@ const ListboxItem = styled("li", itemCss, {margin: 0,});+type ComboboxTextFieldProps = {+ inputProps: ComponentProps<typeof TextField>;+ toggleProps: ComponentProps<typeof IconButton>;+};++export const ComboboxTextField = forwardRef<+ ElementRef<typeof Flex>,+ ComboboxTextFieldProps+>(({ inputProps, toggleProps }, ref) => {+ return (+ <Flex ref={ref}>+ <TextField {...inputProps} />+ <IconButton variant="ghost" size="1" {...toggleProps}>+ <ChevronDownIcon />+ </IconButton>+ </Flex>+ );+});++type ComboboxProps<Item> = {+ name: string;+ items: Array<Item>;+ value?: Item;+ onItemSelect?: (value: Item) => void;+ onItemHighlight?: (value?: Item) => void;+ itemToString?: (item: Item | null) => string;+ disclosure?: (props: ComponentProps<typeof ComboboxTextField>) => JSX.Element;+ // @todo should we spread those props flat?+ popperProps?: ComponentProps<typeof PopperContent>;+ listCss?: CSS;+};+export const Combobox = <Item extends BaseItem>({items,value,name,- itemToString = (item) => item?.label ?? item ?? "",+ itemToString = (item) =>+ item !== null && "label" in item ? item.label : item ?? "",onItemSelect,onItemHighlight,- disclosure = ({ inputProps }) => <TextField {...inputProps} />,+ disclosure = ({ inputProps, toggleProps }) => (+ <ComboboxTextField inputProps={inputProps} toggleProps={toggleProps} />+ ),}: ComboboxProps<Item>) => {const [filteredItems, setFilteredItems] = useState(items);const {@@ -62,7 +91,7 @@ export const Combobox = <Item extends BaseItem>({onInputValueChange({ inputValue }) {if (inputValue) {const filteredItems = matchSorter(items, inputValue, {- ...(items[0]?.label ? { keys: ["label"] } : {}),+ ...("label" in items[0] ? { keys: ["label"] } : {}),});setFilteredItems(filteredItems);}@@ -82,10 +111,10 @@ export const Combobox = <Item extends BaseItem>({},});- const inputProps = getInputProps({ name });- const toggleProps = getToggleButtonProps();- const comboboxProps = getComboboxProps();- const menuProps = getMenuProps();+ const inputProps: Record<string, unknown> = getInputProps({ name });+ const toggleProps: Record<string, unknown> = getToggleButtonProps();+ const comboboxProps: Record<string, unknown> = getComboboxProps();+ const menuProps: Record<string, unknown> = getMenuProps();return (<Popper>@@ -101,7 +130,7 @@ export const Combobox = <Item extends BaseItem>({item,index,key: index,- ...(item.disabled+ ...("disabled" in item && item.disabled? { "data-disabled": true, disabled: true }: {}),...(highlightedIndex === index ? { "data-found": true } : {}),