Skip to content

A11y: improve interactions panel semantics, labels, and run announcements#34109

Closed
anchmelev wants to merge 2 commits into
storybookjs:nextfrom
anchmelev:next
Closed

A11y: improve interactions panel semantics, labels, and run announcements#34109
anchmelev wants to merge 2 commits into
storybookjs:nextfrom
anchmelev:next

Conversation

@anchmelev
Copy link
Copy Markdown
Contributor

@anchmelev anchmelev commented Mar 12, 2026

Closes #31701

What I did

  • Updated the Interactions panel steps container to semantic list markup (ol + li) instead of non-semantic wrappers.
  • Replaced the previous non-semantic top-level labeling with a labeled section and heading (Interaction steps).
  • Improved interaction step button labels so they describe the action and include step status context.
  • Improved nested-step toggle accessibility by adding explicit expand/collapse labels and aria-expanded.
  • Updated nested-step toggle icon behavior to disclosure-style directionality (right when collapsed, down when expanded).
  • Added aria-busy to the interactions list while tests are rendering/running.
  • Added a screen-reader live status region to announce test lifecycle outcomes.
  • Added unit tests for semantics, labeling, and live/busy behavior:
    • code/core/src/component-testing/components/InteractionsPanel.test.tsx

Checklist for Contributors

Testing

The changes in this PR are covered in the following automated tests:

  • stories
  • unit tests
  • integration tests
  • end-to-end tests

Manual testing

  1. Run Storybook UI locally:
    • cd code && yarn task compile && yarn storybook:ui
  2. Open:
    • http://localhost:6006/?path=/story/core-component-test-basics--step
  3. Open the Interactions panel and run the play function.
  4. Verify accessibility behavior:
    • Steps are exposed as a semantic list (ol/li).
    • Step controls have actionable labels (including status context).
    • Nested-step toggle has explicit expand/collapse label and updates expanded state.
    • While running, the interactions list is marked busy.
    • Completion/failure states are announced via live region.

Documentation

  • Add or update documentation reflecting your changes
  • If you are deprecating/removing a feature, make sure to update
    MIGRATION.MD

Checklist for Maintainers

  • When this PR is ready for testing, make sure to add ci:normal, ci:merged or ci:daily GH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found in code/lib/cli-storybook/src/sandbox-templates.ts

  • Make sure this PR contains one of the labels below:

    Available labels
    • bug: Internal changes that fixes incorrect behavior.
    • maintenance: User-facing maintenance tasks.
    • dependencies: Upgrading (sometimes downgrading) dependencies.
    • build: Internal-facing build tooling & test updates. Will not show up in release changelog.
    • cleanup: Minor cleanup style change. Will not show up in release changelog.
    • documentation: Documentation only changes. Will not show up in release changelog.
    • feature request: Introducing a new feature.
    • BREAKING CHANGE: Changes that break compatibility in some way with current major version.
    • other: Changes that don't fit in the above categories.

🦋 Canary release

This PR does not have a canary release associated. You can request a canary release of this pull request by mentioning the @storybookjs/core team here.

core team members can create a canary release here or locally with gh workflow run --repo storybookjs/storybook publish.yml --field pr=<PR_NUMBER>

Summary by CodeRabbit

  • New Features

    • Accessible, semantically structured interactions list with a visible heading and live status announcements during test runs.
    • Improved interaction labels, status messaging, and Expand/Collapse behavior with updated chevrons and aria-expanded support.
    • Error alerts surfaced more clearly for failed interaction runs.
  • Tests

    • Added comprehensive tests for the interactions panel covering rendering, accessibility labels/states, live announcements, and error transitions.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 12, 2026

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

Refactors Interaction and InteractionsPanel for semantic HTML and accessibility: introduces helpers for interaction labels/status, changes Interaction row to a list item with updated ARIA and chevron behavior, adds an id prop, live-region status announcements, aria-busy handling, and a new test suite covering rendering and accessibility states.

Changes

Cohort / File(s) Summary
Interaction component
code/core/src/component-testing/components/Interaction.tsx
Replaced row container with li, renamed RowHeader prop isInteractiveisNavigationDisabled, added helpers (stepStatusTextMap, getInteractionLabel, getInteractionStatusText), updated aria labels/expanded behavior, and toggled chevron icons (ChevronRight when collapsed, ChevronDown when expanded).
InteractionsPanel component
code/core/src/component-testing/components/InteractionsPanel.tsx
Added optional id prop, introduced semantic sections (InteractionsSection, InteractionsHeading, InteractionsList) and LiveStatus live region, computed headingId and isListBusy, mapped play statuses to announcements, applied aria-busy/aria-labelledby, preserved exception flow and endRef placement.
Tests
code/core/src/component-testing/components/InteractionsPanel.test.tsx
New Vitest + RTL test suite: verifies ordered list rendering, actionable labels, nested-toggle aria-expanded behavior, live status announcements, aria-busy during running, and transition to failure alerts.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
code/core/src/component-testing/components/InteractionsPanel.test.tsx (1)

48-106: Consider adding a test for the collapsed toggle state.

The test suite covers aria-expanded="true" (when isCollapsed: false), but doesn't verify aria-expanded="false" when collapsed. This would ensure the toggle correctly reflects both states.

