Skip to content

Commit 91db584

Browse files
author
Luke Bowerman
authored
Checkbox & Radio refactor & readOnly support (#796)
Improve Radio example Refactored `Checkbox` & `Radio` - invert styled component usage to preferred structure seen in other atomic form elements. - extracted sub-components into seperate files Added support for `readOnly` attribute to `Checkbox` & `Radio` - Corrected visual bugs with disabled states - Updated CHANGELOG - Update documentation Update CodeSandbox to show example with a white background to allow for better visibility of disabled states.
1 parent 3662d5a commit 91db584

File tree

17 files changed

+1571
-581
lines changed

17 files changed

+1571
-581
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
### Added
1111

1212
- `ActionList` documentation
13+
- `Checkbox` & `Radio` now support `readOnly` property
14+
15+
### Fixed
16+
17+
- `Checkbox` & `Radio` disabled states match design spec correctly now
1318
- `ComponentsProvider` now automatically loads `GlobalStyle` (also provides `globalStyle={false}` prop to disable this behavior)
1419

1520
### Changed

packages/components/src/Form/Fields/FieldCheckbox/__snapshots__/FieldCheckbox.test.tsx.snap

Lines changed: 39 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ exports[`A FieldCheckbox 1`] = `
55
position: relative;
66
width: 100%;
77
height: 100%;
8+
background: currentColor;
89
border: solid 1px #DEE1E5;
910
border-radius: 0.125rem;
10-
color: transparent;
11+
color: #FFFFFF;
1112
display: -webkit-box;
1213
display: -webkit-flex;
1314
display: -ms-flexbox;
@@ -23,42 +24,45 @@ exports[`A FieldCheckbox 1`] = `
2324
}
2425
2526
.c4 {
26-
position: relative;
27+
margin: 3px;
2728
display: inline-block;
28-
width: 1rem;
2929
height: 1rem;
30-
margin: 3px;
30+
position: relative;
31+
width: 1rem;
3132
vertical-align: middle;
3233
}
3334
34-
.c4 input[type='checkbox'] {
35+
.c4 input {
36+
height: 100%;
3537
opacity: 0;
3638
position: absolute;
3739
width: 100%;
38-
height: 100%;
3940
z-index: 1;
4041
}
4142
42-
.c4 .c5 {
43-
background: #FFFFFF;
44-
border-color: #DEE1E5;
43+
.c4 input:checked + .c5 {
44+
background-color: #6C43E0;
45+
border-color: #6C43E0;
46+
}
47+
48+
.c4 input:not(:checked) + .c5 {
4549
color: #FFFFFF;
4650
}
4751
48-
.c4 input[type='checkbox']:focus + .c5 {
52+
.c4 input:focus + .c5 {
4953
border-color: #9785F2;
5054
box-shadow: 0 0 0 2px #E8E5FF;
5155
outline: none;
5256
}
5357
54-
.c4 input[type='checkbox']:disabled {
55-
cursor: not-allowed;
58+
.c4 input:disabled + .c5 {
59+
background: transparent;
60+
border-color: #DEE1E5;
61+
color: #939BA5;
5662
}
5763
58-
.c4 input[type='checkbox']:disabled + .c5 {
59-
background: #F5F6F7;
60-
border-color: #DEE1E5;
61-
color: #F5F6F7;
64+
.c4 input:disabled:not(:checked) + .c5 {
65+
color: transparent;
6266
}
6367
6468
.c2 {
@@ -109,17 +113,14 @@ exports[`A FieldCheckbox 1`] = `
109113
className="c3 "
110114
>
111115
<div
112-
checked={false}
113116
className="c4 "
114117
>
115118
<input
116119
checked={false}
117-
className=""
118120
id="FieldCheckboxID"
119121
name="thumbsUp"
120122
onChange={[Function]}
121123
onClick={[Function]}
122-
role="checkbox"
123124
type="checkbox"
124125
/>
125126
<div
@@ -154,9 +155,10 @@ exports[`A FieldCheckbox with checked value 1`] = `
154155
position: relative;
155156
width: 100%;
156157
height: 100%;
158+
background: currentColor;
157159
border: solid 1px #DEE1E5;
158160
border-radius: 0.125rem;
159-
color: transparent;
161+
color: #FFFFFF;
160162
display: -webkit-box;
161163
display: -webkit-flex;
162164
display: -ms-flexbox;
@@ -171,61 +173,46 @@ exports[`A FieldCheckbox with checked value 1`] = `
171173
align-items: center;
172174
}
173175
174-
.c8 .c5 {
175-
background: #FFFFFF;
176-
border-color: #DEE1E5;
177-
color: #FFFFFF;
178-
}
179-
180-
.c8 input[type='checkbox']:focus + .c5 {
181-
border-color: #9785F2;
182-
box-shadow: 0 0 0 2px #E8E5FF;
183-
outline: none;
184-
}
185-
186-
.c8 input[type='checkbox']:disabled + .c5 {
187-
background: #F5F6F7;
188-
border-color: #DEE1E5;
189-
color: #F5F6F7;
190-
}
191-
192176
.c4 {
193-
position: relative;
177+
margin: 3px;
194178
display: inline-block;
195-
width: 1rem;
196179
height: 1rem;
197-
margin: 3px;
180+
position: relative;
181+
width: 1rem;
198182
vertical-align: middle;
199183
}
200184
201-
.c4 input[type='checkbox'] {
185+
.c4 input {
186+
height: 100%;
202187
opacity: 0;
203188
position: absolute;
204189
width: 100%;
205-
height: 100%;
206190
z-index: 1;
207191
}
208192
209-
.c4 .c5 {
210-
background: #6C43E0;
193+
.c4 input:checked + .c5 {
194+
background-color: #6C43E0;
211195
border-color: #6C43E0;
196+
}
197+
198+
.c4 input:not(:checked) + .c5 {
212199
color: #FFFFFF;
213200
}
214201
215-
.c4 input[type='checkbox']:focus + .c5 {
202+
.c4 input:focus + .c5 {
216203
border-color: #9785F2;
217204
box-shadow: 0 0 0 2px #E8E5FF;
218205
outline: none;
219206
}
220207
221-
.c4 input[type='checkbox']:disabled {
222-
cursor: not-allowed;
208+
.c4 input:disabled + .c5 {
209+
background: transparent;
210+
border-color: #DEE1E5;
211+
color: #939BA5;
223212
}
224213
225-
.c4 input[type='checkbox']:disabled + .c5 {
226-
background: #F5F6F7;
227-
border-color: #DEE1E5;
228-
color: #F5F6F7;
214+
.c4 input:disabled:not(:checked) + .c5 {
215+
color: transparent;
229216
}
230217
231218
.c2 {
@@ -276,17 +263,14 @@ exports[`A FieldCheckbox with checked value 1`] = `
276263
className="c3 "
277264
>
278265
<div
279-
checked={true}
280266
className="c4 "
281267
>
282268
<input
283269
checked={true}
284-
className=""
285270
id="FieldCheckboxID"
286271
name="thumbsUp"
287272
onChange={[Function]}
288273
onClick={[Function]}
289-
role="checkbox"
290274
type="checkbox"
291275
/>
292276
<div

0 commit comments

Comments
 (0)