From b824a73268657f6d071db5a24ff75f9059db0762 Mon Sep 17 00:00:00 2001 From: Pinar Olguc Date: Wed, 24 Apr 2019 18:46:23 +0300 Subject: [PATCH] Set accessibility props for Heading (#15144) --- .../block-library/src/heading/edit.native.js | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/packages/block-library/src/heading/edit.native.js b/packages/block-library/src/heading/edit.native.js index eb44dd8126dcc9..5d32ba0b3d5745 100644 --- a/packages/block-library/src/heading/edit.native.js +++ b/packages/block-library/src/heading/edit.native.js @@ -2,11 +2,13 @@ * Internal dependencies */ import HeadingToolbar from './heading-toolbar'; +import styles from './editor.scss'; /** * External dependencies */ import { View } from 'react-native'; +import { isEmpty } from 'lodash'; /** * WordPress dependencies @@ -15,8 +17,7 @@ import { __ } from '@wordpress/i18n'; import { Component } from '@wordpress/element'; import { RichText, BlockControls } from '@wordpress/block-editor'; import { createBlock } from '@wordpress/blocks'; - -import styles from './editor.scss'; +import { create } from '@wordpress/rich-text'; const name = 'core/heading'; @@ -73,6 +74,14 @@ class HeadingEdit extends Component { } } + plainTextContent( html ) { + const result = create( { html } ); + if ( result ) { + return result.text; + } + return ''; + } + render() { const { attributes, @@ -89,8 +98,15 @@ class HeadingEdit extends Component { const tagName = 'h' + level; + const accessibilityLabelLevel = __( 'level' ) + ' ' + level + __( '.' ); + const accessibilityLabelContent = isEmpty( content ) ? __( 'Empty' ) : this.plainTextContent( content ); + return ( - + setAttributes( { level: newLevel } ) } />