💡 Optional test addition
it('labels nested-step toggle with collapsed state', () => {
  const interactions = getInteractions(CallStates.DONE).map((interaction) =>
    interaction.method === 'step'
      ? { ...interaction, childCallIds: ['child-call-id'], isCollapsed: true }
      : interaction
  );

  renderPanel(createProps({ interactions }));

  const toggle = screen.getByRole('button', {
    name: 'Expand nested interaction steps for Click button',
  });

  expect(toggle).toHaveAttribute('aria-expanded', 'false');
});
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@code/core/src/component-testing/components/InteractionsPanel.test.tsx` around
lines 48 - 106, Add a complementary test to cover the collapsed toggle state:
create interactions using getInteractions(CallStates.DONE) and for the
interaction with method === 'step' set childCallIds: ['child-call-id'] and
isCollapsed: true, then renderPanel(createProps({ interactions })), find the
toggle button by its accessible name "Expand nested interaction steps for Click
button" and assert toggle has attribute aria-expanded="false"; place this
alongside the existing "labels nested-step toggle buttons with action and
expanded state" test to ensure both expanded and collapsed states of the toggle
(referencing renderPanel, createProps, getInteractions, CallStates, and the
toggle button assertion).
code/core/src/component-testing/components/InteractionsPanel.tsx (1)

145-156: Consider extracting status announcements to a mapping object.

The nested ternary handles all cases correctly, but a mapping object (similar to StatusTextMapping in StatusBadge.tsx) could improve readability and maintainability.

♻️ Optional refactor
+const statusAnnouncementMap: Record<PlayStatus, string> = {
+  rendering: 'Component test is rendering.',
+  playing: 'Component test is running.',
+  errored: 'Component test failed.',
+  aborted: 'Component test was aborted.',
+  completed: 'Component test completed successfully.',
+};

 // In component:
-const statusAnnouncement =
-  status === 'rendering'
-    ? 'Component test is rendering.'
-    : status === 'playing'
-      ? 'Component test is running.'
-      : status === 'errored'
-        ? 'Component test failed.'
-        : status === 'aborted'
-          ? 'Component test was aborted.'
-          : hasException
-            ? 'Component test completed with errors.'
-            : 'Component test completed successfully.';
+const statusAnnouncement =
+  status === 'completed' && hasException
+    ? 'Component test completed with errors.'
+    : statusAnnouncementMap[status];
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@code/core/src/component-testing/components/InteractionsPanel.tsx` around
lines 145 - 156, Replace the nested ternary that produces statusAnnouncement
with a lookup from a mapping object (e.g., create a const
StatusAnnouncementMapping similar to StatusTextMapping in StatusBadge.tsx) keyed
by the status values ('rendering','playing','errored','aborted') and then
compute statusAnnouncement by checking StatusAnnouncementMapping[status] with a
fallback that uses hasException to choose between the error and success
messages; update the InteractionsPanel.tsx references to use this mapping so the
logic is clearer and easier to maintain.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@code/core/src/component-testing/components/InteractionsPanel.tsx`:
- Line 143: The component currently calls React.useId() (headingId) which breaks
in React 17; update InteractionsPanel to accept an optional id prop (e.g., id?:
string on the component props) and replace the React.useId() call with a value
that prefers the caller-provided id and falls back to a client-only generated id
(useRef + useEffect or a lazy random/id generator) so server/React17 rendering
is safe; change references of headingId to use this resolvedId and ensure prop
typing and defaulting are updated accordingly.

---

Nitpick comments:
In `@code/core/src/component-testing/components/InteractionsPanel.test.tsx`:
- Around line 48-106: Add a complementary test to cover the collapsed toggle
state: create interactions using getInteractions(CallStates.DONE) and for the
interaction with method === 'step' set childCallIds: ['child-call-id'] and
isCollapsed: true, then renderPanel(createProps({ interactions })), find the
toggle button by its accessible name "Expand nested interaction steps for Click
button" and assert toggle has attribute aria-expanded="false"; place this
alongside the existing "labels nested-step toggle buttons with action and
expanded state" test to ensure both expanded and collapsed states of the toggle
(referencing renderPanel, createProps, getInteractions, CallStates, and the
toggle button assertion).

In `@code/core/src/component-testing/components/InteractionsPanel.tsx`:
- Around line 145-156: Replace the nested ternary that produces
statusAnnouncement with a lookup from a mapping object (e.g., create a const
StatusAnnouncementMapping similar to StatusTextMapping in StatusBadge.tsx) keyed
by the status values ('rendering','playing','errored','aborted') and then
compute statusAnnouncement by checking StatusAnnouncementMapping[status] with a
fallback that uses hasException to choose between the error and success
messages; update the InteractionsPanel.tsx references to use this mapping so the
logic is clearer and easier to maintain.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 7af7b841-f82a-49fe-a704-94be864ee971

📥 Commits

Reviewing files that changed from the base of the PR and between 1ba2d07 and c4ed70a.

📒 Files selected for processing (3)
  • code/core/src/component-testing/components/Interaction.tsx
  • code/core/src/component-testing/components/InteractionsPanel.test.tsx
  • code/core/src/component-testing/components/InteractionsPanel.tsx

Comment thread code/core/src/component-testing/components/InteractionsPanel.tsx Outdated
@nx-cloud
Copy link
Copy Markdown

nx-cloud Bot commented Mar 12, 2026

View your CI Pipeline Execution ↗ for commit c4ed70a

Command Status Duration Result
nx run-many -t compile -c production --parallel=1 ✅ Succeeded 6m 14s View ↗

☁️ Nx Cloud last updated this comment at 2026-03-12 02:31:39 UTC

@anchmelev anchmelev closed this Mar 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Interaction steps list is not accessible

1 participant