Skip to content

Commit

Permalink
Disable border UI in Global Styles when skipping serialization of sup…
Browse files Browse the repository at this point in the history
…port
  • Loading branch information
aaronrobertshaw committed Jun 6, 2022
1 parent f641907 commit 22af3f5
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion packages/edit-site/src/components/global-styles/border-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* WordPress dependencies
*/
import { __experimentalBorderRadiusControl as BorderRadiusControl } from '@wordpress/block-editor';
import { getBlockType } from '@wordpress/blocks';
import {
__experimentalBorderBoxControl as BorderBoxControl,
__experimentalHasSplitBorders as hasSplitBorders,
Expand All @@ -23,14 +24,19 @@ import {
} from './hooks';

export function useHasBorderPanel( name ) {
// When block's skip serialization of borders it generally means they are
// being applied to inner elements of which there isn't a means within
// Global Styles to target. To avoid the appearance of styles being
// misapplied we disable the border panel UI in the Global Styles sidebar.
const disableUI = shouldSkipBorderSerialization( name );
const controls = [
useHasBorderColorControl( name ),
useHasBorderRadiusControl( name ),
useHasBorderStyleControl( name ),
useHasBorderWidthControl( name ),
];

return controls.some( Boolean );
return ! disableUI && controls.some( Boolean );
}

function useHasBorderColorControl( name ) {
Expand Down Expand Up @@ -65,6 +71,17 @@ function useHasBorderWidthControl( name ) {
);
}

function shouldSkipBorderSerialization( name ) {
const blockType = getBlockType( name );

if ( ! blockType ) {
return true;
}

return blockType?.supports?.__experimentalBorder
?.__experimentalSkipSerialization;
}

function applyFallbackStyle( border ) {
if ( ! border ) {
return border;
Expand Down

0 comments on commit 22af3f5

Please sign in to comment.