Skip to content

Commit

Permalink
[RNMobile] Blur post title any time another block is selected (#16642)
Browse files Browse the repository at this point in the history
* Unselect post title any time another block is selected
* Remove unnecessary state check
  • Loading branch information
mchowning authored Jul 19, 2019
1 parent 6ef0222 commit b1b9c11
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
11 changes: 11 additions & 0 deletions packages/edit-post/src/components/visual-editor/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ class VisualEditor extends Component {
};
}

static getDerivedStateFromProps( props ) {
if ( props.isAnyBlockSelected ) {
return { isPostTitleSelected: false };
}
return null;
}

onPostTitleSelect() {
this.setState( { isPostTitleSelected: true } );
this.props.clearSelectedBlock();
Expand Down Expand Up @@ -87,6 +94,7 @@ class VisualEditor extends Component {
rootViewHeight={ rootViewHeight }
safeAreaBottomInset={ safeAreaBottomInset }
isPostTitleSelected={ this.state.isPostTitleSelected }
onBlockTypeSelected={ this.onPostTitleUnselect }
/>
</BlockEditorProvider>
);
Expand All @@ -100,9 +108,12 @@ export default compose( [
getEditedPostAttribute,
} = select( 'core/editor' );

const { getSelectedBlockClientId } = select( 'core/block-editor' );

return {
blocks: getEditorBlocks(),
title: getEditedPostAttribute( 'title' ),
isAnyBlockSelected: !! getSelectedBlockClientId(),
};
} ),
withDispatch( ( dispatch ) => {
Expand Down
15 changes: 2 additions & 13 deletions packages/editor/src/components/post-title/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,6 @@ import { pasteHandler } from '@wordpress/blocks';
import styles from './style.scss';

class PostTitle extends Component {
constructor() {
super( ...arguments );

this.titleViewRef = null;
}

componentDidMount() {
if ( this.props.innerRef ) {
this.props.innerRef( this );
Expand All @@ -39,10 +33,7 @@ class PostTitle extends Component {
}

focus() {
if ( this.titleViewRef ) {
this.titleViewRef.focus();
this.props.onSelect();
}
this.props.onSelect();
}

render() {
Expand Down Expand Up @@ -91,10 +82,8 @@ class PostTitle extends Component {
onSelectionChange={ () => { } }
onEnter={ this.props.onEnterPress }
disableEditingMenu={ true }
setRef={ ( ref ) => {
this.titleViewRef = ref;
} }
__unstablePasteHandler={ pasteHandler }
__unstableIsSelected={ this.props.isSelected }
>
</RichText>
</View>
Expand Down

0 comments on commit b1b9c11

Please sign in to comment.