Skip to content
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

Fix screen readers not announcing updated aria-describedby in Firefox #51035

Merged
merged 4 commits into from
May 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions packages/block-editor/src/components/list-view/appender.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { store as blockEditorStore } from '../../store';
import useBlockDisplayTitle from '../block-title/use-block-display-title';
import { useListViewContext } from './context';
import Inserter from '../inserter';
import AriaReferencedText from './aria-referenced-text';

export const Appender = forwardRef(
( { nestingLevel, blockCount, clientId, ...props }, ref ) => {
Expand Down Expand Up @@ -90,12 +91,9 @@ export const Appender = forwardRef(
}
} }
/>
<div
className="list-view-appender__description"
id={ descriptionId }
>
<AriaReferencedText id={ descriptionId }>
{ description }
</div>
</AriaReferencedText>
</div>
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* WordPress dependencies
*/
import { useRef, useEffect } from '@wordpress/element';

/**
* A component specifically designed to be used as an element referenced
* by ARIA attributes such as `aria-labelledby` or `aria-describedby`.
*
* @param {Object} props Props.
* @param {import('react').ReactNode} props.children
*/
export default function AriaReferencedText( { children, ...props } ) {
const ref = useRef();

useEffect( () => {
if ( ref.current ) {
// This seems like a no-op, but it fixes a bug in Firefox where
// it fails to recompute the text when only the text node changes.
// @see https://github.com/WordPress/gutenberg/pull/51035
ref.current.textContent = ref.current.textContent;
}
}, [ children ] );

return (
<div hidden { ...props } ref={ ref }>
{ children }
</div>
);
}
8 changes: 3 additions & 5 deletions packages/block-editor/src/components/list-view/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import { store as blockEditorStore } from '../../store';
import useBlockDisplayInformation from '../use-block-display-information';
import { useBlockLock } from '../block-lock';
import { unlock } from '../../lock-unlock';
import AriaReferencedText from './aria-referenced-text';

function ListViewBlock( {
block: { clientId },
Expand Down Expand Up @@ -297,12 +298,9 @@ function ListViewBlock( {
ariaDescribedBy={ descriptionId }
updateFocusAndSelection={ updateFocusAndSelection }
/>
<div
className="block-editor-list-view-block-select-button__description"
id={ descriptionId }
>
<AriaReferencedText id={ descriptionId }>
{ blockPositionDescription }
</div>
</AriaReferencedText>
</div>
) }
</TreeGridCell>
Expand Down
5 changes: 0 additions & 5 deletions packages/block-editor/src/components/list-view/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -340,11 +340,6 @@
}
}

.block-editor-list-view-block-select-button__description,
.block-editor-list-view-appender__description {
display: none;
}

.block-editor-list-view-block__contents-cell,
.block-editor-list-view-appender__cell {
.block-editor-list-view-block__contents-container,
Expand Down