An open source design system that's fully customizable and agent ready
TypeScript
fix(Token): keep remove target off adjacent text (#7728)
zakelstorm085e145dfce5
diff --git a/.changeset/small-token-remove-target.md b/.changeset/small-token-remove-target.mdnew file mode 100644index 0000000000..103a578cc6--- /dev/null+++ b/.changeset/small-token-remove-target.md@@ -0,0 +1,6 @@+---+'@astryxdesign/core': patch+---++[fix] Shrink Token's invisible remove-button target from 44px to 24px without changing the visible icon. Clicking adjacent text or values in PowerSearch now edits the filter instead of accidentally removing it.+@korkt-kimdiff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlindex 938e571178..d8e95ca2f1 100644--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@ -1383,6 +1383,16 @@ jobs:--project chromium \--output menu-header-footer-output+ # A Token's remove target is enlarged past its 16px X, and only a real+ # engine hit-tests it: a press on the end of the value beside the X must+ # run the token's own action, and a press just outside the X must remove.+ - name: Run Token remove target contract+ run: |+ pnpm exec playwright test \+ packages/core/src/Token/__tests__/TokenRemoveTarget.a11y.chromium.spec.ts \+ --project chromium \+ --output token-remove-target-output+# The RichTextEditor "Markdown parity" stories render one Markdown# document with core Markdown and RichTextEditor and measure where each# block lands; geometry, the read/edit switch and the scroll anchor onlydiff --git a/packages/core/src/Token/Token.tsx b/packages/core/src/Token/Token.tsxindex ec52cf6db4..780e3b8597 100644--- a/packages/core/src/Token/Token.tsx+++ b/packages/core/src/Token/Token.tsx@@ -190,7 +190,7 @@ const styles = stylex.create({'::after': {content: '""',position: 'absolute',- inset: '-14px',+ inset: '-4px',},},});diff --git a/packages/core/src/Token/__tests__/TokenRemoveTarget.a11y.chromium.spec.ts b/packages/core/src/Token/__tests__/TokenRemoveTarget.a11y.chromium.spec.tsnew file mode 100644index 0000000000..b991ebf61b--- /dev/null+++ b/packages/core/src/Token/__tests__/TokenRemoveTarget.a11y.chromium.spec.ts@@ -0,0 +1,86 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.++/**+ * @file TokenRemoveTarget.a11y.chromium.spec.ts+ * @input The `Core/PowerSearch` Pre-set Filters story in a built Storybook and+ * real mouse input, in both text directions.+ * @output Real-engine proof that a Token's enlarged remove target stays on its+ * X: a press on the end of the value beside it runs the token's own action,+ * and a press just outside the visible X still removes.+ * @position Run with `pnpm test:a11y-contract`. jsdom has no hit testing, so+ * the remove target's reach is only observable here.+ */++import {expect, test, type Page} from '@playwright/test';+import {+ DEFAULT_STORYBOOK_DIR,+ serveStorybook,+ type StaticServer,+} from '@astryxdesign/a11y-spec/storybook';++let storybook: StaticServer;++test.beforeAll(async () => {+ storybook = await serveStorybook(+ process.env.ASTRYX_STORYBOOK_DIR ?? DEFAULT_STORYBOOK_DIR,+ );+});++test.afterAll(async () => {+ await storybook?.close();+});++const STORY = 'core-powersearch--with-preset-filters';+const REMOVE_BUTTONS = '#storybook-root button[aria-label^="Remove "]';++async function open(page: Page, direction: 'ltr' | 'rtl') {+ await page.setViewportSize({width: 900, height: 600});+ await page.goto(+ `${storybook.origin}/iframe.html?id=${STORY}&viewMode=story&globals=direction:${direction}`,+ );+ await expect(page.locator(REMOVE_BUTTONS)).toHaveCount(2);+ const remove = page.locator(REMOVE_BUTTONS).first();+ const value = page+ .locator('#storybook-root')+ .getByText('Open', {exact: true})+ .first();+ const x = await remove.boundingBox();+ const v = await value.boundingBox();+ if (x == null || v == null) {+ throw new Error('the Status token has no visible value or remove button');+ }+ return {remove, x, v};+}++for (const direction of ['ltr', 'rtl'] as const) {+ test(`a press on the end of the value opens its editor (${direction})`, async ({+ page,+ }) => {+ const {x, v} = await open(page, direction);+ // Two pixels inside the value's inline-end edge, level with the X.+ const px = direction === 'ltr' ? v.x + v.width - 2 : v.x + 2;+ const py = x.y + x.height / 2;+ // Precondition: the point is on the value, not on the visible X.+ expect(px < x.x || px > x.x + x.width).toBe(true);++ await page.mouse.click(px, py);++ await expect(page.getByRole('combobox', {name: 'Field'})).toBeVisible();+ await expect(page.locator(REMOVE_BUTTONS)).toHaveCount(2);+ });++ test(`a press just outside the visible X still removes (${direction})`, async ({+ page,+ }) => {+ const {x} = await open(page, direction);+ // Two pixels past the X's inline-end edge: outside the 16px glyph, inside+ // the enlarged target.+ const px = direction === 'ltr' ? x.x + x.width + 2 : x.x - 2;+ const py = x.y + x.height / 2;++ await page.mouse.click(px, py);++ await expect(page.locator(REMOVE_BUTTONS)).toHaveCount(1);+ await expect(page.getByRole('combobox', {name: 'Field'})).toHaveCount(0);+ });+}