Skip to content

Commit

Permalink
Move mobile accessibility labels to be cross-platform
Browse files Browse the repository at this point in the history
  • Loading branch information
talldan committed Dec 11, 2019
1 parent 7bf4683 commit 516c05c
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 130 deletions.
25 changes: 24 additions & 1 deletion packages/block-library/src/heading/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
/**
* External dependencies
*/
import { isEmpty } from 'lodash';

/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { __, sprintf } from '@wordpress/i18n';

/**
* Internal dependencies
Expand Down Expand Up @@ -31,6 +36,24 @@ export const settings = {
level: 2,
},
},
__experimentalLabel( attributes, { context } ) {
if ( context === 'accessibility' ) {
const { content, level } = attributes;

return isEmpty( content ) ?
sprintf(
/* translators: accessibility text. %s: heading level. */
__( 'Level %s. Empty.' ),
level
) :
sprintf(
/* translators: accessibility text. 1: heading level. 2: heading content. */
__( 'Level %1$s. %2$s' ),
level,
content
);
}
},
transforms,
deprecated,
merge( attributes, attributesToMerge ) {
Expand Down
36 changes: 0 additions & 36 deletions packages/block-library/src/heading/index.native.js

This file was deleted.

17 changes: 17 additions & 0 deletions packages/block-library/src/image/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,23 @@ export const settings = {
{ name: 'default', label: _x( 'Default', 'block style' ), isDefault: true },
{ name: 'circle-mask', label: _x( 'Circle Mask', 'block style' ) },
],
__experimentalLabel( attributes, { context } ) {
if ( context === 'accessibility' ) {
const { caption, alt, url } = attributes;

if ( ! url ) {
return __( 'Empty' );
}

if ( ! alt ) {
return caption || '';
}

// This is intended to be read by a screen reader.
// A period simply means a pause, no need to translate it.
return alt + ( caption ? '. ' + caption : '' );
}
},
transforms,
getEditWrapperProps( attributes ) {
const { align, width } = attributes;
Expand Down
30 changes: 0 additions & 30 deletions packages/block-library/src/image/index.native.js

This file was deleted.

14 changes: 14 additions & 0 deletions packages/block-library/src/missing/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { getBlockType } from '@wordpress/blocks';

/**
* Internal dependencies
Expand All @@ -25,6 +26,19 @@ export const settings = {
html: false,
reusable: false,
},
__experimentalLabel( attributes, { context } ) {
if ( context === 'accessibility' ) {
const { originalName } = attributes;

const originalBlockType = originalName ? getBlockType( originalName ) : undefined;

if ( originalBlockType ) {
return originalBlockType.settings.title || originalName;
}

return '';
}
},
edit,
save,
};
26 changes: 0 additions & 26 deletions packages/block-library/src/missing/index.native.js

This file was deleted.

5 changes: 5 additions & 0 deletions packages/block-library/src/more/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ export const settings = {
multiple: false,
},
example: {},
__experimentalLabel( attributes, { context } ) {
if ( context === 'accessibility' ) {
return attributes.customText;
}
},
transforms,
edit,
save,
Expand Down
13 changes: 0 additions & 13 deletions packages/block-library/src/more/index.native.js

This file was deleted.

11 changes: 11 additions & 0 deletions packages/block-library/src/paragraph/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/**
* External dependencies
*/
import { isEmpty } from 'lodash';

/**
* WordPress dependencies
*/
Expand Down Expand Up @@ -32,6 +37,12 @@ export const settings = {
supports: {
className: false,
},
__experimentalLabel( attributes, { context } ) {
if ( context === 'accessibility' ) {
const { content } = attributes;
return isEmpty( content ) ? __( 'Empty' ) : content;
}
},
transforms,
deprecated,
merge( attributes, attributesToMerge ) {
Expand Down
24 changes: 0 additions & 24 deletions packages/block-library/src/paragraph/index.native.js

This file was deleted.

0 comments on commit 516c05c

Please sign in to comment.