Skip to content

Commit 44b9536

Browse files
committed
Docs: Update docs to reflect the change in how block controls are handled
1 parent 3d612a0 commit 44b9536

File tree

2 files changed

+15
-25
lines changed

2 files changed

+15
-25
lines changed

blocks/README.md

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -275,12 +275,6 @@ buttons. This is useful for block-level modifications to be made available when
275275
a block is selected. For example, if your block supports alignment, you may
276276
want to display alignment options in the selected block's toolbar.
277277

278-
Because the toolbar should only be shown when the block is selected, it is
279-
important that a `BlockControls` element is only returned when the block's
280-
`isSelected` prop is
281-
[truthy](https://developer.mozilla.org/en-US/docs/Glossary/Truthy),
282-
meaning that the block is currently selected.
283-
284278
Example:
285279

286280
```js
@@ -292,15 +286,13 @@ Example:
292286
function edit( props ) {
293287
return [
294288
// Controls: (only visible when block is selected)
295-
props.isSelected && (
296-
el( BlockControls, { key: 'controls' },
297-
el( AlignmentToolbar, {
298-
value: props.align,
299-
onChange: function( nextAlign ) {
300-
props.setAttributes( { align: nextAlign } )
301-
}
302-
} )
303-
)
289+
el( BlockControls, { key: 'controls' },
290+
el( AlignmentToolbar, {
291+
value: props.align,
292+
onChange: function( nextAlign ) {
293+
props.setAttributes( { align: nextAlign } )
294+
}
295+
} )
304296
),
305297

306298
// Block content: (with alignment as attribute)

docs/blocks-controls.md

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ registerBlockType( 'gutenberg-boilerplate-es5/hello-world-step-04', {
5151
}
5252

5353
return [
54-
isSelected && el(
54+
el(
5555
BlockControls,
5656
{ key: 'controls' },
5757
el(
@@ -124,14 +124,12 @@ registerBlockType( 'gutenberg-boilerplate-esnext/hello-world-step-04', {
124124
}
125125

126126
return [
127-
isSelected && (
128-
<BlockControls key="controls">
129-
<AlignmentToolbar
130-
value={ alignment }
131-
onChange={ onChangeAlignment }
132-
/>
133-
</BlockControls>
134-
),
127+
<BlockControls key="controls">
128+
<AlignmentToolbar
129+
value={ alignment }
130+
onChange={ onChangeAlignment }
131+
/>
132+
</BlockControls>,
135133
<RichText
136134
key="editable"
137135
tagName="p"
@@ -152,7 +150,7 @@ registerBlockType( 'gutenberg-boilerplate-esnext/hello-world-step-04', {
152150
```
153151
{% end %}
154152

155-
Note that you should only include `BlockControls` if the block is currently selected. We must test that the `isSelected` value is truthy before rendering the element, otherwise you will inadvertently cause controls to be shown for the incorrect block type.
153+
Note that `BlockControls` is only visible when the block is currently selected.
156154

157155
## Inspector
158156

0 commit comments

Comments
 (0)