Skip to content

Commit

Permalink
Give editable fields in blocks better aria-labels.
Browse files Browse the repository at this point in the history
  • Loading branch information
ZebulanStanphill committed Nov 18, 2020
1 parent b7174b3 commit 8e76797
Show file tree
Hide file tree
Showing 22 changed files with 38 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/block-library/src/audio/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ function AudioEdit( {
{ ( ! RichText.isEmpty( caption ) || isSelected ) && (
<RichText
tagName="figcaption"
aria-label={ __( 'Audio caption text' ) }
placeholder={ __( 'Write caption…' ) }
value={ caption }
onChange={ ( value ) =>
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/button/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ function ButtonEdit( props ) {
} ) }
>
<RichText
aria-label={ __( 'Button text' ) }
placeholder={ placeholder || __( 'Add text…' ) }
value={ text }
onChange={ ( value ) => setAttributes( { text: value } ) }
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/file/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ function FileEdit( { attributes, setAttributes, noticeUI, noticeOperations } ) {
{ /* Using RichText here instead of PlainText so that it can be styled like a button */ }
<RichText
tagName="div" // must be block-level or else cursor disappears
aria-label={ __( 'Download button text' ) }
className={ 'wp-block-file__button' }
value={ downloadButtonText }
withoutInteractiveFormatting
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/gallery/gallery-image.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ class GalleryImage extends Component {
{ ! isEditing && ( isSelected || caption ) && (
<RichText
tagName="figcaption"
aria-label={ __( 'Image caption text' ) }
placeholder={
isSelected ? __( 'Write caption…' ) : null
}
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/gallery/gallery.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export const Gallery = ( props ) => {
isHidden={ ! isSelected && RichText.isEmpty( caption ) }
tagName="figcaption"
className="blocks-gallery-caption"
aria-label={ __( 'Gallery caption text' ) }
placeholder={ __( 'Write gallery caption…' ) }
value={ caption }
unstableOnFocus={ onFocusGalleryCaption }
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/heading/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ function HeadingEdit( {
} }
onReplace={ onReplace }
onRemove={ () => onReplace( [] ) }
aria-label={ __( 'Heading text' ) }
placeholder={ placeholder || __( 'Write heading…' ) }
textAlign={ textAlign }
{ ...blockProps }
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/image/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,7 @@ export default function Image( {
<RichText
ref={ captionRef }
tagName="figcaption"
aria-label={ __( 'Image caption text' ) }
placeholder={ __( 'Write caption…' ) }
value={ caption }
unstableOnFocus={ onFocusCaption }
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/list/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ export default function ListEdit( {
setAttributes( { values: nextValues } )
}
value={ values }
aria-label={ __( 'List text' ) }
placeholder={ __( 'Write list…' ) }
onMerge={ mergeBlocks }
onSplit={ ( value ) =>
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/navigation-link/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ function NavigationLinkEdit( {
createBlock( 'core/navigation-link' )
)
}
aria-label={ __( 'Navigation link text' ) }
placeholder={ itemLabelPlaceholder }
keepPlaceholderOnFocus
withoutInteractiveFormatting
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/post-author/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ function PostAuthorEdit( { isSelected, context, attributes, setAttributes } ) {
<RichText
className="wp-block-post-author__byline"
multiline={ false }
aria-label={ __( 'Post author byline text' ) }
placeholder={ __( 'Write byline …' ) }
value={ byline }
onChange={ ( value ) =>
Expand Down
3 changes: 3 additions & 0 deletions packages/block-library/src/post-excerpt/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ function PostExcerptEditor( {
! showMoreOnNewLine &&
'wp-block-post-excerpt__excerpt is-inline'
}
aria-label={ __( 'Post excerpt text' ) }
value={
excerpt ||
postContentExcerpt ||
Expand All @@ -115,6 +116,7 @@ function PostExcerptEditor( {
<p className="wp-block-post-excerpt__more-text">
<RichText
tagName="a"
aria-label={ __( 'Read more link text' ) }
placeholder={ __( 'Read more…' ) }
value={ moreText }
onChange={ ( newMoreText ) =>
Expand All @@ -125,6 +127,7 @@ function PostExcerptEditor( {
) : (
<RichText
tagName="a"
aria-label={ __( 'Read more link text' ) }
placeholder={ __( 'Read more…' ) }
value={ moreText }
onChange={ ( newMoreText ) =>
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/preformatted/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export default function PreformattedEdit( {
} );
} }
onRemove={ onRemove }
aria-label={ __( 'Preformatted text' ) }
placeholder={ __( 'Write preformatted text…' ) }
onMerge={ mergeBlocks }
{ ...blockProps }
Expand Down
2 changes: 2 additions & 0 deletions packages/block-library/src/pullquote/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ function PullQuoteEdit( {
value: nextValue,
} )
}
aria-label={ __( 'Pullquote text' ) }
placeholder={
// translators: placeholder text used for the quote
__( 'Write quote…' )
Expand All @@ -134,6 +135,7 @@ function PullQuoteEdit( {
<RichText
identifier="citation"
value={ citation }
aria-label={ __( 'Pullquote citation text' ) }
placeholder={
// translators: placeholder text used for the citation
__( 'Write citation…' )
Expand Down
2 changes: 2 additions & 0 deletions packages/block-library/src/quote/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export default function QuoteEdit( {
onReplace( [] );
}
} }
aria-label={ __( 'Quote text' ) }
placeholder={
// translators: placeholder text used for the quote
__( 'Write quote…' )
Expand All @@ -86,6 +87,7 @@ export default function QuoteEdit( {
} )
}
__unstableMobileNoFocusOnMount
aria-label={ __( 'Quote citation text' ) }
placeholder={
// translators: placeholder text used for the citation
__( 'Write citation…' )
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/shortcode/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export default function ShortcodeEdit( { attributes, setAttributes } ) {
className="blocks-shortcode__textarea"
id={ inputId }
value={ attributes.text }
aria-label={ __( 'Shortcode text' ) }
placeholder={ __( 'Write shortcode here…' ) }
onChange={ ( text ) => setAttributes( { text } ) }
/>
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/site-tagline/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export default function SiteTaglineEdit( { attributes, setAttributes } ) {
<RichText
allowedFormats={ [] }
onChange={ setSiteTagline }
aria-label={ __( 'Site tagline text' ) }
placeholder={ __( 'Site Tagline' ) }
tagName="p"
value={ siteTagline }
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/site-title/edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export default function SiteTitleEdit( { attributes, setAttributes } ) {

<RichText
tagName={ tagName }
aria-label={ __( 'Site title text' ) }
placeholder={ __( 'Site Title' ) }
value={ title }
onChange={ setTitle }
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/subhead/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export default function SubheadEdit( {
} }
style={ { textAlign: align } }
className={ className }
aria-label={ __( 'Subheading text' ) }
placeholder={ placeholder || __( 'Write subheading…' ) }
/>
</div>
Expand Down
8 changes: 8 additions & 0 deletions packages/block-library/src/table/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ const ALIGNMENT_CONTROLS = [

const withCustomBackgroundColors = createCustomColorsHOC( BACKGROUND_COLORS );

const cellAriaLabel = {
head: __( 'Header cell text' ),
body: __( 'Body cell text' ),
foot: __( 'Footer cell text' ),
};

const placeholder = {
head: __( 'Header label' ),
foot: __( 'Footer label' ),
Expand Down Expand Up @@ -432,6 +438,7 @@ function TableEdit( {
type: 'cell',
} );
} }
aria-label={ cellAriaLabel[ name ] }
placeholder={ placeholder[ name ] }
/>
)
Expand Down Expand Up @@ -520,6 +527,7 @@ function TableEdit( {
{ ! isEmpty && (
<RichText
tagName="figcaption"
aria-label={ __( 'Table caption text' ) }
placeholder={ __( 'Write caption…' ) }
value={ caption }
onChange={ ( value ) =>
Expand Down
7 changes: 6 additions & 1 deletion packages/block-library/src/text-columns/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { get, times } from 'lodash';
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { __, sprintf } from '@wordpress/i18n';
import { PanelBody, RangeControl } from '@wordpress/components';
import {
BlockControls,
Expand Down Expand Up @@ -73,6 +73,11 @@ export default function TextColumnsEdit( { attributes, setAttributes } ) {
],
} );
} }
aria-label={ sprintf(
// translators: %d: column index (starting with 1)
__( 'Column %d text' ),
index + 1
) }
placeholder={ __( 'New Column' ) }
/>
</div>
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/verse/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export default function VerseEdit( {
content: nextContent,
} );
} }
aria-label={ __( 'Verse text' ) }
placeholder={ __( 'Write…' ) }
onMerge={ mergeBlocks }
textAlign={ textAlign }
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/video/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ function VideoEdit( {
{ ( ! RichText.isEmpty( caption ) || isSelected ) && (
<RichText
tagName="figcaption"
aria-label={ __( 'Video caption text' ) }
placeholder={ __( 'Write caption…' ) }
value={ caption }
onChange={ ( value ) =>
Expand Down

0 comments on commit 8e76797

Please sign in to comment.