Skip to content

Commit

Permalink
Colors: Fix color button border radii (#55207)
Browse files Browse the repository at this point in the history
* Apply the classname prop to `ToolsPanelItem` only when it s not a placeholder

* Color Gradient panel: use new selctors to select first and last items

* Add fallback for browsers not yet supporting the `:has()` selector

* Use nth-child notation instead of :has and sibling selector

* CHANGELOG
  • Loading branch information
ciampo committed Oct 11, 2023
1 parent bd3ea87 commit 00d1226
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,16 @@ $swatch-gap: 12px;
border-right: 1px solid $gray-300;
border-bottom: 1px solid $gray-300;

&.first {
// Identify the first visible instance as placeholder items will not have this class.
&:nth-child(1 of &) {
margin-top: $grid-unit-30;
border-top-left-radius: $radius-block-ui;
border-top-right-radius: $radius-block-ui;
border-top: 1px solid $gray-300;
}

&.last {
// Identify the last visible instance as placeholder items will not have this class.
&:nth-last-child(1 of &) {
border-bottom-left-radius: $radius-block-ui;
border-bottom-right-radius: $radius-block-ui;
}
Expand Down
1 change: 1 addition & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Enhancements

- `Notice`: Remove margins from `Notice` component ([#54800](https://github.com/WordPress/gutenberg/pull/54800)).
- `ToolsPanel`: do not apply the `className` to prop to `ToolsPanelItem` components when rendered as placeholders ([#55207](https://github.com/WordPress/gutenberg/pull/55207)).
- `ColorPalette`/`ToggleGroupControl/ToggleGroupControlOptionBase`: add `type="button"` attribute to native `<button>`s ([#55125](https://github.com/WordPress/gutenberg/pull/55125)).

### Bug Fix
Expand Down
10 changes: 4 additions & 6 deletions packages/components/src/tools-panel/tools-panel-item/hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,18 +176,16 @@ export function useToolsPanelItem(

const cx = useCx();
const classes = useMemo( () => {
const placeholderStyle =
shouldRenderPlaceholder &&
! isShown &&
styles.ToolsPanelItemPlaceholder;
const shouldApplyPlaceholderStyles =
shouldRenderPlaceholder && ! isShown;
const firstItemStyle =
firstDisplayedItem === label && __experimentalFirstVisibleItemClass;
const lastItemStyle =
lastDisplayedItem === label && __experimentalLastVisibleItemClass;
return cx(
styles.ToolsPanelItem,
placeholderStyle,
className,
shouldApplyPlaceholderStyles && styles.ToolsPanelItemPlaceholder,
! shouldApplyPlaceholderStyles && className,
firstItemStyle,
lastItemStyle
);
Expand Down
3 changes: 3 additions & 0 deletions packages/components/src/tools-panel/tools-panel/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,5 +191,8 @@ A function to call when the `Reset all` menu option is selected. As an argument,
Advises the `ToolsPanel` that all of its `ToolsPanelItem` children should render
placeholder content (instead of `null`) when they are toggled off and hidden.

Note that placeholder items won't apply the `className` that would be
normally applied to a visible `ToolsPanelItem` via the `className` prop.

- Required: No
- Default: `false`
2 changes: 2 additions & 0 deletions packages/components/src/tools-panel/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ export type ToolsPanelProps = {
/**
* Advises the `ToolsPanel` that its child `ToolsPanelItem`s should render
* placeholder content instead of null when they are toggled off and hidden.
* Note that placeholder items won't apply the `className` that would be
* normally applied to a visible `ToolsPanelItem` via the `className` prop.
*
* @default false
*/
Expand Down

1 comment on commit 00d1226

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in 00d1226.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/6483519746
📝 Reported issues:

Please sign in to comment.