Skip to content
This repository was archived by the owner on Sep 11, 2021. It is now read-only.

Commit 0158a7d

Browse files
committed
Document styling checkboxes/radios directly when IE11 support is not needed
1 parent ceca61b commit 0158a7d

File tree

2 files changed

+70
-6
lines changed

2 files changed

+70
-6
lines changed

pages/index.mdx

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,37 @@ impose any opinions in that regard. Here we've used flexbox to center the checkb
124124
</div>
125125
`}/>
126126

127+
### Styling checkboxes directly (No IE 11 support)
128+
129+
If you only need to support Edge and not IE 11, you can also add the `form-checkbox` class to
130+
`input[type=checkbox]` elements directly and avoid the extra presentational `span` element.
131+
132+
<CodeSample code={`
133+
<div class="block">
134+
<span class="text-gray-700">Checkboxes</span>
135+
<div class="mt-2">
136+
<div>
137+
<label class="inline-flex items-center">
138+
<input type="checkbox" class="form-checkbox text-gray-800" checked/>
139+
<span class="ml-2">Option 1</span>
140+
</label>
141+
</div>
142+
<div>
143+
<label class="inline-flex items-center">
144+
<input type="checkbox" class="form-checkbox text-gray-800"/>
145+
<span class="ml-2">Option 2</span>
146+
</label>
147+
</div>
148+
<div>
149+
<label class="inline-flex items-center">
150+
<input type="checkbox" class="form-checkbox text-gray-800"/>
151+
<span class="ml-2">Option 3</span>
152+
</label>
153+
</div>
154+
</div>
155+
</div>
156+
`}/>
157+
127158
### Changing the color
128159

129160
You can customize the background color of a checkbox when it's checked by using Tailwind's text
@@ -234,6 +265,37 @@ impose any opinions in that regard. Here we've used flexbox to center the radio
234265
</div>
235266
`}/>
236267

268+
### Styling radio buttons directly (No IE 11 support)
269+
270+
If you only need to support Edge and not IE 11, you can also add the `form-checkbox` class to
271+
`input[type=checkbox]` elements directly and avoid the extra presentational `span` element.
272+
273+
<CodeSample code={`
274+
<div class="block">
275+
<span class="text-gray-700">Radio Buttons</span>
276+
<div class="mt-2">
277+
<div>
278+
<label class="inline-flex items-center">
279+
<input type="radio" class="form-radio text-gray-800" name="radio" value="1" checked/>
280+
<span class="ml-2">Option 1</span>
281+
</label>
282+
</div>
283+
<div>
284+
<label class="inline-flex items-center">
285+
<input type="radio" class="form-radio text-gray-800" name="radio" value="2"/>
286+
<span class="ml-2">Option 2</span>
287+
</label>
288+
</div>
289+
<div>
290+
<label class="inline-flex items-center">
291+
<input type="radio" class="form-radio text-gray-800" name="radio" value="3"/>
292+
<span class="ml-2">Option 3</span>
293+
</label>
294+
</div>
295+
</div>
296+
</div>
297+
`}/>
298+
237299
### Changing the color
238300

239301
You can customize the background color of a radio button when it's checked by using Tailwind's text

tailwind.config.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ module.exports = {
2222

2323
addComponents({
2424
'.form-checkbox': {
25+
appearance: 'none',
2526
display: 'inline-block',
2627
height: theme('spacing.4', defaultTheme.spacing[4]),
2728
width: theme('spacing.4', defaultTheme.spacing[4]),
@@ -30,14 +31,14 @@ module.exports = {
3031
borderRadius: theme('borderRadius.default', defaultTheme.borderRadius.default),
3132
backgroundColor: '#fff',
3233
userSelect: 'none',
33-
'input[type=checkbox]:focus + &': {
34+
'input[type=checkbox]:focus + &, input[type=checkbox]&:focus': {
3435
outline: 'none',
3536
boxShadow: theme('boxShadow.outline', defaultTheme.boxShadow.outline),
3637
},
37-
'input[type=checkbox]:focus:not(:checked) + &': {
38+
'input[type=checkbox]:focus:not(:checked) + &, input[type=checkbox]&:focus:not(:checked)': {
3839
borderColor: defaultTheme.colors.blue[400],
3940
},
40-
'input[type=checkbox]:checked + &': {
41+
'input[type=checkbox]:checked + &, input[type=checkbox]&:checked': {
4142
backgroundColor: 'currentColor',
4243
borderColor: 'currentColor',
4344
backgroundImage: `url("data:image/svg+xml,%3Csvg viewBox='0 0 24 24' fill='%23ffffff' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M10.5 14.586l7.293-8.293a1 1 0 0 1 1.414 1.414l-8 9a1 1 0 0 1-1.414 0l-4-4a1 1 0 0 1 1.414-1.414l3.293 3.293z' fill-rule='evenodd'/%3E%3C/svg%3E")`,
@@ -47,6 +48,7 @@ module.exports = {
4748
},
4849
},
4950
'.form-radio': {
51+
appearance: 'none',
5052
display: 'inline-block',
5153
height: theme('spacing.4', defaultTheme.spacing[4]),
5254
width: theme('spacing.4', defaultTheme.spacing[4]),
@@ -55,14 +57,14 @@ module.exports = {
5557
borderRadius: '9999px',
5658
backgroundColor: '#fff',
5759
userSelect: 'none',
58-
'input[type=radio]:focus + &': {
60+
'input[type=radio]:focus + &, input[type=radio]&:focus': {
5961
outline: 'none',
6062
boxShadow: theme('boxShadow.outline', defaultTheme.boxShadow.outline),
6163
},
62-
'input[type=radio]:focus:not(:checked) + &': {
64+
'input[type=radio]:focus:not(:checked) + &, input[type=radio]&:focus:not(:checked)': {
6365
borderColor: defaultTheme.colors.blue[400],
6466
},
65-
'input[type=radio]:checked + &': {
67+
'input[type=radio]:checked + &, input[type=radio]&:checked': {
6668
backgroundColor: 'currentColor',
6769
borderColor: 'currentColor',
6870
backgroundImage: `url("data:image/svg+xml,%3Csvg viewBox='0 0 24 24' fill='%23ffffff' xmlns='http://www.w3.org/2000/svg'%3E%3Ccircle cx='12' cy='12' r='5'/%3E%3C/svg%3E")`,

0 commit comments

Comments
 (0)