|
| 1 | +import { expect, story } from "../../stories/playwright/story" |
| 2 | + |
| 3 | +for (const control of ["text-input", "textarea"]) { |
| 4 | + story(`${control} supports its surfaces with inset feedback and stable geometry`, async ({ mount, page }) => { |
| 5 | + const root = await mount(`ui-${control}--surfaces`) |
| 6 | + |
| 7 | + const fields = root.locator(`[data-component="${control}-v2"]`) |
| 8 | + |
| 9 | + await page.addStyleTag({ |
| 10 | + content: `[data-component="${control}-v2"] { |
| 11 | + --v2-background-bg-base: rgb(20, 30, 40); |
| 12 | + --v2-background-bg-layer-01: rgb(50, 60, 70); |
| 13 | + --v2-overlay-simple-overlay-hover: rgba(10, 20, 30, 0.1); |
| 14 | + --v2-elevation-input: 0px 0px 0px 3px rgb(1, 2, 3); |
| 15 | + --v2-elevation-button-neutral: 0px 0px 0px 7px rgb(4, 5, 6); |
| 16 | + }`, |
| 17 | + }) |
| 18 | + |
| 19 | + await expect(fields.nth(0)).toHaveCSS("background-color", "rgb(20, 30, 40)") |
| 20 | + await expect(fields.nth(1)).toHaveCSS("background-color", "rgb(50, 60, 70)") |
| 21 | + await expect(fields.nth(0)).toHaveCSS("box-shadow", "rgb(1, 2, 3) 0px 0px 0px 3px") |
| 22 | + await expect(fields.nth(1)).toHaveCSS("box-shadow", "rgb(1, 2, 3) 0px 0px 0px 3px") |
| 23 | + |
| 24 | + for (const field of await fields.all()) { |
| 25 | + await expect(field).toHaveCSS("background-image", "none") |
| 26 | + } |
| 27 | + |
| 28 | + const base = fields.nth(0) |
| 29 | + |
| 30 | + const geometry = await base.getByRole("textbox").boundingBox() |
| 31 | + |
| 32 | + await base.hover() |
| 33 | + await expect |
| 34 | + .poll(() => base.evaluate((element) => getComputedStyle(element).boxShadow)) |
| 35 | + .toContain("rgb(1, 2, 3) 0px 0px 0px 3px") |
| 36 | + await base.getByRole("textbox").fill("Still editable") |
| 37 | + await expect(base.getByRole("textbox")).toHaveValue("Still editable") |
| 38 | + await expect(base).toHaveCSS("outline-width", "1px") |
| 39 | + await expect(base).toHaveCSS("outline-offset", "-1px") |
| 40 | + await expect(base).not.toHaveCSS("outline-color", "rgba(0, 0, 0, 0)") |
| 41 | + expect(await base.getByRole("textbox").boundingBox()).toEqual(geometry) |
| 42 | + |
| 43 | + const invalid = root.locator("[data-invalid]") |
| 44 | + |
| 45 | + const disabled = root.locator("[data-disabled]") |
| 46 | + |
| 47 | + await expect(invalid).toHaveCSS("outline-width", "1px") |
| 48 | + await expect(invalid).toHaveCSS("outline-offset", "-1px") |
| 49 | + await expect(invalid).not.toHaveCSS("outline-color", "rgba(0, 0, 0, 0)") |
| 50 | + await expect(invalid.getByRole("textbox")).toHaveAttribute("aria-invalid", "true") |
| 51 | + await expect(disabled.getByRole("textbox")).toBeDisabled() |
| 52 | + |
| 53 | + if (control === "textarea") return |
| 54 | + |
| 55 | + const invisible = root.locator('[data-surface="invisible"]').first() |
| 56 | + |
| 57 | + await base.getByRole("textbox").blur() |
| 58 | + await expect(invisible).toHaveCSS("background-color", "rgba(0, 0, 0, 0)") |
| 59 | + await invisible.hover() |
| 60 | + await expect(invisible).toHaveCSS("background-color", "rgba(10, 20, 30, 0.1)") |
| 61 | + await expect(invisible).toHaveCSS("box-shadow", "none") |
| 62 | + await invisible.getByRole("textbox").focus() |
| 63 | + await expect(invisible).toHaveCSS("background-color", "rgba(0, 0, 0, 0)") |
| 64 | + await expect(invisible).toHaveCSS("outline-offset", "-1px") |
| 65 | + await expect(invisible).not.toHaveCSS("outline-color", "rgba(0, 0, 0, 0)") |
| 66 | + await expect(invalid).toHaveCSS("background-color", "rgba(0, 0, 0, 0)") |
| 67 | + await expect(disabled).toHaveCSS("background-color", "rgba(0, 0, 0, 0)") |
| 68 | + await expect(disabled).toHaveCSS("box-shadow", "none") |
| 69 | + }) |
| 70 | +} |
| 71 | + |
| 72 | +story( |
| 73 | + "text inputs keep clear and copy actions equally sized and inset across sizes and directions", |
| 74 | + async ({ mount, page }) => { |
| 75 | + const root = await mount("ui-text-input--appearances") |
| 76 | + |
| 77 | + const fields = root.locator('[data-component="text-input-v2"]') |
| 78 | + |
| 79 | + for (const [index, height] of [24, 28, 32, 32, 24, 28, 32].entries()) { |
| 80 | + await expect(fields.nth(index)).toHaveCSS("height", `${height}px`) |
| 81 | + } |
| 82 | + |
| 83 | + for (const direction of ["ltr", "rtl"]) { |
| 84 | + await page.evaluate((dir) => (document.documentElement.dir = dir), direction) |
| 85 | + |
| 86 | + for (const field of await fields.filter({ has: page.getByRole("button") }).all()) { |
| 87 | + const button = field.getByRole("button") |
| 88 | + |
| 89 | + await expect(button).toHaveCSS("width", "20px") |
| 90 | + await expect(button).toHaveCSS("height", "20px") |
| 91 | + await expect(button).toHaveCSS("padding", "2px") |
| 92 | + await expect(button).toHaveCSS("border-radius", "4px") |
| 93 | + |
| 94 | + expect( |
| 95 | + await field.evaluate((element) => { |
| 96 | + const bounds = element.getBoundingClientRect() |
| 97 | + |
| 98 | + const action = element.querySelector("button")!.getBoundingClientRect() |
| 99 | + |
| 100 | + return { |
| 101 | + inset: |
| 102 | + getComputedStyle(element).direction === "rtl" ? action.left - bounds.left : bounds.right - action.right, |
| 103 | + center: action.y + action.height / 2 - bounds.y - bounds.height / 2, |
| 104 | + } |
| 105 | + }), |
| 106 | + ).toEqual({ inset: 8, center: 0 }) |
| 107 | + } |
| 108 | + } |
| 109 | + }, |
| 110 | +) |
0 commit comments