Skip to content

Commit

Permalink
Use nth-child notation instead of :has and sibling selector
Browse files Browse the repository at this point in the history
  • Loading branch information
ciampo committed Oct 11, 2023
1 parent ef3f040 commit 85f1db9
Showing 1 changed file with 4 additions and 17 deletions.
21 changes: 4 additions & 17 deletions packages/block-editor/src/components/colors-gradients/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -77,33 +77,20 @@ $swatch-gap: 12px;
border-right: 1px solid $gray-300;
border-bottom: 1px solid $gray-300;

// Identify the first instance as the item that is not a subsequent item to an
// item with the same class. The `~` selector is used instead of `+` to take
// into account any potential `ToolsPanelItem` placeholder item.
&:not(& ~ &) {
// 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;
}

// Identify the last instance as an item without any subsequent siblings
// with the same class. The `~` selector is used instead of `+` to take
// into account any potential `ToolsPanelItem` placeholder item.
&:not(:has(~ &)) {
// 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;
}

// Less accurate fallback to detect the last instance of this item
// for older browsers not yet supporting the `:has()` selector.
@supports not selector(:has(*)) {
&.last {
border-bottom-left-radius: $radius-block-ui;
border-bottom-right-radius: $radius-block-ui;
}
}

> div,
> div > button {
border-radius: inherit;
Expand Down

0 comments on commit 85f1db9

Please sign in to comment.