An open source design system that's fully customizable and agent ready
TypeScript
[Component Audit] ContextMenuItem: make browser evidence trustworthy (#7237)
Cindy Zhang7c8ddf211857
diff --git a/.github/scripts/accessibility-audit.integration.test.mjs b/.github/scripts/accessibility-audit.integration.test.mjsindex 04cf035378..7e072305e4 100644--- a/.github/scripts/accessibility-audit.integration.test.mjs+++ b/.github/scripts/accessibility-audit.integration.test.mjs@@ -23,6 +23,7 @@ const Module = require('node:module');const originalLoad = Module._load;let requestedUrl = '';let reads = 0;+let selectorResolved = false;function scenarioState() {const scenario = process.env.A11Y_TEST_SCENARIO;@@ -66,6 +67,16 @@ function evaluateInFixture(fn, arg) {const page = {goto: async url => { requestedUrl = url; },addStyleTag: async () => {},+ waitForSelector: async (selector, options) => {+ if (process.env.A11Y_TEST_SCENARIO === 'selector-missing') {+ throw new Error('selector did not become visible: ' + selector);+ }+ if (options?.state !== 'visible') {+ throw new Error('readiness selector must wait for visible state');+ }+ selectorResolved = true;+ return {};+ },evaluate: async (fn, arg) => evaluateInFixture(fn, arg),close: async () => {},};@@ -74,7 +85,12 @@ const browser = {newContext: async () => context, close: async () => {}};class FakeAxeBuilder {disableRules() { return this; }- async analyze() { return {violations: []}; }+ async analyze() {+ if (process.argv.includes('--ready-selector') && !selectorResolved) {+ throw new Error('axe ran before the readiness selector resolved');+ }+ return {violations: []};+ }}Module._load = function(request, parent, isMain) {@@ -88,7 +104,12 @@ Module._load = function(request, parent, isMain) {};`;-function runFixture(scenario, indexContent, components = 'core/Button') {+function runFixture(+ scenario,+ indexContent,+ components = 'core/Button',+ readySelector = null,+) {const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'a11y-cli-fixture-'));const storybook = path.join(dir, 'storybook');const output = path.join(dir, 'report.json');@@ -111,6 +132,9 @@ function runFixture(scenario, indexContent, components = 'core/Button') {components,'--port',String(port),+ ...(readySelector == null+ ? []+ : ['--ready-selector', readySelector]),],{cwd: REPO_ROOT,@@ -163,6 +187,31 @@ describe.sequential('accessibility-audit CLI readiness', () => {expect(result.report.auditedStoryKeys).toHaveLength(1);});+ it('waits for a focused readiness selector and records it in the report', () => {+ const result = runFixture(+ 'delayed',+ VALID_INDEX,+ 'core/Button',+ '[role="menu"]',+ );+ expect(result.status).toBe(0);+ expect(result.report.readySelector).toBe('[role="menu"]');+ });++ it('fails closed when a focused readiness selector stays absent', () => {+ const result = runFixture(+ 'selector-missing',+ VALID_INDEX,+ 'core/Button',+ '[role="menu"]',+ );+ expect(result.status).not.toBe(0);+ expect(result.stderr).toContain(+ 'selector did not become visible: [role="menu"]',+ );+ expect(result.report).toBeNull();+ });+it('routes a11y contract fixtures to canonical owners and legacy aliases', () => {const result = runFixture('delayed',diff --git a/.github/scripts/accessibility-audit.js b/.github/scripts/accessibility-audit.jsindex 62187f9904..ca62e578ee 100644--- a/.github/scripts/accessibility-audit.js+++ b/.github/scripts/accessibility-audit.js@@ -5,7 +5,7 @@/*** @description Runs accessibility audits on component stories using axe-core* @input --storybook-dir <path> --output <file> [--components <comma-separated>]- * [--port <number>]+ * [--port <number>] [--ready-selector <css-selector>]* --baseline <path> (compare violations against a checked-in baseline)* --fail-on-new (exit 1 when violations not present in the baseline exist)* --update-baseline (rewrite the baseline file from this run's report)@@ -61,6 +61,7 @@ const components = (componentsArg || '').split(',').filter(Boolean);// means "all stories" (the a11y-weekly contract).const emptyComponentSet = componentsArg !== null && components.length === 0;const baselineFile = getArg('baseline');+const readySelector = getArg('ready-selector');const failOnNew = hasFlag('fail-on-new');const updateBaseline = hasFlag('update-baseline');@@ -337,6 +338,12 @@ async function runAccessibilityAudit() {),{timeoutMs: 5000, pollMs: 50},);+ if (readySelector != null) {+ await page.waitForSelector(readySelector, {+ state: 'visible',+ timeout: 5000,+ });+ }// Run axe-core accessibility analysisconst results = await new AxeBuilder({ page })@@ -455,6 +462,7 @@ async function runAccessibilityAudit() {}const report = {+ readySelector,ownerStoryRoutes: routed.ownerStoryRoutes,ownerStoryKeys,auditedStories,diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlindex a7acba54f8..0a4f0fc406 100644--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@ -1674,6 +1674,31 @@ jobs:retention-days: 30if-no-files-found: error+ # ContextMenuItem opens from a pointer gesture after the trigger renders.+ # The focused selector wait binds axe to the open menu rather than letting+ # the trigger's first frame satisfy generic Storybook readiness.+ - name: Run ContextMenuItem audit browser evidence+ if: github.event_name == 'pull_request' && startsWith(github.event.pull_request.title, '[Component Audit] ContextMenuItem:')+ env:+ ASTRYX_HEAD_SHA: ${{ github.event.pull_request.head.sha }}+ run: |+ node .github/scripts/accessibility-audit.js \+ --storybook-dir apps/storybook/dist \+ --output context-menu-item-a11y-report.json \+ --components ContextMenuItem \+ --ready-selector '[role="menu"]' \+ --baseline .github/a11y-baseline.json \+ --fail-on-new++ - name: Upload ContextMenuItem audit evidence+ if: always() && github.event_name == 'pull_request' && startsWith(github.event.pull_request.title, '[Component Audit] ContextMenuItem:')+ uses: actions/upload-artifact@v7+ with:+ name: context-menu-item-audit-evidence-${{ needs.build-storybook.outputs.short_hash }}+ path: context-menu-item-a11y-report.json+ retention-days: 30+ if-no-files-found: error+# The CheckboxList and CheckboxListItem component audits grade the same# option rows: interactive row paint, focus, busy, disabled, read-only,# status, narrow, forced-colors, and RTL states from exact-head Chromiumdiff --git a/apps/storybook/rtl-audit/targets.json b/apps/storybook/rtl-audit/targets.jsonindex 0bec104343..6b12d1dd1b 100644--- a/apps/storybook/rtl-audit/targets.json+++ b/apps/storybook/rtl-audit/targets.json@@ -184,6 +184,15 @@"storyId": "core-chatcomposer--with-streaming","dims": []},+ {+ "component": "ContextMenuItem",+ "storyId": "core-contextmenuitem--states",+ "dims": ["D2"],+ "selectors": {+ "prev": ".astryx-dropdown-menu-item .astryx-icon",+ "next": "[data-testid=\"context-menu-item-end-content\"]"+ }+ },{"component": "DropdownMenu","storyId": "core-dropdownmenu--alignment-end",diff --git a/apps/storybook/stories/ContextMenuItem.stories.tsx b/apps/storybook/stories/ContextMenuItem.stories.tsxnew file mode 100644index 0000000000..368ed94975--- /dev/null+++ b/apps/storybook/stories/ContextMenuItem.stories.tsx@@ -0,0 +1,87 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.++import type {Meta, StoryObj} from '@storybook/react';+import {ContextMenu, ContextMenuItem} from '@astryxdesign/core/ContextMenu';+import {Kbd} from '@astryxdesign/core/Kbd';+import {+ DocumentDuplicateIcon,+ PencilIcon,+ ShareIcon,+ TrashIcon,+} from '@heroicons/react/24/outline';+import * as stylex from '@stylexjs/stylex';++const styles = stylex.create({+ trigger: {+ paddingBlock: 'var(--spacing-8)',+ paddingInline: 'var(--spacing-10)',+ borderWidth: '1px',+ borderStyle: 'dashed',+ borderColor: 'var(--color-border-default)',+ borderRadius: 'var(--radius-element)',+ },+});++const meta: Meta<typeof ContextMenuItem> = {+ title: 'Core/ContextMenuItem',+ component: ContextMenuItem,+ tags: ['autodocs', 'visual-theme-matrix'],+ parameters: {+ layout: 'centered',+ },+};++export default meta;+type Story = StoryObj<typeof meta>;++/** The public alias in its supported ContextMenu compound composition. */+export const States: Story = {+ render: () => (+ <ContextMenu+ data-testid="context-menu-item-audit-trigger"+ label="Document actions"+ menuContent={+ <>+ <ContextMenuItem+ icon={PencilIcon}+ label="Edit"+ description="Modify this document"+ endContent={+ <span data-testid="context-menu-item-end-content">+ <Kbd keys="mod+e" />+ </span>+ }+ onClick={() => {}}+ />+ <ContextMenuItem icon={ShareIcon} label="Share" onClick={() => {}} />+ <ContextMenuItem+ icon={DocumentDuplicateIcon}+ label="Duplicate"+ isDisabled+ onClick={() => {}}+ />+ <ContextMenuItem+ icon={TrashIcon}+ label="Delete"+ variant="destructive"+ onClick={() => {}}+ />+ </>+ }>+ <div {...stylex.props(styles.trigger)}>+ Right-click for document actions+ </div>+ </ContextMenu>+ ),+ play: async ({canvasElement}) => {+ canvasElement+ .querySelector('[data-testid="context-menu-item-audit-trigger"]')+ ?.dispatchEvent(+ new MouseEvent('contextmenu', {+ bubbles: true,+ clientX: 40,+ clientY: 40,+ }),+ );+ },+};