diff --git a/docs/manifest.json b/docs/manifest.json index b9b8a239a36ba..abcc27569c88e 100644 --- a/docs/manifest.json +++ b/docs/manifest.json @@ -1199,6 +1199,18 @@ "markdown_source": "../packages/components/src/toolbar-button/README.md", "parent": "components" }, + { + "title": "ToolbarGroup", + "slug": "toolbar-group", + "markdown_source": "../packages/components/src/toolbar-group/README.md", + "parent": "components" + }, + { + "title": "ToolbarItem", + "slug": "toolbar-item", + "markdown_source": "../packages/components/src/toolbar-item/README.md", + "parent": "components" + }, { "title": "Toolbar", "slug": "toolbar", diff --git a/packages/block-editor/src/components/block-mover/index.js b/packages/block-editor/src/components/block-mover/index.js index 0b45496222043..d4b9cc66ead73 100644 --- a/packages/block-editor/src/components/block-mover/index.js +++ b/packages/block-editor/src/components/block-mover/index.js @@ -7,10 +7,7 @@ import classnames from 'classnames'; /** * WordPress dependencies */ -import { - ToolbarGroup, - __experimentalToolbarItem as ToolbarItem, -} from '@wordpress/components'; +import { ToolbarGroup, ToolbarItem } from '@wordpress/components'; import { getBlockType } from '@wordpress/blocks'; import { Component } from '@wordpress/element'; import { withSelect } from '@wordpress/data'; diff --git a/packages/block-editor/src/components/block-settings-menu/index.js b/packages/block-editor/src/components/block-settings-menu/index.js index 7014f29f0e336..0b0b1a775e736 100644 --- a/packages/block-editor/src/components/block-settings-menu/index.js +++ b/packages/block-editor/src/components/block-settings-menu/index.js @@ -1,10 +1,7 @@ /** * WordPress dependencies */ -import { - ToolbarGroup, - __experimentalToolbarItem as ToolbarItem, -} from '@wordpress/components'; +import { ToolbarGroup, ToolbarItem } from '@wordpress/components'; /** * Internal dependencies diff --git a/packages/block-editor/src/components/block-switcher/index.js b/packages/block-editor/src/components/block-switcher/index.js index 1326e7c76cff7..6f77c5ccf8be3 100644 --- a/packages/block-editor/src/components/block-switcher/index.js +++ b/packages/block-editor/src/components/block-switcher/index.js @@ -11,7 +11,7 @@ import { DropdownMenu, ToolbarButton, ToolbarGroup, - __experimentalToolbarItem as ToolbarItem, + ToolbarItem, MenuGroup, Popover, } from '@wordpress/components'; diff --git a/packages/block-editor/src/components/navigable-toolbar/index.js b/packages/block-editor/src/components/navigable-toolbar/index.js index d0816a6236890..931932b7ab6da 100644 --- a/packages/block-editor/src/components/navigable-toolbar/index.js +++ b/packages/block-editor/src/components/navigable-toolbar/index.js @@ -9,6 +9,7 @@ import { useEffect, useCallback, } from '@wordpress/element'; +import deprecated from '@wordpress/deprecated'; import { focus } from '@wordpress/dom'; import { useShortcut } from '@wordpress/keyboard-shortcuts'; @@ -23,7 +24,7 @@ function useUpdateLayoutEffect( effect, deps ) { } function hasOnlyToolbarItem( elements ) { - const dataProp = 'experimentalToolbarItem'; + const dataProp = 'toolbarItem'; return ! elements.some( ( element ) => ! ( dataProp in element.dataset ) ); } @@ -59,7 +60,15 @@ function useIsAccessibleToolbar( ref ) { const determineIsAccessibleToolbar = useCallback( () => { const tabbables = focus.tabbable.find( ref.current ); - setIsAccessibleToolbar( hasOnlyToolbarItem( tabbables ) ); + const onlyToolbarItem = hasOnlyToolbarItem( tabbables ); + if ( ! onlyToolbarItem ) { + deprecated( 'Using custom components as toolbar controls', { + alternative: 'ToolbarItem or ToolbarButton components', + link: + 'https://developer.wordpress.org/block-editor/components/toolbar-button/#inside-blockcontrols', + } ); + } + setIsAccessibleToolbar( onlyToolbarItem ); }, [] ); useLayoutEffect( determineIsAccessibleToolbar, [] ); @@ -106,7 +115,7 @@ function NavigableToolbar( { children, focusOnMount, ...props } ) { if ( isAccessibleToolbar ) { return ( diff --git a/packages/block-editor/src/components/rich-text/format-toolbar/index.js b/packages/block-editor/src/components/rich-text/format-toolbar/index.js index e0c35b11cdae5..4e98ce8d064ba 100644 --- a/packages/block-editor/src/components/rich-text/format-toolbar/index.js +++ b/packages/block-editor/src/components/rich-text/format-toolbar/index.js @@ -10,7 +10,7 @@ import { orderBy } from 'lodash'; import { __ } from '@wordpress/i18n'; import { - __experimentalToolbarItem as ToolbarItem, + ToolbarItem, ToolbarGroup, DropdownMenu, Slot, diff --git a/packages/block-library/src/classic/edit.js b/packages/block-library/src/classic/edit.js index 238afa052a15b..8195e51006af4 100644 --- a/packages/block-library/src/classic/edit.js +++ b/packages/block-library/src/classic/edit.js @@ -7,7 +7,7 @@ import { debounce } from 'lodash'; * WordPress dependencies */ import { BlockControls } from '@wordpress/block-editor'; -import { Toolbar } from '@wordpress/components'; +import { ToolbarGroup } from '@wordpress/components'; import { Component } from '@wordpress/element'; import { __, _x } from '@wordpress/i18n'; import { BACKSPACE, DELETE, F10, isKeyboardEvent } from '@wordpress/keycodes'; @@ -248,9 +248,9 @@ export default class ClassicEdit extends Component { return ( <> - + - +
( ( - -); +import { Toolbar, ToolbarButton } from '@wordpress/components'; +import { edit } from '@wordpress/icons'; + +function MyToolbar() { + return ( + + alert( 'Editing' ) } + /> + + ); +} +``` + +### Inside BlockControls + +If you're working on a custom block and you want to add controls to the block toolbar, you should use [BlockControls](/docs/designers-developers/developers/tutorials/block-tutorial/block-controls-toolbar-and-sidebar.md) instead. Optinally wrapping it with [ToolbarGroup](/packages/components/src/toolbar-group/README.md). + +```jsx +import { BlockControls } from '@wordpress/block-editor'; +import { ToolbarGroup, ToolbarButton } from '@wordpress/components'; +import { edit } from '@wordpress/icons'; + +function Edit() { + return ( + + + alert( 'Editing' ) } + /> + + + ); +} ``` ## Props diff --git a/packages/components/src/toolbar-button/index.js b/packages/components/src/toolbar-button/index.js index f449ecdd2d523..d053ea2b52cf6 100644 --- a/packages/components/src/toolbar-button/index.js +++ b/packages/components/src/toolbar-button/index.js @@ -30,8 +30,6 @@ function ToolbarButton( const accessibleToolbarState = useContext( ToolbarContext ); if ( ! accessibleToolbarState ) { - // This should be deprecated when - // becomes stable. return (