diff --git a/editor/modes/visual-editor/sibling-inserter.js b/editor/modes/visual-editor/sibling-inserter.js index 8965a24335f467..e0b92d51cd1aed 100644 --- a/editor/modes/visual-editor/sibling-inserter.js +++ b/editor/modes/visual-editor/sibling-inserter.js @@ -8,7 +8,6 @@ import classnames from 'classnames'; * WordPress dependencies */ import { Component } from '@wordpress/element'; -import { focus } from '@wordpress/utils'; /** * Internal dependencies @@ -23,98 +22,41 @@ class VisualEditorSiblingInserter extends Component { constructor() { super( ...arguments ); - this.bindNode = this.bindNode.bind( this ); - this.focusFirstTabbable = this.focusFirstTabbable.bind( this ); - this.show = this.toggleVisible.bind( this, true ); - this.hide = this.toggleVisible.bind( this, false ); - this.showAndFocus = this.showAndFocus.bind( this ); - this.suspendToggleVisible = this.suspendToggleVisible.bind( this ); + this.forceVisibleWhileInserting = this.forceVisibleWhileInserting.bind( this ); this.state = { - isVisible: false, - isToggleVisibleSuspended: false, + isForcedVisible: false, }; } - componentDidUpdate( prevProps, prevState ) { - const { visibleViaFocus, state } = this; - const { isVisible, isToggleVisibleSuspended } = state; - if ( isVisible && ! prevState.isVisible && visibleViaFocus ) { - this.focusFirstTabbable(); - - // Reset for next toggle visible - this.visibleViaFocus = false; - } - - // If inserter is closed, we must check to see if focus is still within - // the inserter, since it may have been closed by clicking outside. We - // want to retain visible if still focused, or hide otherwise. - if ( ! isToggleVisibleSuspended && prevState.isToggleVisibleSuspended && - ! this.node.contains( document.activeElement ) ) { - this.toggleVisible( false ); - } - } - - bindNode( node ) { - this.node = node; - } - - focusFirstTabbable() { - // Sibling inserter doesn't render its inserter button until after it - // becomes visible by focus or hover. If visible by focus, move focus - // into the now-visible button. - const tabbable = focus.tabbable.find( this.node ); - if ( tabbable.length ) { - tabbable[ 0 ].focus(); - } - } - - toggleVisible( isVisible ) { - if ( ! this.state.isToggleVisibleSuspended ) { - this.setState( { isVisible } ); - } - } - - showAndFocus() { - this.toggleVisible( true ); - this.visibleViaFocus = true; - } - - suspendToggleVisible( isOpen ) { + forceVisibleWhileInserting( isOpen ) { // Prevent mouseout and blur while navigating the open inserter menu // from causing the inserter to be unmounted. - this.setState( { isToggleVisibleSuspended: isOpen } ); + this.setState( { isForcedVisible: isOpen } ); } render() { const { insertIndex, showInsertionPoint } = this.props; - const { isVisible } = this.state; + const { isForcedVisible } = this.state; const classes = classnames( 'editor-visual-editor__sibling-inserter', { - 'is-visible': isVisible || showInsertionPoint, + 'is-forced-visible': isForcedVisible || showInsertionPoint, } ); return (