-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make accessible toolbar stable and deprecate old usage (#23316)
* Deprecate legacy toolbar usage * Update e2e tests * Remove __experimental flag from Toolbar accessibilityLabel prop * Use label instead of accessibilityLabel * Deprecate <Toolbar> without label prop * Make ToolbarItem component stable * Deprecate ToolbarButton usage without a parent Toolbar * Simplify jsdocs * data-experimental-toolbar-item to data-toolbar-item * Remove deprecation warning from ToolbarButton This is actually an invalid warning as it may still be rendered inside <ToolbarGroup /> * Update unit test * Update Toolbar README * Update tests * Remove ToolbarGroup test from Toolbar * Replace Toolbar by ToolbarGroup on the Classic Editor * Add Toolbar, ToolbarButton, ToolbarGroup and ToolbarItem docs * Add links to depreaction notices and warnings * Update ToolbarButton docs * Improve documentation around BlockControls usage * Update deprecation warning link on Navigable Toolbar * Update ToolbarItem README * Update ToolbarItem README
- Loading branch information
Showing
27 changed files
with
255 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 1 addition & 4 deletions
5
packages/block-editor/src/components/block-settings-menu/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# ToolbarGroup | ||
|
||
A ToolbarGroup can be used to create subgroups of controls inside a [Toolbar](/packages/components/src/toolbar/README.md). | ||
|
||
## Usage | ||
|
||
```jsx | ||
import { Toolbar, ToolbarGroup, ToolbarButton } from '@wordpress/components'; | ||
import { paragraph, formatBold, formatItalic, link } from '@wordpress/icons'; | ||
|
||
function MyToolbar() { | ||
return ( | ||
<Toolbar label="Options"> | ||
<ToolbarGroup> | ||
<ToolbarButton icon={ paragraph } label="Paragraph" /> | ||
</ToolbarGroup> | ||
<ToolbarGroup> | ||
<ToolbarButton icon={ formatBold } label="Bold" /> | ||
<ToolbarButton icon={ formatItalic } label="Italic" /> | ||
<ToolbarButton icon={ link } label="Link" /> | ||
</ToolbarGroup> | ||
</Toolbar> | ||
); | ||
} | ||
``` | ||
|
||
### Props | ||
|
||
ToolbarGroup will pass all HTML props to the underlying element. | ||
|
||
## Related components | ||
|
||
* ToolbarGroup may contain [ToolbarButton](/packages/components/src/toolbar-button/README.md) and [ToolbarItem](/packages/components/src/toolbar-Item/README.md) as children. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# ToolbarItem | ||
|
||
A ToolbarItem is a generic headless component that can be used to make any custom component a [Toolbar](/packages/components/src/toolbar/README.md) item. It should be inside a [Toolbar](/packages/components/src/toolbar/README.md) or [ToolbarGroup](/packages/components/src/toolbar-group/README.md) when used to create general interfaces. If you're using it to add controls to your custom block, you should consider using [BlockControls](/docs/designers-developers/developers/tutorials/block-tutorial/block-controls-toolbar-and-sidebar.md). | ||
|
||
## Usage | ||
|
||
### `as` prop | ||
|
||
You can use the `as` prop with a custom component or any HTML element. | ||
|
||
```jsx | ||
import { Toolbar, ToolbarItem, Button } from '@wordpress/components'; | ||
|
||
function MyToolbar() { | ||
return ( | ||
<Toolbar label="Options"> | ||
<ToolbarItem as={ Button }>I am a toolbar button</ToolbarItem> | ||
<ToolbarItem as="button">I am another toolbar button</ToolbarItem> | ||
</Toolbar> | ||
); | ||
} | ||
``` | ||
|
||
### render prop | ||
|
||
You can pass children as function to get the ToolbarItem props and pass them to another component. | ||
|
||
```jsx | ||
import { Toolbar, ToolbarItem, DropdownMenu } from '@wordpress/components'; | ||
import { table } from '@wordpress/icons'; | ||
|
||
function MyToolbar() { | ||
return ( | ||
<Toolbar label="Options"> | ||
<ToolbarItem> | ||
{ ( toolbarItemHTMLProps ) => ( | ||
<DropdownMenu | ||
icon={ table } | ||
toggleProps={ toolbarItemHTMLProps } | ||
label={ 'Edit table' } | ||
controls={ [] } | ||
/> | ||
) } | ||
</ToolbarItem> | ||
</Toolbar> | ||
); | ||
} | ||
``` | ||
|
||
### 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, ToolbarItem, Button } from '@wordpress/components'; | ||
|
||
function Edit() { | ||
return ( | ||
<BlockControls> | ||
<ToolbarGroup> | ||
<ToolbarItem as={ Button }>I am a toolbar button</ToolbarItem> | ||
</ToolbarGroup> | ||
</BlockControls> | ||
); | ||
} | ||
``` | ||
|
||
## Related components | ||
|
||
* ToolbarItem should be used inside [Toolbar](/packages/components/src/toolbar/README.md) or [ToolbarGroup](/packages/components/src/toolbar-group/README.md). | ||
* If you want a simple toolbar button, consider using [ToolbarButton](/packages/components/src/toolbar-button/README.md) instead. |
Oops, something went wrong.