Skip to content

Commit

Permalink
RadioControl: Fully encapsulate styles (WordPress#57347)
Browse files Browse the repository at this point in the history
* RadioControl: Fully encapsulate styles

* Update changelog
  • Loading branch information
mirka authored Dec 25, 2023
1 parent 3c7e4ce commit ed68c36
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
1 change: 1 addition & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
- `Snackbar`: Remove erroneous `__unstableHTML` prop from TypeScript definitions ([#57218](https://github.com/WordPress/gutenberg/pull/57218)).
- `Truncate`: improve handling of non-string `children` ([#57261](https://github.com/WordPress/gutenberg/pull/57261)).
- `PaletteEdit`: Don't discard colors with default name and slug ([#54332](https://github.com/WordPress/gutenberg/pull/54332)).
- `RadioControl`: Fully encapsulate styles ([#57347](https://github.com/WordPress/gutenberg/pull/57347)).

### Enhancements

Expand Down
5 changes: 4 additions & 1 deletion packages/components/src/radio-control/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,10 @@ export function RadioControl(
}
{ ...additionalProps }
/>
<label htmlFor={ `${ id }-${ index }` }>
<label
className="components-radio-control__label"
htmlFor={ `${ id }-${ index }` }
>
{ option.label }
</label>
</div>
Expand Down
31 changes: 29 additions & 2 deletions packages/components/src/radio-control/style.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,32 @@
.components-radio-control__option {
display: flex;
align-items: center;
}

.components-radio-control__input[type="radio"] {
@include radio-control;
margin-top: 0;
margin-right: 6px;

display: inline-flex;
margin: 0 6px 0 0;
padding: 0;
appearance: none;
cursor: pointer;

&:focus {
box-shadow: 0 0 0 ($border-width * 2) $components-color-background, 0 0 0 ($border-width * 2 + $border-width-focus-fallback) $components-color-accent;
}

&:checked {
background: $components-color-accent;
border-color: $components-color-accent;

&::before {
content: "";
border-radius: 50%;
}
}
}

.components-radio-control__label {
cursor: pointer;
}

0 comments on commit ed68c36

Please sign in to comment.