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

Comments form: Accessibility fixes for back-end #54393

Merged
merged 3 commits into from
Sep 13, 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
10 changes: 10 additions & 0 deletions packages/block-library/src/post-comments-form/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import {
BlockControls,
useBlockProps,
} from '@wordpress/block-editor';
import { VisuallyHidden } from '@wordpress/components';
import { useInstanceId } from '@wordpress/compose';
import { __, sprintf } from '@wordpress/i18n';

/**
* Internal dependencies
Expand All @@ -25,10 +28,14 @@ export default function PostCommentsFormEdit( {
const { textAlign } = attributes;
const { postId, postType } = context;

const instanceId = useInstanceId( PostCommentsFormEdit );
const instanceIdDesc = sprintf( 'comments-form-edit-%d-desc', instanceId );

const blockProps = useBlockProps( {
className: classnames( {
[ `has-text-align-${ textAlign }` ]: textAlign,
} ),
'aria-describedby': instanceIdDesc,
} );

return (
Expand All @@ -43,6 +50,9 @@ export default function PostCommentsFormEdit( {
</BlockControls>
<div { ...blockProps }>
<CommentsForm postId={ postId } postType={ postType } />
<VisuallyHidden id={ instanceIdDesc }>
{ __( 'Comments form disabled in editor.' ) }
</VisuallyHidden>
</div>
</>
);
Expand Down
8 changes: 7 additions & 1 deletion packages/block-library/src/post-comments-form/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ const CommentsFormPlaceholder = () => {
return (
<div className="comment-respond">
<h3 className="comment-reply-title">{ __( 'Leave a Reply' ) }</h3>
<form noValidate className="comment-form" inert="true">
<form
noValidate
className="comment-form"
onSubmit={ ( event ) => event.preventDefault() }
>
<p>
<label htmlFor={ `comment-${ instanceId }` }>
{ __( 'Comment' ) }
Expand All @@ -33,6 +37,7 @@ const CommentsFormPlaceholder = () => {
name="comment"
cols="45"
rows="8"
readOnly
/>
</p>
<p className="form-submit wp-block-button">
Expand All @@ -45,6 +50,7 @@ const CommentsFormPlaceholder = () => {
) }
label={ __( 'Post Comment' ) }
value={ __( 'Post Comment' ) }
aria-disabled="true"
jeryj marked this conversation as resolved.
Show resolved Hide resolved
/>
</p>
</form>
Expand Down
Loading