fix(a11y): use figure/figcaption for media block captions#2717
Open
nperez0111 wants to merge 2 commits intomainfrom
Open
fix(a11y): use figure/figcaption for media block captions#2717nperez0111 wants to merge 2 commits intomainfrom
nperez0111 wants to merge 2 commits intomainfrom
Conversation
Closes #2055. Supersedes #2056. When a file/image/video/audio block has a caption, render the wrapper as <figure> with a <figcaption> instead of a <div>+<p>. This matches the WCAG-recommended semantic for caption-content association and removes the need for ad-hoc ARIA fallbacks. Image alt text logic is also tightened: - caption present -> alt="" (the figcaption is the accessible name; this avoids screen readers double-announcing the caption) - no caption, name present -> alt={name} - neither -> alt="" (decorative; aria-hidden was dropped because it would have removed unintentionally-unlabeled images from the accessibility tree entirely) Co-Authored-By: Cyril G <c.gromoff@gmail.com> Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📝 WalkthroughWalkthroughThe PR updates file and image block rendering to use semantic / when a caption and URL exist, and makes image alt text caption-aware (empty when caption present, otherwise uses name), with small CSS to reset figure margins.ChangesFile & Image Accessibility (semantic figures + caption-aware alt text)
Sequence Diagram(s)sequenceDiagram
participant User
participant FileBlock as File Block
participant Wrapper
participant DOM
User->>FileBlock: Add or view file with metadata (url, caption)
FileBlock->>Wrapper: Evaluate url and caption (useFigure)
alt caption exists and url present (useFigure)
Wrapper->>DOM: Render <figure> container
FileBlock->>DOM: Render file preview / loader inside figure
FileBlock->>DOM: Render <figcaption> with caption text
else no caption or missing url
Wrapper->>DOM: Render <div> container
FileBlock->>DOM: Render file preview / loader
FileBlock->>DOM: Optionally render non-figure caption fallback
end
DOM-->>User: Display semantic structure
sequenceDiagram
participant User
participant ImageBlock as Image Block
participant AltLogic as Alt Logic
participant DOM
User->>ImageBlock: Render image (with/without caption)
ImageBlock->>AltLogic: Compute alt (caption-aware)
alt caption exists
AltLogic-->>ImageBlock: alt = ""
ImageBlock->>DOM: Render <img alt=""> inside <figure>
ImageBlock->>DOM: Render <figcaption> visible caption
else no caption
AltLogic-->>ImageBlock: alt = image name or ""
ImageBlock->>DOM: Render <img alt="name"> (or decorative)
end
DOM-->>User: Accessible announcement without duplication
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 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 |
Two CI fixes for #2717: - Block.css: add `margin: 0` to .bn-file-block-content-wrapper so the wrapper looks identical whether it renders as <figure> (captioned) or <div> (uncaptioned). Browser default <figure> margin is `1em 40px`, whereas the previous <div>+<p class="bn-file-caption"> structure had the <p> margins reset by .bn-default-styles. Without this reset the captioned-image visual snapshot grew by ~50px. - server-util/ServerBlockNoteEditor.test.ts.snap: refresh — these snapshots cover the full HTML/markdown round-trip and were missed in the previous snapshot pass. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@blocknote/ariakit
@blocknote/code-block
@blocknote/core
@blocknote/mantine
@blocknote/react
@blocknote/server-util
@blocknote/shadcn
@blocknote/xl-ai
@blocknote/xl-docx-exporter
@blocknote/xl-email-exporter
@blocknote/xl-multi-column
@blocknote/xl-odt-exporter
@blocknote/xl-pdf-exporter
commit: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Render media blocks (image / video / audio / file) with
<figure>+<figcaption>when a caption is set. Closes #2055, supersedes #2056.Changes
createFileBlockWrapper.ts/FileBlockWrapper.tsx: wrapper element is<figure>when a caption is shown,<div>otherwise; caption uses<figcaption>instead of<p>.Image/block.tsand ReactImage/block.tsx— alt text:alt=""(figcaption is the accessible name; avoids double-announcement)alt={name}alt=""(decorative; no extra ARIA)Video/Audiopreviews: removed interimaria-describedby— figure/figcaption now provides the association.Block.css: resetmargin: 0on.bn-file-block-content-wrapperso the figure version matches the previous div layout (figure defaultmargin: 1em 40pxwas not covered by the existing.bn-default-stylesp-reset).Notes
<figure>+<figcaption>viaparseFigureElement(the export path was already producing that structure).Co-authored with @Ovgodd, whose original PR did the alt-text simplification preserved here.
🤖 Generated with Claude Code