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.

refactor text-control to use combobox

Sultan5086f46b2ecb
diff --git a/apps/designer/app/designer/features/style-panel/controls/select/select-control.tsx b/apps/designer/app/designer/features/style-panel/controls/select/select-control.tsx
index e363a3f6a2..73fa8bc783 100644
--- a/apps/designer/app/designer/features/style-panel/controls/select/select-control.tsx
+++ b/apps/designer/app/designer/features/style-panel/controls/select/select-control.tsx
@@ -21,7 +21,7 @@ export const SelectControl = ({
const setValue = setProperty(styleConfig.property);
return (
- <Grid columns={2}>
+ <Grid css={{ gridTemplateColumns: "$columns$1" }}>
<PropertyName property={styleConfig.property} label={styleConfig.label} />
<Select
options={styleConfig.items.map(({ label }) => label)}
@@ -30,8 +30,8 @@ export const SelectControl = ({
ghost
css={{
gap: "calc($sizes$1 / 2)",
- px: "calc($sizes$1 + $nudge$3)",
- height: "$sizes$6",
+ paddingLeft: "calc($sizes$4 / 2)",
+ height: "calc($sizes$5 + $sizes$1)",
boxShadow: "inset 0 0 0 1px $colors$slate7",
textTransform: "capitalize",
fontWeight: "inherit",
diff --git a/apps/designer/app/designer/features/style-panel/controls/text/text-control.tsx b/apps/designer/app/designer/features/style-panel/controls/text/text-control.tsx
index b66d4c7e8f..30961a3e63 100644
--- a/apps/designer/app/designer/features/style-panel/controls/text/text-control.tsx
+++ b/apps/designer/app/designer/features/style-panel/controls/text/text-control.tsx
@@ -1,23 +1,20 @@
-import { ChangeEvent, FocusEvent, KeyboardEvent, useRef } from "react";
+import { FocusEvent, PointerEvent, useCallback } from "react";
import {
Box,
Text,
Grid,
IconButton,
TextField,
- Tooltip,
- IconButtonWithMenu,
+ Combobox,
numericScrubControl,
} from "@webstudio-is/design-system";
import { getFinalValue } from "../../shared/get-final-value";
-import { useIsFromCurrentBreakpoint } from "../../shared/use-is-from-current-breakpoint";
import { ControlProps } from "../../style-sections";
-import { iconConfigs, StyleConfig } from "../../shared/configs";
-import { type StyleValue, type Unit, units } from "@webstudio-is/react-sdk";
+import { units } from "@webstudio-is/react-sdk";
import { ChevronDownIcon } from "@webstudio-is/icons";
-import { PropertyName } from "../../shared/property-name";
+import { PropertyName, PropertyIcon } from "../../shared/property-name";
-const commonUnitsSubset = units
+const sortedUnits = units
.slice(0)
.sort((v) =>
["%", "px", "rem", "em", "ch", "vh", "vw", "hv", "vmin", "vmax"].includes(v)
@@ -25,237 +22,180 @@ const commonUnitsSubset = units
: 1
);
-const gridTemplateStyle = {
- gridTemplateColumns: "$sizes$6 auto $sizes$6",
- gridTemplateRows: "repeat(1, 1fr)",
-};
-
-const gridLeftStyle = {
- "& ~ input": {
- paddingLeft: "calc($sizes$6 + $nudge$3)",
- },
- gridArea: "1 / 1 / 2 / 2",
-};
-
-const gridRightStyle = {
- gridArea: "-1 / -1 / -2 / -2",
- "& ~ input": {
- paddingRight: "calc($sizes$5 + $nudge$3)",
- },
-};
-
-const iconButtonStyle = {
- borderRadius: 2,
- height: "calc($sizes$6 - $nudge$3)",
- width: "calc($sizes$6 - $nudge$3)",
- transform: "translate(3px, 3px)",
- "&:focus": {
- boxShadow: "none",
- },
-};
-
-const iconButtonActiveStyle = {
- bc: "$colors$blue4",
- "&:not(:hover)": {
- color: "$colors$blue11",
- },
-};
-
-const iconButtonGridLeftStyle = {
- ...gridLeftStyle,
- ...iconButtonStyle,
-};
-
-const iconButtonGridRightStyle = {
- ...gridRightStyle,
- "& button": { ...iconButtonStyle },
-};
-
-const textFieldStyle = {
- height: "$6",
- fontWeight: "500",
- paddingLeft: "calc($sizes$1 + $nudge$3)",
- gridArea: "1 / 1 / -1 / -1",
- cursor: "default",
-};
-
export const TextControl = ({
currentStyle,
inheritedStyle,
setProperty,
styleConfig,
}: ControlProps) => {
- const numericScrubRef = useRef<{ disconnectedCallback: () => void }>();
- const isCurrentBreakpoint = useIsFromCurrentBreakpoint(styleConfig.property);
- const textFieldRef = useRef<HTMLInputElement>(null);
-
const value = getFinalValue({
currentStyle,
inheritedStyle,
property: styleConfig.property,
});
+ const getInputNode = (node: HTMLElement): HTMLInputElement => {
+ return node
+ .closest("[data-control]")
+ ?.querySelector("input") as HTMLInputElement;
+ };
+ const isExpanded = (node: HTMLElement) => {
+ return node
+ .closest("[data-control]")
+ ?.querySelector("[aria-expanded=true]");
+ };
+
+ const numericScrubRefCallback = useCallback(
+ (node: HTMLButtonElement) => {
+ if (!value) return;
+ const id = Symbol.for("numericScrubControl");
+ if (!node) return Object(node)[id]?.disconnectedCallback();
+ if (value.type !== "unit") return;
+ if (Object(node)[id]) return;
+ Object(node)[id] = numericScrubControl(node, {
+ initialValue: value.value,
+ onValueChange: (event) => {
+ getInputNode(node).value = String(event.value);
+ handleChange("unit", event.value, true);
+ },
+ });
+ },
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ []
+ );
+
if (value === undefined) return null;
const setValue = setProperty(styleConfig.property);
- const Icon = iconConfigs[styleConfig.property]?.normal;
+ const items =
+ value.type === "unit"
+ ? sortedUnits.map((unit) => ({ name: unit, label: unit }))
+ : styleConfig.items;
+ const handleChange = (
+ type: string,
+ item: string | number | undefined,
+ isEphemeral: boolean
+ ) => {
+ if (!item) return;
+ const newValue =
+ type === "unit" ? value.value + String(item) : String(item);
+ setValue(value.type === "unit" ? newValue + value.unit : newValue, {
+ isEphemeral,
+ });
+ };
return (
- <Grid columns={2}>
+ <Grid css={{ gridTemplateColumns: "$columns$1" }}>
<PropertyName property={styleConfig.property} label={styleConfig.label} />
- <Grid css={gridTemplateStyle}>
- {Icon && (
- <Tooltip
- content={styleConfig.label}
- delayDuration={200}
- disableHoverableContent={true}
- >
- <IconButton
- onPointerEnter={(event) => {
- if (value.type !== "unit" || !textFieldRef.current) return;
- const textFieldNode = textFieldRef.current;
- numericScrubRef.current =
- numericScrubRef.current ||
- numericScrubControl(event.target as HTMLInputElement, {
- minValue: 0,
- initialValue: value.value as number,
- onValueChange: ({ value }) => {
- textFieldNode.value = String(value);
- setValue(String(value), { isEphemeral: true });
- },
- });
- }}
- onPointerLeave={() => {
- if (value.type !== "unit") return;
- numericScrubRef.current?.disconnectedCallback();
- numericScrubRef.current = undefined;
- }}
- onPointerUp={(event) => {
- setValue((event.target as HTMLInputElement).value);
- }}
- css={{
- ...iconButtonGridLeftStyle,
- ...(isCurrentBreakpoint && iconButtonActiveStyle),
- }}
- >
- {Icon && <Icon />}
- </IconButton>
- </Tooltip>
- )}
- {value.type === "unit" ? (
- <Units
- value={value.unit}
- items={commonUnitsSubset.map((unit) => ({
- name: unit,
- label: unit,
- }))}
- onChange={(unit) => setValue(value.value + unit)}
- onHover={(unit) =>
- setValue(value.value + unit, { isEphemeral: true })
- }
- />
- ) : (
- <Items
- value={value.value}
- items={styleConfig.items}
- onChange={(item) => setValue(item)}
- onHover={(item) => setValue(item, { isEphemeral: true })}
- />
- )}
- <TextField
- ref={textFieldRef}
- css={textFieldStyle}
- spellCheck={false}
- defaultValue={value.value}
- onFocus={(event: FocusEvent<HTMLInputElement>) =>
- event.target.select()
- }
- onBlur={(event: ChangeEvent<HTMLInputElement>) =>
- setValue(event.target.value)
- }
- onKeyDown={(event: KeyboardEvent<HTMLInputElement>) => {
- const target = event.target as HTMLInputElement;
- if (event.code === "Enter") {
- setValue(target.value);
- const number = parseFloat(target.value);
- if (!isNaN(number)) target.value = String(number);
- }
- if (value.type !== "unit") return;
- if (!["ArrowUp", "ArrowDown"].includes(event.code)) return;
- event.preventDefault();
- let currentValue = parseFloat(target.value);
- let currentDelta = 1;
- if (event.shiftKey) currentDelta = 10;
- if (event.altKey) currentDelta = 0.1;
- if (event.code === "ArrowUp")
- currentValue = currentValue + currentDelta;
- if (event.code === "ArrowDown")
- currentValue = currentValue - currentDelta;
- const currentValueAsString =
- currentValue % 1
- ? currentValue.toPrecision(
- Math.abs(currentValue).toString().indexOf(".") + 2
- )
- : String(currentValue);
- target.value = currentValueAsString;
- setValue(currentValueAsString, { isEphemeral: true });
- }}
- />
- </Grid>
- </Grid>
- );
-};
-
-const Units = ({
- value,
- items,
- onChange,
- onHover,
-}: {
- value: Unit;
- items: StyleConfig["items"];
- onChange?: (value: string) => void;
- onHover?: (value: string) => void;
-}) => {
- return (
- <Box css={iconButtonGridRightStyle}>
- <IconButtonWithMenu
- icon={
- <Text css={{ cursor: "default" }}>
- {value === "number" ? "—" : value}
- </Text>
- }
- items={items}
- value={String(value)}
- onChange={onChange}
- onHover={onHover}
+ <Combobox
+ name={styleConfig.property}
+ items={items.map((item) => item.label)}
+ value={String(value.value)}
+ selected={String(value.type === "unit" ? value.unit : value.value)}
+ onItemSelect={(item) => {
+ handleChange(value.type, item, false);
+ }}
+ onItemHighlight={(item) => {
+ handleChange(value.type, item, true);
+ }}
+ renderTextField={({ inputProps, toggleProps }) => {
+ return (
+ <Box css={{ position: "relative" }}>
+ <PropertyIcon
+ property={styleConfig.property}
+ label={styleConfig.label}
+ {...(value.type === "unit" && {
+ onPointerUp: (event: PointerEvent<HTMLInputElement>) => {
+ setValue(String(getInputNode(event.target).value));
+ },
+ ref: numericScrubRefCallback,
+ })}
+ />
+ <TextField
+ {...inputProps}
+ css={{
+ cursor: "default",
+ height: "calc($sizes$5 + $sizes$1)",
+ fontWeight: "500",
+ paddingLeft: "calc($sizes$4 / 2)",
+ }}
+ onFocus={(event: FocusEvent<HTMLInputElement>) => {
+ event.target.select();
+ }}
+ onBlur={(event) => {
+ if (event.target.value !== event.target.getAttribute("value"))
+ setValue(event.target.value);
+ }}
+ onKeyDown={(event) => {
+ const target = event.target as HTMLInputElement;
+ if (isExpanded(target)) return inputProps?.onKeyDown?.(event);
+ if (
+ event.code === "Enter" &&
+ String(value.value) !== target.value
+ ) {
+ setValue(target.value);
+ const number = parseFloat(target.value);
+ if (!isNaN(number)) target.value = String(number);
+ }
+ if (value.type !== "unit")
+ return inputProps?.onKeyDown?.(event);
+ if (!["ArrowUp", "ArrowDown"].includes(event.code)) return;
+ event.preventDefault();
+ let currentValue = parseFloat(target.value);
+ let currentDelta = 1;
+ if (event.shiftKey) currentDelta = 10;
+ if (event.altKey) currentDelta = 0.1;
+ if (event.code === "ArrowUp")
+ currentValue = currentValue + currentDelta;
+ if (event.code === "ArrowDown")
+ currentValue = currentValue - currentDelta;
+ const currentValueAsString =
+ currentValue % 1
+ ? currentValue.toPrecision(
+ Math.abs(currentValue).toString().indexOf(".") + 2
+ )
+ : String(currentValue);
+ target.value = currentValueAsString;
+ setValue(currentValueAsString, { isEphemeral: true });
+ }}
+ />
+ <IconButton
+ {...toggleProps}
+ css={{
+ visibility: items.length ? "visible" : "hidden",
+ position: "absolute",
+ right: "1px",
+ top: "1px",
+ width: "auto",
+ height: "calc(100% - 2px)",
+ px: "calc($1 / 2)",
+ borderRadius: "$1",
+ border: "2px solid $colors$loContrast",
+ "&:focus": {
+ outline: "none",
+ },
+ }}
+ >
+ {value.type === "unit" ? (
+ <Text
+ css={{
+ cursor: "default",
+ minWidth: "calc($sizes$3 - $nudge$1)",
+ textAlign: "center",
+ fontSize: "calc($fontSizes$1 - $nudge$1)",
+ }}
+ >
+ {value.unit === "number" ? "—" : value.unit}
+ </Text>
+ ) : (
+ <ChevronDownIcon />
+ )}
+ </IconButton>
+ </Box>
+ );
+ }}
/>
- </Box>
- );
-};
-
-const Items = ({
- value,
- items,
- onChange,
- onHover,
-}: {
- value: StyleValue["value"];
- items: StyleConfig["items"];
- onChange?: (value: string) => void;
- onHover?: (value: string) => void;
-}) => {
- if (!items?.length) return null;
- return (
- <Box css={iconButtonGridRightStyle}>
- <IconButtonWithMenu
- icon={<ChevronDownIcon />}
- items={items}
- value={String(value)}
- onChange={onChange}
- onHover={onHover}
- />
- </Box>
+ </Grid>
);
};
diff --git a/apps/designer/app/designer/features/style-panel/sections/layout/layout.tsx b/apps/designer/app/designer/features/style-panel/sections/layout/layout.tsx
index 0bbf5ba763..a7528ec2a3 100644
--- a/apps/designer/app/designer/features/style-panel/sections/layout/layout.tsx
+++ b/apps/designer/app/designer/features/style-panel/sections/layout/layout.tsx
@@ -37,10 +37,6 @@ const layoutSectionFlexStyle = {
"grid grid grid grid grid . . . . . . ."
"columnGap columnGap columnGap columnGap columnGap lock lock rowGap rowGap rowGap rowGap rowGap"
`,
- // @todo justifyItems icons are using justifycontent icons atm
- "& > [data-property=justifyItems]": {
- display: "none",
- },
"& [data-control=text]": {
"& > :first-child": {
gridTemplateColumns: "repeat(1, 1fr)",
@@ -49,6 +45,18 @@ const layoutSectionFlexStyle = {
},
},
},
+ // @todo justifyItems icons are using justifycontent icons atm
+ "& [data-property=justifyItems]": {
+ display: "none",
+ },
+ "& [data-property=columnGap]": {
+ gridArea: "6 / 1 / -1 / 7",
+ paddingRight: "10px",
+ },
+ "& [data-property=rowGap]": {
+ gridArea: "6 / 7 / -1 / -1",
+ paddingLeft: "10px",
+ },
};
const LayoutSectionFlex = ({
diff --git a/apps/designer/app/designer/features/style-panel/sections/layout/shared/flex-grid.tsx b/apps/designer/app/designer/features/style-panel/sections/layout/shared/flex-grid.tsx
index 077958a68e..723868f769 100644
--- a/apps/designer/app/designer/features/style-panel/sections/layout/shared/flex-grid.tsx
+++ b/apps/designer/app/designer/features/style-panel/sections/layout/shared/flex-grid.tsx
@@ -96,7 +96,14 @@ export const FlexGrid = ({
width: "100%",
height: "100%",
color: "$colors$gray8",
- "&:focus": { boxShadow: "none" },
+ "&:hover": {
+ bc: "$colors$slate4",
+ },
+ "&:focus": {
+ background: "none",
+ boxShadow: "none",
+ outline: "none",
+ },
}}
onClick={() => {
const [alignItems, justifyContent] = cells[index]
diff --git a/apps/designer/app/designer/features/style-panel/sections/layout/shared/lock.tsx b/apps/designer/app/designer/features/style-panel/sections/layout/shared/lock.tsx
index 3b55ef674f..c114965deb 100644
--- a/apps/designer/app/designer/features/style-panel/sections/layout/shared/lock.tsx
+++ b/apps/designer/app/designer/features/style-panel/sections/layout/shared/lock.tsx
@@ -1,5 +1,5 @@
import { useState, useEffect } from "react";
-import { IconButton, Tooltip } from "@webstudio-is/design-system";
+import { Flex, IconButton, Tooltip } from "@webstudio-is/design-system";
import { LockOpenIcon, LockCloseIcon } from "@webstudio-is/icons";
import type { Style } from "@webstudio-is/react-sdk";
import type { CreateBatchUpdate } from "../../../shared/use-style-data";
@@ -39,13 +39,25 @@ export const Lock = ({
delayDuration={400}
disableHoverableContent={true}
>
- <IconButton
+ <Flex
data-property={name}
- css={{ width: "100%", gridArea: name }}
- onClick={() => setIsPaired((value) => !value)}
+ css={{
+ width: "100%",
+ justifyContent: "center",
+ gridArea: name,
+ }}
>
- {isPaired ? <LockCloseIcon /> : <LockOpenIcon />}
- </IconButton>
+ <IconButton
+ css={{
+ "&:focus": {
+ outline: "none",
+ },
+ }}
+ onClick={() => setIsPaired((value) => !value)}
+ >
+ {isPaired ? <LockCloseIcon /> : <LockOpenIcon />}
+ </IconButton>
+ </Flex>
</Tooltip>
);
};
diff --git a/apps/designer/app/designer/features/style-panel/shared/property-name.tsx b/apps/designer/app/designer/features/style-panel/shared/property-name.tsx
index 4216db70f9..734fce91d0 100644
--- a/apps/designer/app/designer/features/style-panel/shared/property-name.tsx
+++ b/apps/designer/app/designer/features/style-panel/shared/property-name.tsx
@@ -1,39 +1,98 @@
-import { Flex, Label } from "@webstudio-is/design-system";
+import {
+ Flex,
+ Label,
+ Tooltip,
+ IconButton,
+ TextField,
+} from "@webstudio-is/design-system";
import { useIsFromCurrentBreakpoint } from "./use-is-from-current-breakpoint";
import { propertyNameColorForSelectedBreakpoint } from "./constants";
import type { PropertyProps } from "../style-sections";
+import { iconConfigs } from "./configs";
+import { forwardRef, PointerEventHandler } from "react";
export const PropertyName = ({ property, label, css }: PropertyProps) => {
const isCurrentBreakpoint = useIsFromCurrentBreakpoint(property);
return (
- <Flex
- css={{
- ...css,
- alignItems: "center",
- }}
- >
- <Label
+ <Tooltip content={label} delayDuration={600} disableHoverableContent={true}>
+ <Flex
css={{
- gridColumn: "1",
- fontWeight: "inherit",
- ...(isCurrentBreakpoint
- ? {
- color: propertyNameColorForSelectedBreakpoint,
- backgroundColor: "$colors$blue4",
- padding: "calc($radii$1 / 2) $radii$1",
- borderRadius: "$radii$1",
- }
- : {
- color: "$hiContrast",
- }),
+ ...css,
+ alignItems: "center",
}}
- variant="contrast"
- size="1"
- htmlFor={property}
>
- {label}
- </Label>
- </Flex>
+ <Label
+ css={{
+ gridColumn: "1",
+ fontWeight: "inherit",
+ ...(isCurrentBreakpoint
+ ? {
+ color: propertyNameColorForSelectedBreakpoint,
+ backgroundColor: "$colors$blue4",
+ padding: "calc($radii$1 / 2) $radii$1",
+ borderRadius: "$radii$1",
+ }
+ : {
+ color: "$hiContrast",
+ }),
+ }}
+ variant="contrast"
+ size="1"
+ htmlFor={property}
+ >
+ {label}
+ </Label>
+ </Flex>
+ </Tooltip>
);
};
+PropertyName.displayName = "PropertyName";
+
+export const PropertyIcon = forwardRef<
+ HTMLButtonElement,
+ PropertyProps & { [key: `on${string}`]: PointerEventHandler }
+>(({ property, label, ...props }, forwardRef) => {
+ const isCurrentBreakpoint = useIsFromCurrentBreakpoint(property);
+ const IconType = iconConfigs[property]?.normal;
+ if (!IconType) return null;
+
+ return (
+ <Tooltip content={label} delayDuration={600} disableHoverableContent={true}>
+ <IconButton
+ {...props}
+ ref={forwardRef}
+ variant="ghost"
+ size="1"
+ css={{
+ position: "absolute",
+ left: "1px",
+ top: "1px",
+ width: "$5",
+ height: "calc(100% - 2px)",
+ borderRadius: "$1",
+ border: "2px solid $colors$loContrast",
+ "&:hover,&:active,&:focus": {
+ bc: "$colors$slate4",
+ outline: "none",
+ },
+ ...(isCurrentBreakpoint && {
+ bc: "$colors$blue4",
+ color: "$colors$blue11",
+ outline: "none",
+ "&:hover,&:active,&:focus": {
+ bc: "$colors$blue4",
+ color: "$colors$blue11",
+ },
+ }),
+ [`& ~ ${TextField}`]: {
+ paddingLeft: "calc($sizes$5 + $sizes$1)",
+ },
+ }}
+ >
+ <IconType />
+ </IconButton>
+ </Tooltip>
+ );
+});
+PropertyIcon.displayName = "PropertyIcon";
diff --git a/apps/designer/app/designer/shared/inspector/collapsible-section.tsx b/apps/designer/app/designer/shared/inspector/collapsible-section.tsx
index fa27f5a4ab..7afee1d0dd 100644
--- a/apps/designer/app/designer/shared/inspector/collapsible-section.tsx
+++ b/apps/designer/app/designer/shared/inspector/collapsible-section.tsx
@@ -51,6 +51,7 @@ export const CollapsibleSection = ({
px: "$3",
color: "$hiContrast",
cursor: "default",
+ userSelect: "none",
}}
>
<Text css={{ fontWeight: "500", flexGrow: 1 }}>{label}</Text>
diff --git a/packages/design-system/src/components/combobox.tsx b/packages/design-system/src/components/combobox.tsx
index 11eadbde54..88750a3d0a 100644
--- a/packages/design-system/src/components/combobox.tsx
+++ b/packages/design-system/src/components/combobox.tsx
@@ -52,18 +52,36 @@ export const ComboboxTextField = forwardRef(ComboboxTextFieldBase);
ComboboxTextField.displayName = "ComboboxTextField";
-const Listbox = styled("ul", panelStyles, {
- padding: 0,
+const Listbox = styled("ul", {
margin: 0,
+ padding: 0,
overflow: "auto",
- // @todo need some non-hardcoded value
- maxHeight: 400,
- minWidth: 230,
+ minWidth: 124,
+ maxHeight: 190,
+ py: "$1",
+ backgroundColor: "$colors$slate4",
+ borderRadius: "$1",
+ boxShadow:
+ "0px 2px 7px rgba(0, 0, 0, 0.1), 0px 5px 17px rgba(0, 0, 0, 0.15), inset 0 0 1px 1px $colors$slate1, 0 0 0 1px $colors$slate8",
+ "&:empty": {
+ display: "none",
+ },
});
-const ListboxItem = styled("li", itemCss, {
- padding: 0,
- margin: 0,
+const ListboxItem = styled("li", {
+ all: "unset",
+ fontSize: "$2",
+ lineHeight: 1,
+ color: "$hiContrast",
+ display: "flex",
+ alignItems: "center",
+ height: "$5",
+ padding: "0 $2",
+ position: "relative",
+ "&[aria-selected=true]": {
+ backgroundColor: "$blue10",
+ color: "white",
+ },
});
type ListProps<Item> = {
@@ -119,6 +137,7 @@ type ComboboxProps<Item> = {
label?: string;
items: Array<Item>;
value?: Item;
+ selected?: Item;
onItemSelect?: (value: Item) => void;
onItemHighlight?: (value?: Item) => void;
itemToString?: (item: Item | null) => string;
@@ -134,6 +153,7 @@ type ComboboxProps<Item> = {
export const Combobox = <Item extends BaseItem>({
items,
value,
+ selected = value,
name,
itemToString = (item) =>
typeof item === "object" && item !== null && "label" in item
@@ -156,7 +176,6 @@ export const Combobox = <Item extends BaseItem>({
getComboboxProps,
highlightedIndex,
getItemProps,
- selectedItem,
} = useCombobox({
onInputValueChange({ inputValue }) {
if (inputValue) {
@@ -203,12 +222,14 @@ export const Combobox = <Item extends BaseItem>({
</PopperAnchor>
{renderPopperContent({
style: { zIndex: 1 },
+ align: "end",
+ sideOffset: 8,
children: renderList({
containerProps: menuProps,
items: isOpen ? foundItems : [],
getItemProps,
highlightedIndex,
- selectedItem,
+ selectedItem: selected as Item,
itemToString,
}),
})}
diff --git a/packages/design-system/src/components/icon-button-with-menu.tsx b/packages/design-system/src/components/icon-button-with-menu.tsx
index d8bc5da645..7f1bcc7345 100644
--- a/packages/design-system/src/components/icon-button-with-menu.tsx
+++ b/packages/design-system/src/components/icon-button-with-menu.tsx
@@ -30,8 +30,7 @@ const itemStyles = {
paddingRight: "$space$5",
userSelect: "none",
gap: "$space$2",
- // @todo should be "&[data-highlighted]" don't know why radix isn't activating the attribute though
- "&[tabindex='0']": {
+ "&[data-highlighted]": {
background: "$colors$blue10",
color: "$colors$blue1",
"& *": { fill: "$colors$blue1" },
@@ -52,7 +51,11 @@ const iconButtonStyle = {
height: "$6",
color: "$colors$gray12",
backgroundColor: "$colors$loContrast",
- "&:hover": {
+ "&:focus": {
+ outline: "none",
+ boxShadow: "inset 0 0 0 1px $colors$blue9, 0 0 0 1px $colors$blue9",
+ },
+ "&:hover,&:focus": {
backgroundColor: "$colors$gray3",
},
};
@@ -60,10 +63,11 @@ const iconButtonStyle = {
const iconButtonActiveStyle = {
color: "$colors$blue11",
backgroundColor: "$colors$blue4",
- "&:hover": {
+ "&:hover,&:focus": {
backgroundColor: "$colors$blue4",
},
"&:focus": {
+ outline: "none",
boxShadow: "inset 0 0 0 1px $colors$blue9, 0 0 0 1px $colors$blue9",
},
};
@@ -124,7 +128,7 @@ export const IconButtonWithMenu = ({
</DropdownMenuPrimitive.Trigger>
</Tooltip>
<DropdownMenuPrimitive.Portal>
- <StyledContent sideOffset={4} alignOffset={-4}>
+ <StyledContent sideOffset={4} collisionPadding={16} side="bottom">
<DropdownMenuPrimitive.RadioGroup
value={value}
onValueChange={onChange}
diff --git a/packages/design-system/src/components/icon-button.tsx b/packages/design-system/src/components/icon-button.tsx
index fec2f9fd30..2fb04a9a71 100644
--- a/packages/design-system/src/components/icon-button.tsx
+++ b/packages/design-system/src/components/icon-button.tsx
@@ -23,7 +23,7 @@ export const IconButton = styled("button", {
"&::before, &::after": {
boxSizing: "border-box",
},
- "&:hover, &:active": {
+ "&:focus, &:hover, &:active": {
backgroundColor: "$slate5",
},
"&:focus": {
diff --git a/packages/design-system/src/components/select.tsx b/packages/design-system/src/components/select.tsx
index 4db6ccad8a..56a1192ba1 100644
--- a/packages/design-system/src/components/select.tsx
+++ b/packages/design-system/src/components/select.tsx
@@ -1,6 +1,8 @@
import * as SelectPrimitive from "@radix-ui/react-select";
import noop from "lodash.noop";
import React, { ReactNode, Ref } from "react";
+import { Grid } from "./grid";
+import { Box } from "./box";
import { CheckIcon, ChevronDownIcon, ChevronUpIcon } from "@webstudio-is/icons";
import { styled } from "../stitches.config";
@@ -49,6 +51,9 @@ const StyledTrigger = styled(SelectPrimitive.SelectTrigger, {
const StyledIcon = styled(SelectPrimitive.Icon, {
display: "inline-flex",
alignItems: "center",
+ justifyContent: "center",
+ height: "100%",
+ padding: "calc($space$1 / 2)",
});
const StyledContent = styled(SelectPrimitive.Content, {
@@ -71,7 +76,7 @@ const StyledItem = styled(SelectPrimitive.Item, {
display: "flex",
alignItems: "center",
height: "$5",
- padding: "0 $6 0 $5",
+ padding: "0 $2",
position: "relative",
userSelect: "none",
@@ -81,20 +86,11 @@ const StyledItem = styled(SelectPrimitive.Item, {
},
"&:focus": {
- backgroundColor: "$blue9",
+ backgroundColor: "$blue10",
color: "white",
},
});
-const StyledItemIndicator = styled(SelectPrimitive.ItemIndicator, {
- position: "absolute",
- left: 0,
- width: 25,
- display: "inline-flex",
- alignItems: "center",
- justifyContent: "center",
-});
-
const scrollButtonStyles = {
display: "flex",
alignItems: "center",
@@ -120,10 +116,14 @@ const SelectItemBase = (
) => {
return (
<StyledItem {...props} ref={forwardedRef}>
- <SelectPrimitive.ItemText>{children}</SelectPrimitive.ItemText>
- <StyledItemIndicator>
- <CheckIcon />
- </StyledItemIndicator>
+ <Grid align="center" css={{ gridTemplateColumns: "$4 1fr" }}>
+ <SelectPrimitive.ItemIndicator>
+ <CheckIcon />
+ </SelectPrimitive.ItemIndicator>
+ <Box css={{ gridColumn: 2 }}>
+ <SelectPrimitive.ItemText>{children}</SelectPrimitive.ItemText>
+ </Box>
+ </Grid>
</StyledItem>
);
};
diff --git a/packages/design-system/src/stitches.config.ts b/packages/design-system/src/stitches.config.ts
index e159c2e7d7..3ad781ad76 100644
--- a/packages/design-system/src/stitches.config.ts
+++ b/packages/design-system/src/stitches.config.ts
@@ -271,6 +271,9 @@ export const {
4: "400",
max: "999",
},
+ columns: {
+ 1: "40% 60%",
+ },
},
media: {
bp1: "(min-width: 520px)",