Repository navigation
fix(docs) Improve a11y for Admonitions with file refactor - #48112
Conversation
|
This pull request has been ignored for the connected project Preview Branches by Supabase. |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughThe PR moves Admonition into a dedicated module with typed contracts, label and variant mappings, reusable icons, rendering tests, package export subpaths, and updated consumers using corrected casing. ChangesAdmonition component
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant Consumer
participant Admonition
participant AdmonitionTypeIcon
participant Alert
Consumer->>Admonition: Pass type, content, layout, and actions
Admonition->>AdmonitionTypeIcon: Resolve optional type icon
Admonition->>Alert: Render variant, accessibility attributes, and content
Alert-->>Consumer: Render admonition UI
Suggested labels: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
| @@ -0,0 +1,126 @@ | |||
| import { render, screen, within } from '@testing-library/react' | |||
There was a problem hiding this comment.
This test had been renamed and migrated, but Github does not seem to detect that it has moved.
| @@ -0,0 +1,208 @@ | |||
| import { cva } from 'class-variance-authority' | |||
There was a problem hiding this comment.
This was also renamed and migrated into an Admonition folder.
| children: ReactNode | ||
| } | ||
|
|
||
| function AdmonitionIcon({ className, viewBox, children, ...props }: AdmonitionIconBaseProps) { |
| @@ -0,0 +1,54 @@ | |||
| import type { ReactNode, SVGProps } from 'react' | |||
There was a problem hiding this comment.
Icons are pulled out from the component to reduce file size and improve readability.
| ) | ||
| } | ||
| ) | ||
| export * from './Admonition' |
There was a problem hiding this comment.
Does not break exports.
| ) => { | ||
| const typeMapped = variant ? admonitionToAlertMapping[variant] : admonitionToAlertMapping[type] | ||
| const typeStyle = type === 'success' ? 'success' : typeMapped | ||
| const typeLabel = admonitionTypeLabel[type] |
|
This is still in draft. I want to adjust the tailwind styles before I'm ready for design review. |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
packages/ui-patterns/src/Admonition/Admonition.tsx (1)
31-31: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winConsider including
titleinaria-labelwhen present.Currently
aria-labelis always just the generic type label (e.g. "Note"), even when a specifictitleis supplied. Multiple admonitions of the same type on a page will all share an identical, non-descriptive accessible name for screen-reader landmark navigation.♻️ Proposed refactor
- const label = TYPE_LABEL[type] + const label = TYPE_LABEL[type] + const accessibleName = title ? `${label}: ${title}` : label- aria-label={label} + aria-label={accessibleName}Also applies to: 37-38
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/ui-patterns/src/Admonition/Admonition.tsx` at line 31, Update the aria-label construction in Admonition to include the supplied title alongside the generic TYPE_LABEL[type] value when title is present, while retaining the current type label for untitled admonitions. Apply the change to the related accessibility attributes around the referenced lines without altering other admonition behavior.packages/ui-patterns/src/Admonition/Admonition.test.tsx (1)
98-98: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winBrittle SVG path assertion.
Hardcoding the exact
dpath data couples this test to icon implementation details; any icon glyph update (even a purely cosmetic one) will break this test.♻️ Proposed refactor
- expect(note.querySelector('svg path')?.getAttribute('d')).toContain('M10.5 19.5') + expect(note.querySelector('svg')).toBeInTheDocument()🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/ui-patterns/src/Admonition/Admonition.test.tsx` at line 98, Replace the exact SVG path-data assertion in the Admonition test with an assertion on the stable, user-facing icon behavior or identifying attributes. Keep verifying that the note renders the expected icon, but avoid depending on the path element’s specific d value or glyph geometry.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/ui-patterns/src/Admonition/Admonition.tsx`:
- Around line 10-14: Update the Admonition prop typing and rendering so
consumer-supplied variant is not accepted and silently overridden. Include the
Alert variant key in the omitted props used by the forwardRef generic, and
ensure the Alert invocation around the explicit variant={TYPE_TO_VARIANT[type]}
remains the sole source of the variant value.
---
Nitpick comments:
In `@packages/ui-patterns/src/Admonition/Admonition.test.tsx`:
- Line 98: Replace the exact SVG path-data assertion in the Admonition test with
an assertion on the stable, user-facing icon behavior or identifying attributes.
Keep verifying that the note renders the expected icon, but avoid depending on
the path element’s specific d value or glyph geometry.
In `@packages/ui-patterns/src/Admonition/Admonition.tsx`:
- Line 31: Update the aria-label construction in Admonition to include the
supplied title alongside the generic TYPE_LABEL[type] value when title is
present, while retaining the current type label for untitled admonitions. Apply
the change to the related accessibility attributes around the referenced lines
without altering other admonition behavior.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 2fa237d2-f782-41f1-86c5-646daa07b3c3
📒 Files selected for processing (14)
packages/ui-patterns/package.jsonpackages/ui-patterns/src/Admonition/Admonition.constants.tspackages/ui-patterns/src/Admonition/Admonition.test.tsxpackages/ui-patterns/src/Admonition/Admonition.tsxpackages/ui-patterns/src/Admonition/Admonition.types.tspackages/ui-patterns/src/Admonition/AdmonitionIcons.tsxpackages/ui-patterns/src/Admonition/index.tsxpackages/ui-patterns/src/Dialogs/ConfirmationModal.tsxpackages/ui-patterns/src/Dialogs/TextConfirmModal.tsxpackages/ui-patterns/src/ErrorDisplay/ErrorDisplay.tsxpackages/ui-patterns/src/PrivacySettings/index.tsxpackages/ui-patterns/src/SqlToRest/index.tsxpackages/ui-patterns/src/admonition.test.tsxpackages/ui-patterns/src/admonition.tsx
💤 Files with no reviewable changes (1)
- packages/ui-patterns/src/admonition.test.tsx
There was a problem hiding this comment.
🧹 Nitpick comments (2)
packages/ui-patterns/src/Admonition/Admonition.test.tsx (2)
62-62: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winPrefer semantic role queries over DOM selectors.
Using
querySelectoris discouraged in React Testing Library, particularly in tests designed to verify accessibility. UsequeryByRole('heading')to semantically assert that no headings are rendered.
packages/ui-patterns/src/Admonition/Admonition.test.tsx#L62-L62: replace the DOM selector withexpect(within(note).queryByRole('heading')).not.toBeInTheDocument()packages/ui-patterns/src/Admonition/Admonition.test.tsx#L76-L76: replace the DOM selector withexpect(within(note).queryByRole('heading')).not.toBeInTheDocument()🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/ui-patterns/src/Admonition/Admonition.test.tsx` at line 62, Replace the DOM querySelector heading checks in packages/ui-patterns/src/Admonition/Admonition.test.tsx at lines 62-62 and 76-76 with within(note).queryByRole('heading') assertions, preserving the expectation that no heading is rendered.
119-120: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueExtract the element query into a variable.
To avoid querying the DOM multiple times and to maintain consistency with the other tests in this file, extract
screen.getByRole('note')into anotevariable. This also ensures both assertions use the same{ name }scoped filter.♻️ Proposed refactor
- expect(screen.getByRole('note', { name })).toBeVisible() - expect(within(screen.getByRole('note')).queryByText(`${name}:`)).not.toBeInTheDocument() + const note = screen.getByRole('note', { name }) + expect(note).toBeVisible() + expect(within(note).queryByText(`${name}:`)).not.toBeInTheDocument()🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/ui-patterns/src/Admonition/Admonition.test.tsx` around lines 119 - 120, In the test containing the two note assertions, extract the named `screen.getByRole('note', { name })` result into a `note` variable, then use that variable for both visibility and `within` assertions so the same filtered element is queried once.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@packages/ui-patterns/src/Admonition/Admonition.test.tsx`:
- Line 62: Replace the DOM querySelector heading checks in
packages/ui-patterns/src/Admonition/Admonition.test.tsx at lines 62-62 and 76-76
with within(note).queryByRole('heading') assertions, preserving the expectation
that no heading is rendered.
- Around line 119-120: In the test containing the two note assertions, extract
the named `screen.getByRole('note', { name })` result into a `note` variable,
then use that variable for both visibility and `within` assertions so the same
filtered element is queried once.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: bf28bc83-f213-45ef-b3ae-41e8548b2ebb
📒 Files selected for processing (2)
packages/ui-patterns/src/Admonition/Admonition.test.tsxpackages/ui-patterns/src/Admonition/Admonition.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
- packages/ui-patterns/src/Admonition/Admonition.tsx
| )} | ||
| > | ||
| {title && ( | ||
| <div |
There was a problem hiding this comment.
If this is text/heading it shouldn't be a div, right?
There was a problem hiding this comment.
Agree. Maybe <p> with <strong> since <h5> was dropped on purpose?
There was a problem hiding this comment.
Yes. H5 breaks the heading hierarchy if the header above is not h4. Possibly, there can be a prop for the header so the heading-level is defined correctly.
| {description} | ||
| {children} |
There was a problem hiding this comment.
What about AlertDescription? That auto-wrapped strings in <p>. I believe just the raw text node is shown now.
There was a problem hiding this comment.
I mean just for description, not children.
AlertTitle and AlertDescription also had built-in text styles. I wonder if we should have just amended those instead of pulling them out. What do you think of that?
There was a problem hiding this comment.
Makes sense. Sounds cleaner. 😄
dnywh
left a comment
There was a problem hiding this comment.
One proper ask around role. Some other minor comments!
b50d726 to
a91e6a2
Compare
Move Admonition into its own folder, split icons out, and label admonitions for screen readers: group the region with an aria-label, hide decorative icons, and keep the underlying role=alert semantics. Co-Authored-By: Claude Sonnet 5 <[email protected]>
Restricted to h2-h5 since an admonition title is never a page's top-level heading and h6 has no practical use in this context. Co-Authored-By: Claude Sonnet 5 <[email protected]>
Co-Authored-By: Claude Sonnet 5 <[email protected]>
474ae2a to
542a8e6
Compare
variant is always derived from type via TYPE_TO_VARIANT and silently overridden at runtime, so allowing it through the prop types was a footgun with no compile or runtime signal. Co-Authored-By: Claude Sonnet 5 <[email protected]>
|
@dnywh Feedback is applied and I've used Claude to clean up the commit history:
|
variant was always silently overridden by TYPE_TO_VARIANT[type], so these were rendering with the default note styling instead of the intended warning styling. Now caught at compile time by the stricter Admonition prop types. Co-Authored-By: Claude Sonnet 5 <[email protected]>
🎭 Playwright Test Results (tanstack)Details
Skipped testsFeatures › auth-users.spec.ts › should show web3 users as enabled when the matching web3 provider is enabled |
| type = 'note', | ||
| showIcon = true, | ||
| title, | ||
| headingLevel, |
There was a problem hiding this comment.
I can’t foresee using the headingLevel prop FWIW. Can you?
| {description && ( | ||
| <AlertDescription | ||
| {...childProps.description} | ||
| className={cn( | ||
| admonitionBodyClassName, | ||
| !heading && 'my-0.5', | ||
| childProps.description?.className | ||
| )} | ||
| > | ||
| {description} | ||
| </AlertDescription> |
There was a problem hiding this comment.
This PR still has one minor regression against prod: any text that is passed in the description prop is now a raw text node instead of <p>. Should we re-include this selected logic?
TLDR: put description in <AlertDescription> again?
description wrapped in AlertDescription Remove heading override option
The title is a <p>, so the MDX body [&_p]:!mb-1.5 rules were overriding its mb-0.5 and adding ~4px under the title.
… admonition Prefer beating [&_p]:!mb-1.5 with !mb-0.5 on the title over splitting the DOM.
!mb-0.5 on the title loses to parent [&_p]:!mb-1.5 (class+element beats class). Mark the title and narrow the reset selector instead.
Braintrust eval report
|
Closes FE-3914
I have read the CONTRIBUTING.md file.
YES
Problem
On screenreader, I found that the Admonition was not behaving as it should:
h5, breaking header hierarchy structures.Solution
This PR does several things to resolve the issue:
aria-hiddento all icons. Instead of duplicating code, I refactored the icons into a Base Icon and moved Admonitions into its own folder.Adds a text label for each of the notes. For example, "Note:". This is a standard practice in other documentation. If there is a title, it is added there. Otherwise, it's added to the description.Change reverted from design feedback.AddsThis will be done in a follow-up for docs only.role='note'andaria-labelto the Admonition. While<aside>is recommended semantic HTML, the base UI element does not allow for that change.h5by default with a new prop to declare a headerAdditionally adjusts the icon so that it aligns with text better.
Testing
Summary by CodeRabbit
Summary by CodeRabbit
type,layout,title/description, optional actions, and configurable icons.type="warning"instead ofvariant="warning".