-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
* External dependencies | ||
*/ | ||
import { View } from 'react-native'; | ||
import { isEmpty } from 'lodash'; | ||
|
||
/** | ||
* WordPress dependencies | ||
|
@@ -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, | ||
}; | ||
} | ||
|
||
/** | ||
|
@@ -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, | ||
|
@@ -95,13 +116,16 @@ class ParagraphEdit extends Component { | |
} = attributes; | ||
|
||
return ( | ||
<View> | ||
<View | ||
accessible={ ! this.state.isSelected } | ||
accessibilityLabel={ __( 'Paragraph block' ) + __( '.' ) + ' ' + ( isEmpty( content ) ? __( 'Empty' ) : content ) } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here we could use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One more detail: |
||
> | ||
<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 ) => { | ||
|
There was a problem hiding this comment.
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 tofalse
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.