Skip to content

Commit

Permalink
Rich Text: Add aria-readonly attribute to Rich Text component (WordPr…
Browse files Browse the repository at this point in the history
…ess#58687)

* Add aria-readonly attribute to Rich Text component

* Add check to ensure only supported blocks are disabled

Co-authored-by: artemiomorales <[email protected]>
Co-authored-by: SantosGuillamot <[email protected]>
Co-authored-by: afercia <[email protected]>
  • Loading branch information
4 people authored Feb 8, 2024
1 parent cd7ec2f commit 265a57f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion packages/block-editor/src/components/rich-text/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import { getAllowedFormats } from './utils';
import { Content } from './content';
import { withDeprecations } from './with-deprecations';
import { unlock } from '../../lock-unlock';
import { BLOCK_BINDINGS_ALLOWED_BLOCKS } from '../../hooks/use-bindings-attributes';

export const keyboardShortcutContext = createContext();
export const inputEventContext = createContext();
Expand Down Expand Up @@ -147,7 +148,7 @@ export function RichTextWrapper(

// Disable Rich Text editing if block bindings specify that.
let shouldDisableEditing = false;
if ( blockBindings ) {
if ( blockBindings && blockName in BLOCK_BINDINGS_ALLOWED_BLOCKS ) {
const blockTypeAttributes = getBlockType( blockName ).attributes;
const { getBlockBindingsSource } = unlock(
select( blockEditorStore )
Expand Down Expand Up @@ -355,6 +356,7 @@ export function RichTextWrapper(
role="textbox"
aria-multiline={ ! disableLineBreaks }
aria-label={ placeholder }
aria-readonly={ shouldDisableEditing }
{ ...props }
{ ...autocompleteProps }
ref={ useMergeRefs( [
Expand Down
2 changes: 1 addition & 1 deletion packages/block-editor/src/hooks/use-bindings-attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { unlock } from '../lock-unlock';
* @return {WPHigherOrderComponent} Higher-order component.
*/

const BLOCK_BINDINGS_ALLOWED_BLOCKS = {
export const BLOCK_BINDINGS_ALLOWED_BLOCKS = {
'core/paragraph': [ 'content' ],
'core/heading': [ 'content' ],
'core/image': [ 'url', 'title', 'alt' ],
Expand Down

0 comments on commit 265a57f

Please sign in to comment.