Skip to content

Commit 91197f6

Browse files
authored
fix: required radio elements displayed as invalid (#431)
* feat: added required example * feat: added relevant name * feat: displayed further example elements * chore: simplified the name declaration again * chore: wrong title * fix: only one radio is supposed to be checked * chore: corrected the pseudo patterns name * fix: corrected invalid styling regarding border width * fix: we need to use this future selector
1 parent c52a643 commit 91197f6

17 files changed

+77
-26
lines changed

helpers/unique-id.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/* eslint unicorn/prefer-module: 0, eqeqeq: 0 */
2+
module.exports = function (Handlebars) {
3+
Handlebars.registerHelper('unique-id', function () {
4+
const crypto = require('node:crypto');
5+
6+
return `id-${crypto.randomUUID()}`;
7+
});
8+
};
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
<input type="radio"
22
class="elm-radio {{ styleModifier }}"
3-
{{#if name}} name="{{ name }}"{{/if }}
3+
name="{{ name }}"
44
id="{{ id }}"
55
{{#if checked}} checked{{/if }}
66
{{#if disabled}} disabled{{/if }}
7-
value="{{ value }}"
7+
{{#if value}} value="{{ value }}"{{/if }}
88
{{#if describedbyid }} aria-describedby="{{ describedbyid }}"{{/if }}
9-
{{#if invalid}} aria-invalid="true"{{/if }}>
9+
{{#if invalid}} aria-invalid="true"{{/if }}
10+
{{#if required}} required{{/if}}>
1011
<label class="elm-label" for="{{ id }}">{{ label }}</label>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"label": "Radio",
3+
"id": "radio",
4+
"name": "radio"
5+
}

source/_patterns/01-elements/radio/_radio.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: Textarea
2+
title: Radio
33
state: complete
44
---
55

source/_patterns/01-elements/radio/radio.json

Lines changed: 0 additions & 4 deletions
This file was deleted.

source/_patterns/01-elements/radio/radio.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
border-width: to-em($pxValue: 6);
4040
}
4141
// * the invalid style using the :invalid pseudo class (and [aria-invalid="true"] equivalent, see #136 and #141)
42-
&:invalid,
42+
&:is(:user-invalid),
4343
&[aria-invalid="true"] {
4444
border-color: #c13e34;
4545
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{{#each radios }}
2+
{{> elements-radio disabled=../disabled invalid=../invalid required=../required id=(unique-id) name=../name }}<br>
3+
{{/each }}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "radio",
3+
"radios": [
4+
{
5+
"label": "Radio 01"
6+
},
7+
{
8+
"label": "Radio 02"
9+
},
10+
{
11+
"label": "Radio 03"
12+
}
13+
]
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "radioChecked",
3+
"radios": [
4+
{
5+
"checked": true
6+
},
7+
{
8+
"checked": false
9+
},
10+
{
11+
"checked": false
12+
}
13+
]
14+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"disabled": true,
3+
"name": "radioDisabledChecked",
4+
"radios": [
5+
{
6+
"checked": true
7+
},
8+
{
9+
"checked": false
10+
},
11+
{
12+
"checked": false
13+
}
14+
]
15+
}

0 commit comments

Comments
 (0)