Skip to content

Commit

Permalink
Fix screen readers not announcing updated aria-describedby in Firef…
Browse files Browse the repository at this point in the history
…ox (#51035)

* Fix aria-describedby not updating content

* Try aria-description.

* Try a different approach

* Fix missing prop

---------

Co-authored-by: Alex Stine <alex.stine@yourtechadvisors.com>
  • Loading branch information
kevin940726 and alexstine authored May 30, 2023
1 parent e318682 commit a9e19c0
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 15 deletions.
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

0 comments on commit a9e19c0

Please sign in to comment.