From 774a3dd5100236debcdaea91128fc36f7f82195b Mon Sep 17 00:00:00 2001 From: Ludvig Rask <74653458+ludvigrask@users.noreply.github.com> Date: Wed, 4 Nov 2026 05:42:13 +0100 Subject: [PATCH] feat(ui): add input field appearances and surfaces to select (#61500) --- .../component-tests/input-surfaces.spec.ts | 56 ++++++++++++++++ packages/ui/src/forms/select/select.css | 65 +++++++++++++++---- .../ui/src/forms/select/select.stories.tsx | 41 +++++++++++- packages/ui/src/forms/select/select.tsx | 25 ++++--- 4 files changed, 164 insertions(+), 23 deletions(-) diff --git a/packages/app/component-tests/input-surfaces.spec.ts b/packages/app/component-tests/input-surfaces.spec.ts index b9679e188da..12806180f69 100644 --- a/packages/app/component-tests/input-surfaces.spec.ts +++ b/packages/app/component-tests/input-surfaces.spec.ts @@ -69,6 +69,62 @@ for (const control of ["text-input", "textarea"]) { }) } +story("select fields match the text input surfaces with inset feedback", async ({ mount, page }) => { + const root = await mount("ui-select--surfaces") + + const fields = root.locator('[data-component="select-v2"]') + + await page.addStyleTag({ + content: `[data-component="select-v2"] { + --v2-background-bg-base: rgb(20, 30, 40); + --v2-background-bg-layer-01: rgb(50, 60, 70); + --v2-overlay-simple-overlay-hover: rgba(10, 20, 30, 0.1); + --v2-elevation-input: 0px 0px 0px 3px rgb(1, 2, 3); + --v2-elevation-button-neutral: 0px 0px 0px 7px rgb(4, 5, 6); + }`, + }) + + const base = fields.nth(0) + + const invisible = fields.nth(2) + + await expect(base).toHaveCSS("background-color", "rgb(20, 30, 40)") + await expect(fields.nth(1)).toHaveCSS("background-color", "rgb(50, 60, 70)") + await expect(base).toHaveCSS("box-shadow", "rgb(1, 2, 3) 0px 0px 0px 3px") + await expect(base).toHaveCSS("background-image", "none") + await expect(invisible).toHaveCSS("background-color", "rgba(0, 0, 0, 0)") + await expect(invisible).toHaveCSS("box-shadow", "none") + + await base.hover() + await expect + .poll(() => base.evaluate((element) => getComputedStyle(element).boxShadow)) + .toContain("rgb(1, 2, 3) 0px 0px 0px 3px") + await expect(base).toHaveCSS("background-color", "rgb(20, 30, 40)") + + await invisible.hover() + await expect(invisible).toHaveCSS("background-color", "rgba(10, 20, 30, 0.1)") + await expect(invisible).toHaveCSS("box-shadow", "none") + + const invalid = root.locator("[data-invalid]") + + await expect(invalid).toHaveCSS("outline-width", "1px") + await expect(invalid).toHaveCSS("outline-offset", "-1px") + await expect(invalid).not.toHaveCSS("outline-color", "rgba(0, 0, 0, 0)") +}) + +story("select fields come in the text input sizes and default to the inline trigger", async ({ mount }) => { + const root = await mount("ui-select--appearances") + + const fields = root.locator('[data-component="select-v2"]') + + for (const [index, height] of [24, 28, 32].entries()) { + await expect(fields.nth(index)).toHaveCSS("height", `${height}px`) + } + + await expect(fields.nth(3)).toHaveAttribute("data-appearance", "inline") + await expect(fields.nth(3)).toHaveCSS("box-shadow", "none") +}) + story( "text inputs keep clear and copy actions equally sized and inset across sizes and directions", async ({ mount, page }) => { diff --git a/packages/ui/src/forms/select/select.css b/packages/ui/src/forms/select/select.css index aa7c30f9d52..54f48b2e53a 100644 --- a/packages/ui/src/forms/select/select.css +++ b/packages/ui/src/forms/select/select.css @@ -32,10 +32,9 @@ border: 0; border-radius: 6px; outline: 1px solid transparent; - outline-offset: 0; - background: - linear-gradient(180deg, var(--v2-alpha-light-2) 0%, var(--v2-alpha-light-0) 100%), var(--v2-background-bg-base); - box-shadow: var(--v2-elevation-button-neutral); + outline-offset: -1px; + background: var(--v2-background-bg-base); + box-shadow: var(--v2-elevation-input); flex: none; align-self: stretch; user-select: none; @@ -45,21 +44,59 @@ box-shadow 85ms ease-out; } -[data-component="select-v2"]:where(:hover):not([data-disabled], [data-invalid]):not(:focus-within):not( - [data-expanded] - ) { - background: - linear-gradient(0deg, var(--v2-overlay-simple-overlay-hover), var(--v2-overlay-simple-overlay-hover)), - linear-gradient(180deg, var(--v2-alpha-light-2) 0%, var(--v2-alpha-light-0) 100%), var(--v2-background-bg-base); +[data-component="select-v2"][data-appearance="small"] { + height: 24px; } -[data-component="select-v2"]:where([data-expanded]):not([data-disabled], [data-invalid]) { - background: - linear-gradient(0deg, var(--v2-overlay-simple-overlay-hover), var(--v2-overlay-simple-overlay-hover)), - linear-gradient(180deg, var(--v2-alpha-light-2) 0%, var(--v2-alpha-light-0) 100%), var(--v2-background-bg-base); +[data-component="select-v2"][data-appearance="large"] { + height: 32px; + padding-inline: 0 8px; +} + +[data-component="select-v2"][data-surface="layer-1"] { + background: var(--v2-background-bg-layer-01); +} + +[data-component="select-v2"][data-surface="invisible"] { + background: transparent; + box-shadow: none; +} + +/* An inset overlay keeps the surface colour underneath, the same hover the text input uses. */ +@media (hover: hover) { + [data-component="select-v2"]:where(:hover):not( + [data-disabled], + [data-invalid], + [data-expanded], + [data-appearance="inline"], + [data-surface="invisible"] + ):not(:focus-within) { + box-shadow: + inset 0 0 0 100vmax var(--v2-overlay-simple-overlay-hover), + var(--v2-elevation-input); + } + + [data-component="select-v2"][data-surface="invisible"]:where(:hover):not( + [data-disabled], + [data-invalid], + [data-expanded] + ):not(:focus-within) { + background: var(--v2-overlay-simple-overlay-hover); + } +} + +[data-component="select-v2"]:where([data-expanded]):not([data-disabled], [data-invalid], [data-appearance="inline"]) { + box-shadow: + inset 0 0 0 100vmax var(--v2-overlay-simple-overlay-hover), + var(--v2-elevation-input); outline-color: transparent; } +[data-component="select-v2"][data-surface="invisible"]:where([data-expanded]):not([data-disabled], [data-invalid]) { + background: var(--v2-overlay-simple-overlay-hover); + box-shadow: none; +} + [data-component="select-v2"]:where(:focus-within):not([data-disabled], [data-invalid]):not([data-expanded]) { outline-color: var(--v2-border-border-focus); box-shadow: none; diff --git a/packages/ui/src/forms/select/select.stories.tsx b/packages/ui/src/forms/select/select.stories.tsx index 66805fdd5a1..4da62ccf6a2 100644 --- a/packages/ui/src/forms/select/select.stories.tsx +++ b/packages/ui/src/forms/select/select.stories.tsx @@ -16,9 +16,11 @@ const cities: { city: string; region: Region }[] = [ ] const docs = `### Overview -Single-select built on Kobalte with an inline trigger and current menu styling. +Single-select built on Kobalte with current menu styling. The trigger is inline by default, or an input field that matches the text input. ### API +- \`appearance\`: \`inline\` (default) is the borderless trigger; \`small\`, \`base\` and \`large\` are 24px, 28px and 32px input fields. +- \`surface\`: \`base\` (default), \`layer-1\` or \`invisible\` for input fields; invisible gains a fill on hover. - \`placeholder\`: Shown in the trigger when nothing is selected (same idea as text inputs). - \`options\`, \`current\`, \`onSelect\`: controlled selection (\`current\` is the selected option object). - \`value\` / \`label\`: accessors when options are not plain strings. @@ -126,6 +128,43 @@ export const Disabled = { ), } +export const Appearances = { + render: () => ( +