diff --git a/components/button/index.js b/components/button/index.js index 07b5d7c622296a..079038a4297bbb 100644 --- a/components/button/index.js +++ b/components/button/index.js @@ -6,40 +6,61 @@ import classnames from 'classnames'; /** * WordPress dependencies */ -import { createElement } from '@wordpress/element'; +import { Component, createElement } from '@wordpress/element'; /** * Internal dependencies */ import './style.scss'; -function Button( { - href, - target, - isPrimary, - isLarge, - isSmall, - isToggled, - className, - disabled, - ...additionalProps -} ) { - const classes = classnames( 'components-button', className, { - button: ( isPrimary || isLarge ), - 'button-primary': isPrimary, - 'button-large': isLarge, - 'button-small': isSmall, - 'is-toggled': isToggled, - } ); - - const tag = href !== undefined && ! disabled ? 'a' : 'button'; - const tagProps = tag === 'a' ? { href, target } : { type: 'button', disabled }; - - return createElement( tag, { - ...tagProps, - ...additionalProps, - className: classes, - } ); +class Button extends Component { + constructor( props ) { + super( props ); + this.setRef = this.setRef.bind( this ); + } + + componentDidMount() { + if ( this.props.focus ) { + this.ref.focus(); + } + } + + setRef( ref ) { + this.ref = ref; + } + + render() { + const { + href, + target, + isPrimary, + isLarge, + isSmall, + isToggled, + className, + disabled, + ...additionalProps + } = this.props; + const classes = classnames( 'components-button', className, { + button: ( isPrimary || isLarge ), + 'button-primary': isPrimary, + 'button-large': isLarge, + 'button-small': isSmall, + 'is-toggled': isToggled, + } ); + + const tag = href !== undefined && ! disabled ? 'a' : 'button'; + const tagProps = tag === 'a' ? { href, target } : { type: 'button', disabled }; + + delete additionalProps.focus; + + return createElement( tag, { + ...tagProps, + ...additionalProps, + className: classes, + ref: this.setRef, + } ); + } } export default Button; diff --git a/components/icon-button/index.js b/components/icon-button/index.js index 0449ceeac5be7c..a078b0ef959aa8 100644 --- a/components/icon-button/index.js +++ b/components/icon-button/index.js @@ -21,11 +21,11 @@ import Dashicon from '../dashicon'; // is common to apply a ref to the button element (only supported in class) class IconButton extends Component { render() { - const { icon, children, label, className, tooltip, ...additionalProps } = this.props; + const { icon, children, label, className, tooltip, focus, ...additionalProps } = this.props; const classes = classnames( 'components-icon-button', className ); let element = ( - diff --git a/editor/block-settings-menu/index.js b/editor/block-settings-menu/index.js index c265b97f152e0c..1a87a3581ac315 100644 --- a/editor/block-settings-menu/index.js +++ b/editor/block-settings-menu/index.js @@ -20,7 +20,7 @@ import BlockDeleteButton from './block-delete-button'; import { selectBlock } from '../actions'; import UnknownConverter from './unknown-converter'; -function BlockSettingsMenu( { uids, onSelect } ) { +function BlockSettingsMenu( { uids, onSelect, focus } ) { const count = uids.length; return ( @@ -32,6 +32,7 @@ function BlockSettingsMenu( { uids, onSelect } ) { const toggleClassname = classnames( 'editor-block-settings-menu__toggle', { 'is-opened': isOpen, } ); + return ( ); } } diff --git a/editor/modes/visual-editor/block.js b/editor/modes/visual-editor/block.js index 5295121e6679b5..6a7c1a446707a0 100644 --- a/editor/modes/visual-editor/block.js +++ b/editor/modes/visual-editor/block.js @@ -321,7 +321,7 @@ class VisualEditorBlock extends Component { // Generate the wrapper class names handling the different states of the block. const { isHovered, isSelected, isMultiSelected, isFirstMultiSelected, focus } = this.props; - const showUI = isSelected && ( ! this.props.isTyping || focus.collapsed === false ); + const showUI = isSelected && ( ! this.props.isTyping || ( focus && focus.collapsed === false ) ); const isProperlyHovered = isHovered && ! this.props.isSelecting; const { error } = this.state; const wrapperClassName = classnames( 'editor-visual-editor__block', { @@ -362,7 +362,10 @@ class VisualEditorBlock extends Component { } { isFirstMultiSelected && ! this.props.isSelecting && - + }
+
{ children }
); + /* eslint-disable jsx-a11y/no-static-element-interactions */ } }