Skip to content
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

RadioControl: Fully encapsulate styles #57347

Merged
merged 2 commits into from Dec 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/components/CHANGELOG.md
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
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
@@ -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;
}