Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Mobile]Paragraph - Add accessibility label for unselected state #15126

Merged
merged 2 commits into from
Apr 24, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 27 additions & 3 deletions packages/block-library/src/paragraph/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* External dependencies
*/
import { View } from 'react-native';
import { isEmpty } from 'lodash';

/**
* WordPress dependencies
Expand All @@ -22,6 +23,12 @@ class ParagraphEdit extends Component {
super( props );
this.splitBlock = this.splitBlock.bind( this );
this.onReplace = this.onReplace.bind( this );
this.onFocus = this.onFocus.bind( this );
this.onBlur = this.onBlur.bind( this );

this.state = {
isSelected: false,
};
}

/**
Expand Down Expand Up @@ -81,6 +88,20 @@ class ParagraphEdit extends Component {
) ) );
}

onFocus() {
this.setState( { isSelected: true } );
if ( this.props.onFocus ) {
this.props.onFocus();
}
}

onBlur() {
this.setState( { isSelected: false } );
if ( this.props.onBlur ) {
this.props.onBlur();
}
}

render() {
const {
attributes,
Expand All @@ -95,13 +116,16 @@ class ParagraphEdit extends Component {
} = attributes;

return (
<View>
<View
accessible={ ! this.state.isSelected }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we should probably use isSelected from props. In that way it will be properly set to false when the block is selected by any method (not just from focusing RichText directly), and ScreenReader won't read this label after double tap to select.

accessibilityLabel={ __( 'Paragraph block' ) + __( '.' ) + ' ' + ( isEmpty( content ) ? __( 'Empty' ) : content ) }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we could use onAccessibilityTap={ this.props.onFocus } to avoid defining the internal onFocus method.
The parent component (BlockHolder) should be in charge of setting the selection state of the block in the store. And we can use that state from the store internally via props.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more detail: content has all the html code, so the ScreenReader will read the html tags too.
We can clean it up using: import { create } from '@wordpress/rich-text';

>
<RichText
tagName="p"
value={ content }
isSelected={ this.props.isSelected }
onFocus={ this.props.onFocus } // always assign onFocus as a props
onBlur={ this.props.onBlur } // always assign onBlur as a props
onFocus={ this.onFocus }
onBlur={ this.onBlur }
onCaretVerticalPositionChange={ this.props.onCaretVerticalPositionChange }
style={ style }
onChange={ ( nextContent ) => {
Expand Down