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

[RNMobile] Focus RichText on mount if block is selected and says so #15878

Merged
merged 5 commits into from
May 30, 2019
Merged
Show file tree
Hide file tree
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
15 changes: 9 additions & 6 deletions packages/block-editor/src/components/rich-text/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,11 @@ export class RichText extends Component {
}

componentDidMount() {
if ( this.props.isSelected ) {
// Request focus if wrapping block is selected and parent hasn't inhibited the focus request. This method of focusing
// is trying to implement the web-side counterpart of BlockList's `focusTabbable` where the BlockList is focusing an
// inputbox by searching the DOM. We don't have the DOM in RN so, using the combination of blockIsSelected and noFocusOnMount
// to determine if we should focus the RichText.
if ( this.props.blockIsSelected && ! this.props.noFocusOnMount ) {
this._editor.focus();
this.onSelectionChange( this.props.selectionStart || 0, this.props.selectionEnd || 0 );
}
Expand Down Expand Up @@ -889,16 +893,13 @@ RichText.defaultProps = {
const RichTextContainer = compose( [
withInstanceId,
withBlockEditContext( ( { clientId, onFocus, onCaretVerticalPositionChange, isSelected }, ownProps ) => {
// ownProps.onFocus and isSelected needs precedence over the block edit context
if ( ownProps.isSelected !== undefined ) {
isSelected = ownProps.isSelected;
}
// ownProps.onFocus and needs precedence over the block edit context
hypest marked this conversation as resolved.
Show resolved Hide resolved
if ( ownProps.onFocus !== undefined ) {
onFocus = ownProps.onFocus;
}
return {
isSelected,
clientId,
blockIsSelected: ownProps.isSelected !== undefined ? ownProps.isSelected : isSelected,
onFocus,
onCaretVerticalPositionChange,
};
Expand All @@ -908,6 +909,7 @@ const RichTextContainer = compose( [
instanceId,
identifier = instanceId,
isSelected,
blockIsSelected,
} ) => {
const { getFormatTypes } = select( 'core/rich-text' );
const {
Expand All @@ -930,6 +932,7 @@ const RichTextContainer = compose( [
selectionStart: isSelected ? selectionStart.offset : undefined,
selectionEnd: isSelected ? selectionEnd.offset : undefined,
isSelected,
blockIsSelected,
};
} ),
withDispatch( ( dispatch, {
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/image/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ class ImageEdit extends React.Component {
onFocus={ this.onFocusCaption }
onBlur={ this.props.onBlur } // always assign onBlur as props
isSelected={ this.state.isCaptionSelected }
noFocusOnMount={ true }
fontSize={ 14 }
underlineColorAndroid="transparent"
textAlign={ 'center' }
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/quote/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export default function QuoteEdit( { attributes, setAttributes, isSelected, merg
citation: nextCitation,
} )
}
noFocusOnMount={ true }
hypest marked this conversation as resolved.
Show resolved Hide resolved
placeholder={
// translators: placeholder text used for the citation
__( 'Write citation…' )
Expand Down