diff --git a/blocks/README.md b/blocks/README.md index b34f78338e6b5..42014611ca8be 100644 --- a/blocks/README.md +++ b/blocks/README.md @@ -277,9 +277,9 @@ want to display alignment options in the selected block's toolbar. Because the toolbar should only be shown when the block is selected, it is important that a `BlockControls` element is only returned when the block's -`focus` prop is +`isSelected` prop is [truthy](https://developer.mozilla.org/en-US/docs/Glossary/Truthy), -meaning that focus is currently within the block. +meaning that the block is currently selected. Example: @@ -291,8 +291,8 @@ Example: function edit( props ) { return [ - // Controls: (only visible when focused) - props.focus && ( + // Controls: (only visible when block is selected) + props.isSelected && ( el( BlockControls, { key: 'controls' }, el( AlignmentToolbar, { value: props.align, diff --git a/blocks/block-controls/index.js b/blocks/block-controls/index.js index e23a344f955ad..ed25d5849d816 100644 --- a/blocks/block-controls/index.js +++ b/blocks/block-controls/index.js @@ -5,7 +5,7 @@ import { Toolbar, Fill } from '@wordpress/components'; export default function BlockControls( { controls, children } ) { return ( - + { children } diff --git a/blocks/block-controls/test/__snapshots__/index.js.snap b/blocks/block-controls/test/__snapshots__/index.js.snap index 78c75ad990fb2..f1cf3c119e9ad 100644 --- a/blocks/block-controls/test/__snapshots__/index.js.snap +++ b/blocks/block-controls/test/__snapshots__/index.js.snap @@ -2,7 +2,7 @@ exports[`BlockControls Should render a dynamic toolbar of controls 1`] = ` ; + // For backwards compatibility concerns adds a focus and setFocus prop + // These should be removed after some time (maybe when merging to Core) + return ( + + ); } export default withFilters( 'blocks.BlockEdit' )( BlockEdit ); diff --git a/blocks/library/audio/index.js b/blocks/library/audio/index.js index 6a66ce3e81de5..c47b248296bb3 100644 --- a/blocks/library/audio/index.js +++ b/blocks/library/audio/index.js @@ -70,7 +70,7 @@ export const settings = { } render() { const { align, caption, id } = this.props.attributes; - const { setAttributes, focus, setFocus } = this.props; + const { setAttributes, isSelected } = this.props; const { editing, className, src } = this.state; const updateAlignment = ( nextAlign ) => setAttributes( { align: nextAlign } ); const switchToEditing = () => { @@ -93,7 +93,7 @@ export const settings = { } return false; }; - const controls = focus && ( + const controls = isSelected && ( ); - const focusCaption = ( focusValue ) => setFocus( { editable: 'caption', ...focusValue } ); - if ( editing ) { return [ controls, @@ -153,14 +151,13 @@ export const settings = { controls,