-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Mobile] Move unselected block accessibility handling to block-holder…
… (v2) (#15225) * Update paragraph block accessibility label * Move block unselected state accessibility handling to block-holder * Add getAccessibilityLabel to block settings * Rename getAccessibilityLabel into __experimentalGetAccessibilityLabel * Make __experimentalGetAccessibilityLabel only available for native mobile * Handle not alt and a caption case * Handle no caption case * Fix merge mistake in prop names * Handle setting UnrecognizedBlock accessibility label in BlockHolder * Fix lint errors
- Loading branch information
Showing
7 changed files
with
149 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { isEmpty } from 'lodash'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __, sprintf } from '@wordpress/i18n'; | ||
import { create } from '@wordpress/rich-text'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { settings as webSettings } from './index.js'; | ||
|
||
export { metadata, name } from './index.js'; | ||
|
||
export const settings = { | ||
...webSettings, | ||
__experimentalGetAccessibilityLabel( attributes ) { | ||
const { content, level } = attributes; | ||
|
||
const plainTextContent = ( html ) => create( { html } ).text || ''; | ||
|
||
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, | ||
plainTextContent( content ) | ||
); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { settings as webSettings } from './index.js'; | ||
|
||
export { metadata, name } from './index.js'; | ||
|
||
export const settings = { | ||
...webSettings, | ||
__experimentalGetAccessibilityLabel( attributes ) { | ||
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 : '' ); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { isEmpty } from 'lodash'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { create } from '@wordpress/rich-text'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { settings as webSettings } from './index.js'; | ||
|
||
export { metadata, name } from './index.js'; | ||
|
||
export const settings = { | ||
...webSettings, | ||
__experimentalGetAccessibilityLabel( attributes ) { | ||
const { content } = attributes; | ||
|
||
const plainTextContent = ( html ) => create( { html } ).text || ''; | ||
|
||
return isEmpty( content ) ? __( 'Empty' ) : plainTextContent( content ); | ||
}, | ||
}; |