-
Notifications
You must be signed in to change notification settings - Fork 408
✨(frontend) fix rgaa 1.9.1: convert to figure/figcaption structure if… #1426
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+69
−6
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ import { | |
imageRender, | ||
imageToExternalHTML, | ||
} from '@blocknote/core'; | ||
import { t } from 'i18next'; | ||
|
||
type ImageBlockConfig = typeof imageBlockConfig; | ||
|
||
|
@@ -25,10 +26,73 @@ export const accessibleImageRender = ( | |
const dom = imageRenderComputed.dom; | ||
const imgSelector = dom.querySelector('img'); | ||
|
||
imgSelector?.setAttribute('alt', ''); | ||
imgSelector?.setAttribute('role', 'presentation'); | ||
imgSelector?.setAttribute('aria-hidden', 'true'); | ||
imgSelector?.setAttribute('tabindex', '-1'); | ||
const withCaption = | ||
block.props.caption && dom.querySelector('.bn-file-caption'); | ||
|
||
const accessibleImageWithCaption = () => { | ||
imgSelector?.setAttribute('alt', block.props.caption); | ||
imgSelector?.removeAttribute('aria-hidden'); | ||
imgSelector?.setAttribute('tabindex', '0'); | ||
|
||
// Fix RGAA 1.9.1: Convert to figure/figcaption structure if caption exists | ||
const captionElement = dom.querySelector('.bn-file-caption'); | ||
|
||
if (captionElement) { | ||
const figureElement = document.createElement('figure'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
// Copy all attributes from the original div | ||
figureElement.className = dom.className; | ||
const styleAttr = dom.getAttribute('style'); | ||
if (styleAttr) { | ||
figureElement.setAttribute('style', styleAttr); | ||
} | ||
figureElement.style.setProperty('margin', '0'); | ||
|
||
Array.from(dom.children).forEach((child) => { | ||
figureElement.appendChild(child.cloneNode(true)); | ||
}); | ||
|
||
// Replace the <p> caption with <figcaption> | ||
const figcaptionElement = document.createElement('figcaption'); | ||
const originalCaption = figureElement.querySelector('.bn-file-caption'); | ||
if (originalCaption) { | ||
figcaptionElement.className = originalCaption.className; | ||
figcaptionElement.textContent = originalCaption.textContent; | ||
originalCaption.parentNode?.replaceChild( | ||
figcaptionElement, | ||
originalCaption, | ||
); | ||
|
||
// Add explicit role and aria-label for better screen reader support | ||
figureElement.setAttribute('role', 'img'); | ||
figureElement.setAttribute( | ||
'aria-label', | ||
t(`Image: {{title}}`, { title: figcaptionElement.textContent }), | ||
); | ||
} | ||
|
||
// Return the figure element as the new dom | ||
return { | ||
...imageRenderComputed, | ||
dom: figureElement, | ||
}; | ||
} | ||
}; | ||
|
||
const accessibleImage = () => { | ||
imgSelector?.setAttribute('alt', ''); | ||
imgSelector?.setAttribute('role', 'presentation'); | ||
imgSelector?.setAttribute('aria-hidden', 'true'); | ||
imgSelector?.setAttribute('tabindex', '-1'); | ||
}; | ||
|
||
// Set accessibility attributes for the image | ||
const result = withCaption ? accessibleImageWithCaption() : accessibleImage(); | ||
|
||
// Return the result if accessibleImageWithCaption created a figure, otherwise return original | ||
if (result) { | ||
return result; | ||
} | ||
|
||
return { | ||
...imageRenderComputed, | ||
|
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can add all this part in this function as well:
docs/src/frontend/apps/impress/src/features/docs/doc-editor/components/custom-blocks/AccessibleImageBlock.tsx
Lines 49 to 92 in 0ab6394
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indeed