Repository navigation
Block Inspector: Move Classnames, Additional CSS and Apply Globally to Styles 'Additional styles' panel #83753
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
talldan
wants to merge
6
commits into
trunk
Choose a base branch
from
try/split-advanced-panels
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+407
−96
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
13530ed
Block Inspector: Add an advanced-styles group for tab-aware Advanced …
talldan a4f5dea
try switching to a ToolsPanel for additional styles
talldan 8cec968
Revert "Ensure correct a11y text for a non-resettable hideable tools …
talldan 8fb8c22
Block Editor: Consolidate hook utility tests in TypeScript
talldan f129e89
Block Inspector: Keep Additional styles in the Styles tab
talldan 381435e
Block Editor: Remove stale test exclusion
talldan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
37 changes: 37 additions & 0 deletions
37
packages/block-editor/src/components/inspector-controls-tabs/additional-styles-panel.jsx
This file contains hidden or 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,37 @@ | ||
| import { | ||
| PanelBody, | ||
| __experimentalUseSlotFills as useSlotFills, | ||
| } from '@wordpress/components'; | ||
| import { __ } from '@wordpress/i18n'; | ||
| import { default as InspectorControls } from '../inspector-controls'; | ||
| import groups from '../inspector-controls/groups'; | ||
|
|
||
| /** | ||
| * Renders the "Additional styles" panel for the block inspector. | ||
| * | ||
| * The panel holds advanced styling controls such as Additional CSS, which live | ||
| * in the `additional-styles` group. It renders nothing when the group has no | ||
| * fills. | ||
| * | ||
| * @param {Object} props Component props. | ||
| * @param {boolean} [props.initialOpen] Whether the panel starts expanded. | ||
| */ | ||
| const AdditionalStyles = ( { initialOpen = false } ) => { | ||
| const fills = useSlotFills( groups[ 'additional-styles' ].name ); | ||
|
|
||
| if ( ! fills?.length ) { | ||
| return null; | ||
| } | ||
|
|
||
| return ( | ||
| <PanelBody | ||
| className="block-editor-block-inspector__additional-styles" | ||
| title={ __( 'Additional styles' ) } | ||
| initialOpen={ initialOpen } | ||
| > | ||
| <InspectorControls.Slot group="additional-styles" /> | ||
| </PanelBody> | ||
| ); | ||
| }; | ||
|
|
||
| export default AdditionalStyles; |
This file contains hidden or 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 hidden or 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 hidden or 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
113 changes: 113 additions & 0 deletions
113
...s/block-editor/src/components/inspector-controls-tabs/test/advanced-panels.jsdom.test.tsx
This file contains hidden or 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,113 @@ | ||
| import { describe, expect, it } from 'vitest'; | ||
| import { render, screen } from '@testing-library/react'; | ||
| import { SlotFillProvider } from '@wordpress/components'; | ||
| import AdvancedControls from '../advanced-controls-panel'; | ||
| import AdditionalStyles from '../additional-styles-panel'; | ||
| import groups from '../../inspector-controls/groups'; | ||
|
|
||
| // The `InspectorControls` fill component is bypassed in favour of the | ||
| // underlying group fills, so that the panels can be exercised without a | ||
| // selected block and its editing mode. | ||
| const AdvancedFill = groups.advanced.Fill; | ||
| const AdditionalStylesFill = groups[ 'additional-styles' ].Fill; | ||
|
|
||
| describe( 'AdvancedControls', () => { | ||
| it( 'renders nothing when the advanced group has no fills', () => { | ||
| render( | ||
| <SlotFillProvider> | ||
| <AdvancedControls initialOpen /> | ||
| </SlotFillProvider> | ||
| ); | ||
|
|
||
| expect( | ||
| screen.queryByRole( 'button', { name: 'Advanced' } ) | ||
| ).not.toBeInTheDocument(); | ||
| } ); | ||
|
|
||
| it( 'renders the advanced group fills', () => { | ||
| render( | ||
| <SlotFillProvider> | ||
| <AdvancedFill> | ||
| <span>HTML anchor</span> | ||
| </AdvancedFill> | ||
| <AdvancedControls initialOpen /> | ||
| </SlotFillProvider> | ||
| ); | ||
|
|
||
| expect( | ||
| screen.getByRole( 'button', { name: 'Advanced' } ) | ||
| ).toBeVisible(); | ||
| expect( screen.getByText( 'HTML anchor' ) ).toBeVisible(); | ||
| } ); | ||
|
|
||
| it( 'renders nothing when only the additional-styles group has fills', () => { | ||
| render( | ||
| <SlotFillProvider> | ||
| <AdditionalStylesFill> | ||
| <span>Additional CSS</span> | ||
| </AdditionalStylesFill> | ||
| <AdvancedControls initialOpen /> | ||
| </SlotFillProvider> | ||
| ); | ||
|
|
||
| expect( | ||
| screen.queryByRole( 'button', { name: 'Advanced' } ) | ||
| ).not.toBeInTheDocument(); | ||
| } ); | ||
| } ); | ||
|
|
||
| describe( 'AdditionalStyles', () => { | ||
| it( 'renders nothing when the additional-styles group has no fills', () => { | ||
| render( | ||
| <SlotFillProvider> | ||
| <AdditionalStyles initialOpen /> | ||
| </SlotFillProvider> | ||
| ); | ||
|
|
||
| expect( | ||
| screen.queryByRole( 'button', { name: 'Additional styles' } ) | ||
| ).not.toBeInTheDocument(); | ||
| } ); | ||
|
|
||
| it( 'renders the additional-styles group fills', () => { | ||
| render( | ||
| <SlotFillProvider> | ||
| <AdditionalStylesFill> | ||
| <span>Additional CSS</span> | ||
| </AdditionalStylesFill> | ||
| <AdditionalStyles initialOpen /> | ||
| </SlotFillProvider> | ||
| ); | ||
|
|
||
| expect( | ||
| screen.getByRole( 'button', { name: 'Additional styles' } ) | ||
| ).toBeVisible(); | ||
| expect( screen.getByText( 'Additional CSS' ) ).toBeVisible(); | ||
| } ); | ||
| } ); | ||
|
|
||
| describe( 'Advanced and Additional styles together', () => { | ||
| it( 'renders as two separate panels', () => { | ||
| render( | ||
| <SlotFillProvider> | ||
| <AdvancedFill> | ||
| <span>HTML anchor</span> | ||
| </AdvancedFill> | ||
| <AdditionalStylesFill> | ||
| <span>Additional CSS</span> | ||
| </AdditionalStylesFill> | ||
| <AdditionalStyles initialOpen /> | ||
| <AdvancedControls initialOpen /> | ||
| </SlotFillProvider> | ||
| ); | ||
|
|
||
| expect( | ||
| screen.getByRole( 'button', { name: 'Additional styles' } ) | ||
| ).toBeVisible(); | ||
| expect( | ||
| screen.getByRole( 'button', { name: 'Advanced' } ) | ||
| ).toBeVisible(); | ||
| expect( screen.getByText( 'Additional CSS' ) ).toBeVisible(); | ||
| expect( screen.getByText( 'HTML anchor' ) ).toBeVisible(); | ||
| } ); | ||
| } ); |
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -2,6 +2,9 @@ import { createSlotFill } from '@wordpress/components'; | |
|
|
||
| const InspectorControlsDefault = createSlotFill( 'InspectorControls' ); | ||
| const InspectorControlsAdvanced = createSlotFill( 'InspectorAdvancedControls' ); | ||
| const InspectorControlsAdditionalStyles = createSlotFill( | ||
| 'InspectorControlsAdditionalStyles' | ||
| ); | ||
| const InspectorControlsBindings = createSlotFill( 'InspectorControlsBindings' ); | ||
| const InspectorControlsBackground = createSlotFill( | ||
| 'InspectorControlsBackground' | ||
|
|
@@ -27,6 +30,7 @@ const InspectorControlsContent = createSlotFill( 'InspectorControlsContent' ); | |
| const groups = { | ||
| default: InspectorControlsDefault, | ||
| advanced: InspectorControlsAdvanced, | ||
| 'additional-styles': InspectorControlsAdditionalStyles, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we document Looks like the current docs still place custom CSS classes under Advanced and don't mention the new group. |
||
| background: InspectorControlsBackground, | ||
| bindings: InspectorControlsBindings, | ||
| border: InspectorControlsBorder, | ||
|
|
||
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.