Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Add label for Block Title component to satisfy accessibility #4585

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 14 additions & 2 deletions assets/js/editor-components/block-title/index.js
Expand Up @@ -4,17 +4,29 @@
import PropTypes from 'prop-types';
import { PlainText } from '@wordpress/block-editor';
import classnames from 'classnames';
import { withInstanceId } from '@wordpress/compose';
import { __ } from '@wordpress/i18n';

/**
* Internal dependencies
*/
import './editor.scss';

const BlockTitle = ( { className, headingLevel, onChange, heading } ) => {
const BlockTitle = ( {
className,
headingLevel,
onChange,
heading,
instanceId,
} ) => {
const TagName = `h${ headingLevel }`;
return (
<TagName>
<label className="screen-reader-text" htmlFor={ `block-title-${ instanceId }` }>
{ __( 'Block title', 'woo-gutenberg-products-block' ) }
</label>
<PlainText
id={ `block-title-${ instanceId }` }
className={ classnames(
'wc-block-editor-components-title',
className
Expand Down Expand Up @@ -45,4 +57,4 @@ BlockTitle.propTypes = {
headingLevel: PropTypes.number,
};

export default BlockTitle;
export default withInstanceId( BlockTitle );