Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/shared/design-system/DESIGN.md
Original file line number Diff line number Diff line change
Expand Up @@ -1126,6 +1126,11 @@ filtering, custom-value commits, and async requests with the feature. Its Contro
owns the label, input and integrated browse caret; Popup and Item own the shared
menu presentation. For a closed dropdown with search inside, use Combobox.Trigger
and Combobox.Popup with search; opening focuses the popup search input.
In a row of compact controls, such as beside a compact Select, use
`Combobox.Trigger variant="compact"`: the same outlined capsule as a compact
Select, with its label announced rather than shown. Combobox menus keep the
compact Select's minimum width, so a narrow trigger such as an avatar stack never
squeezes its choices.
Use its loading state while discovering options, and keep
retry/cancel actions with the feature. Do not style a native select as an Input
or attach a separate round button to mimic a combobox.
Expand Down
24 changes: 24 additions & 0 deletions src/shared/design-system/styles/forms.css
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,21 @@
display: flex;
flex-shrink: 0;
}
/* Artwork in a compact value, such as a Combobox trigger's avatar stack,
aligns to the line box instead of the text baseline, so the trigger keeps
the compact Select's height. Identity artwork tucks toward the leading
edge, as small identity buttons do. */
.buzz-select[data-variant="compact"]
.buzz-select-value
> :is([data-avatar-stack], svg) {
vertical-align: top;
}
.buzz-select[data-variant="compact"]
.buzz-button[data-size="sm"]:has(
.buzz-select-value > [data-avatar-stack]:first-child
) {
padding-inline-start: var(--space-1h);
}
.buzz-select-popup[data-variant="compact"] {
min-width: min(
max(var(--anchor-width), 11.25rem),
Expand Down Expand Up @@ -433,6 +448,15 @@
width: var(--anchor-width);
overflow-wrap: anywhere;
}
/* A combobox menu can open from a trigger narrower than its choices, such as
a compact avatar trigger. Keep the compact Select's minimum so names never
break mid-word. */
.buzz-select-popup[data-combobox-size] {
min-width: min(
max(var(--anchor-width), 11.25rem),
calc(100vw - var(--space-6))
);
}
/* Roughly four avatar-and-detail rows plus search. The viewport may make
the list shorter; keep search fixed and every result scrollable. */
.buzz-select-popup[data-combobox-size="compact"] {
Expand Down
24 changes: 24 additions & 0 deletions src/shared/design-system/ui/ChoiceControls.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -395,3 +395,27 @@ it("defaults combobox queries to exact text while permitting explicit correction
expect(input).toHaveAttribute("autocapitalize", "sentences");
expect(input).toHaveAttribute("spellcheck", "true");
});

it("names a compact Combobox trigger without showing its label", async () => {
const user = userEvent.setup();
render(
<Combobox.Root items={options}>
<Combobox.Trigger variant="compact" label="Assignees">
Nobody
</Combobox.Trigger>
<Combobox.Popup search empty="No choices">
<Combobox.List>
{(item: (typeof options)[number]) => (
<Combobox.Item value={item} key={item.value}>
{item.label}
</Combobox.Item>
)}
</Combobox.List>
</Combobox.Popup>
</Combobox.Root>,
);
const trigger = screen.getByRole("combobox", { name: "Assignees" });
expect(screen.queryByText("Assignees")).not.toBeInTheDocument();
await user.click(trigger);
expect(await screen.findByRole("option", { name: "One" })).toBeVisible();
});
51 changes: 46 additions & 5 deletions src/shared/design-system/ui/Combobox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { CaretDownIcon, CircleNotchIcon, CheckIcon } from "../icons";
import { Field } from "./Field";
import { InputGroup } from "./InputGroup";
import { IconButton } from "./IconButton";
import { Button } from "./Button";

/** Shared presentation; callers retain filtering, custom values and async work. */
function Control({
Expand Down Expand Up @@ -94,20 +95,60 @@ function Control({
);
}

/** A button-style field for comboboxes whose search input lives in the popup. */
/** A button-style trigger for comboboxes whose search input lives in the popup.
* `field` is a labelled form field. `compact` matches Select's compact
* variant: a small outlined capsule whose label is announced, not shown, for
* rows of adjacent controls. */
function Trigger({
label,
children,
error,
disabled,
...props
}: {
label: string;
children: ReactNode;
error?: ReactNode;
disabled?: boolean | undefined;
}) {
} & (
| { variant?: "field"; error?: ReactNode }
| { variant: "compact"; error?: never }
)) {
if (props.variant === "compact")
return (
<div
data-buzz-ui=""
className="buzz-select text-body"
data-variant="compact"
data-appearance="outlined"
>
<BaseCombobox.Trigger
aria-label={label}
disabled={disabled}
render={(triggerProps) => (
<Button
{...triggerProps}
shape="capsule"
variant="outline"
size="sm"
>
<span className="buzz-select-value-content">
<span className="buzz-select-value-text">
<span className="buzz-select-value">{children}</span>
</span>
</span>
<span>
<CaretDownIcon
size={14}
className="buzz-dropdown-chevron"
aria-hidden="true"
/>
</span>
</Button>
)}
/>
</div>
);
return (
<Field label={label} error={error}>
<Field label={label} error={props.error}>
<BaseCombobox.Trigger
aria-label={label}
disabled={disabled}
Expand Down
67 changes: 67 additions & 0 deletions tests/fixtures/design-system/ui/FormSpecimens.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { Select } from "../../../../src/shared/design-system/ui/Select";
import { PreferenceRow } from "../../../../src/shared/design-system/ui/PreferenceRow";
import { SettingsGroup } from "../../../../src/shared/design-system/ui/SettingsGroup";
import { Combobox } from "../../../../src/shared/design-system/ui/Combobox";
import { AvatarStack } from "../../../../src/shared/design-system/ui/AvatarStack";
import { Button } from "../../../../src/shared/design-system/ui/Button";

import { IconButton } from "../../../../src/shared/design-system/ui/IconButton";
Expand Down Expand Up @@ -758,6 +759,63 @@ function PopupSearchExample({ compact = false }: { compact?: boolean }) {
);
}

function CompactTriggerExample() {
const people = ["Riley", "Wes", "Priya", "Dana"];
const [status, setStatus] = useState("in_progress");
const [chosen, setChosen] = useState<string[]>(["Riley"]);
return (
<div className="flex flex-wrap items-center gap-2">
<Select
label="Status"
variant="compact"
value={status}
onValueChange={setStatus}
groups={[
{
label: "",
options: [
{ value: "todo", label: "To do" },
{ value: "in_progress", label: "In progress" },
{ value: "done", label: "Done" },
],
},
]}
/>
<Combobox.Root
items={people}
multiple
value={chosen}
onValueChange={setChosen}
>
<Combobox.Trigger variant="compact" label="Assignees">
{chosen.length ? (
<AvatarStack
size="mini"
max={4}
items={chosen.map((name) => ({
id: name,
name,
shape: "circle",
}))}
/>
) : (
"Nobody"
)}
</Combobox.Trigger>
<Combobox.Popup search size="compact" empty="No one here matches.">
<Combobox.List>
{(item: string) => (
<Combobox.Item key={item} value={item}>
{item}
</Combobox.Item>
)}
</Combobox.List>
</Combobox.Popup>
</Combobox.Root>
</div>
);
}

export function ComboboxExamples() {
const [state, setState] = useState<ExampleState>("ready");
return (
Expand All @@ -779,6 +837,15 @@ ${workspaceComboboxCode}`}
<WorkspaceCombobox label="Read-only choices" readOnly />
<WorkspaceCombobox label="Disabled choices" disabled />
</FormExample>
<FormExample
title="Compact trigger"
description="In a row of compact controls, the trigger matches a compact Select and announces its label. The menu keeps a minimum width, so short triggers never squeeze names."
code={`<Combobox.Trigger variant="compact" label="Assignees">
<AvatarStack size="mini" items={assignees} />
</Combobox.Trigger>`}
>
<CompactTriggerExample />
</FormExample>
<FormExample
title="Loading, empty, and recovery"
description="Choose a sample state to inspect loading or failure, then use the recovery action. These examples make no service requests. Features own requests, cancellation, and custom values."
Expand Down
Loading