Skip to content

Commit 6fecbe2

Browse files
authored
Merge pull request #979 from primer/radio-group
Add `.radio-group` component
2 parents 9aa9f79 + a6a50de commit 6fecbe2

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed

docs/content/components/forms.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,23 @@ Content that is hidden by default should only be done so if it is non-essential
305305
</form>
306306
```
307307

308+
#### Radio group
309+
310+
Radio groups are tab like controls. Their blue border gives extra emphasis to what is selected.
311+
312+
```html live
313+
<form>
314+
<div class="radio-group">
315+
<input class="radio-input" id="option-a" type="radio" name="options">
316+
<label class="radio-label" for="option-a">Option A</label>
317+
<input class="radio-input" id="option-b" type="radio" name="options">
318+
<label class="radio-label" for="option-b">Option B</label>
319+
<input class="radio-input" id="option-c" type="radio" name="options">
320+
<label class="radio-label" for="option-c">Option C</label>
321+
</div>
322+
</form>
323+
```
324+
308325
#### Input group
309326

310327
Attached an input and button to one another.

src/forms/index.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
@import "./form-group.scss";
55
@import "./form-validation.scss";
66
@import "./input-group.scss";
7+
@import "./radio-group.scss";

src/forms/radio-group.scss

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Tab like radio group
2+
3+
.radio-group {
4+
@include clearfix;
5+
}
6+
7+
.radio-label {
8+
float: left;
9+
// stylelint-disable-next-line primer/spacing
10+
padding: 6px $spacer-3 6px ($spacer-3 + 12px + $spacer-2); // 12px is the size of the radio-input
11+
// stylelint-disable-next-line primer/spacing
12+
margin-left: -1px;
13+
font-size: $body-font-size;
14+
// stylelint-disable-next-line primer/typography
15+
line-height: 20px; // Specifically not inherit our `<body>` default
16+
color: $text-gray-dark;
17+
cursor: pointer;
18+
border: $border-width $border-style $border-gray-dark;
19+
20+
:checked + & {
21+
position: relative;
22+
z-index: 1;
23+
border-color: $border-blue;
24+
}
25+
26+
&:first-of-type {
27+
margin-left: 0;
28+
border-top-left-radius: $border-radius;
29+
border-bottom-left-radius: $border-radius;
30+
}
31+
32+
&:last-of-type {
33+
border-top-right-radius: $border-radius;
34+
border-bottom-right-radius: $border-radius;
35+
}
36+
}
37+
38+
.radio-input {
39+
z-index: 3;
40+
float: left;
41+
// stylelint-disable-next-line primer/spacing
42+
margin: 10px (-$spacer-5) 0 $spacer-3;
43+
}

0 commit comments

Comments
 (0)