@@ -41,6 +41,7 @@ export const API_1: Story = () => {
41
41
const [ disabled , setDisabled ] = useState ( false )
42
42
const [ error , setError ] = useState ( false )
43
43
const [ valid , setValid ] = useState ( false )
44
+ const [ native , setNative ] = useState ( false )
44
45
45
46
const rotate = rotateCheckedState ( setRequired )
46
47
@@ -67,6 +68,11 @@ export const API_1: Story = () => {
67
68
onCheckedChange = { setValid }
68
69
label = "Valid"
69
70
> </ Checkbox >
71
+ < Checkbox
72
+ checked = { native }
73
+ onCheckedChange = { setNative }
74
+ label = "Native"
75
+ > </ Checkbox >
70
76
</ Row >
71
77
72
78
< FormControl >
@@ -77,6 +83,7 @@ export const API_1: Story = () => {
77
83
error = { error }
78
84
valid = { valid }
79
85
disabled = { disabled }
86
+ native = { native }
80
87
required = { required === 'indeterminate' ? undefined : required }
81
88
/>
82
89
< FormControlHelp
@@ -199,11 +206,55 @@ export const Example: Story = () => {
199
206
)
200
207
}
201
208
209
+ /**
210
+ * The `native` prop can be added to allow the use of the native html `:invalid` and `:valid` pseudo-classes.
211
+ *
212
+ * This is not the default as can have negative user experience when required forms show initial error.
213
+ *
214
+ * This is useful for styling the inputs when using the native html validation attributes.
215
+ * The is added for checkbox, radio, and select inputs too but uses the :has selector which has limited support.
216
+ */
217
+ export const Native : Story = ( ) => {
218
+ return (
219
+ < Form onSubmit = { withFormData ( alert ) } >
220
+ < FormControl >
221
+ < Input
222
+ name = "email"
223
+ label = "Email"
224
+ type = "email"
225
+ placeholder = "hello@committed.io"
226
+ minLength = { 3 }
227
+ required
228
+ native
229
+ />
230
+ < FormControlHelp defaultText = "Input your email address" />
231
+ </ FormControl >
232
+ < FormControl >
233
+ < Input
234
+ name = "password"
235
+ type = "password"
236
+ label = "Password"
237
+ pattern = "^(?=.*[A-Za-z])(?=.*\d)(?=.*[@$!%*#?&])[A-Za-z\d@$!%*#?&]{8,}$"
238
+ required
239
+ native
240
+ title = "Password must have minimum eight characters, at least one letter, one number and one special character"
241
+ />
242
+ < FormControlHelp defaultText = "Input your password" />
243
+ </ FormControl >
244
+ < FormButton />
245
+ </ Form >
246
+ )
247
+ }
248
+
249
+ /**
250
+ * Behavioural test/demo. Use the checkboxes to add these properties to all form elements.
251
+ */
202
252
export const Controls : Story = ( ) => {
203
253
const [ required , setRequired ] = useState < CheckedState > ( 'indeterminate' )
204
254
const [ disabled , setDisabled ] = useState ( false )
205
255
const [ error , setError ] = useState ( false )
206
256
const [ valid , setValid ] = useState ( false )
257
+ const [ native , setNative ] = useState ( false )
207
258
208
259
const rotate = rotateCheckedState ( setRequired )
209
260
@@ -212,6 +263,7 @@ export const Controls: Story = () => {
212
263
valid,
213
264
disabled,
214
265
required : required === 'indeterminate' ? undefined : required ,
266
+ native,
215
267
}
216
268
217
269
return (
@@ -237,6 +289,11 @@ export const Controls: Story = () => {
237
289
onCheckedChange = { setValid }
238
290
label = "Valid"
239
291
> </ Checkbox >
292
+ < Checkbox
293
+ checked = { native }
294
+ onCheckedChange = { setNative }
295
+ label = "Native"
296
+ > </ Checkbox >
240
297
</ Row >
241
298
242
299
< Form onSubmit = { withFormData ( alert ) } >
@@ -309,11 +366,15 @@ export const Controls: Story = () => {
309
366
)
310
367
}
311
368
369
+ /**
370
+ * Behavioural test/demo with ids, to ensure elements are correctly referenced in aria. Use the checkboxes to add these properties to all form elements.
371
+ */
312
372
export const WithIds : Story = ( ) => {
313
373
const [ required , setRequired ] = useState < CheckedState > ( 'indeterminate' )
314
374
const [ disabled , setDisabled ] = useState ( false )
315
375
const [ error , setError ] = useState ( false )
316
376
const [ valid , setValid ] = useState ( false )
377
+ const [ native , setNative ] = useState ( false )
317
378
318
379
const rotate = rotateCheckedState ( setRequired )
319
380
@@ -322,6 +383,7 @@ export const WithIds: Story = () => {
322
383
valid,
323
384
disabled,
324
385
required : required === 'indeterminate' ? undefined : required ,
386
+ native,
325
387
}
326
388
327
389
return (
@@ -347,6 +409,11 @@ export const WithIds: Story = () => {
347
409
onCheckedChange = { setValid }
348
410
label = "Valid"
349
411
> </ Checkbox >
412
+ < Checkbox
413
+ checked = { native }
414
+ onCheckedChange = { setNative }
415
+ label = "Native"
416
+ > </ Checkbox >
350
417
</ Row >
351
418
352
419
< Form onSubmit = { withFormData ( alert ) } >
0 commit comments