@spectrum-web-components/radio 1.4.0-beta.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -113
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
## Overview
|
|
2
2
|
|
|
3
|
-
`<sp-radio>` and `<sp-radio-group>` allow users to select a single option from a list of mutually exclusive options. All possible options are exposed up front for users to compare.
|
|
3
|
+
`<sp-radio>` and [`<sp-radio-group>`](../radio-group) allow users to select a single option from a list of mutually exclusive options. All possible options are exposed up front for users to compare.
|
|
4
4
|
|
|
5
5
|
### Usage
|
|
6
6
|
|
|
@@ -8,24 +8,21 @@
|
|
|
8
8
|
[](https://bundlephobia.com/result?p=@spectrum-web-components/radio)
|
|
9
9
|
[](https://webcomponents.dev/edit/collection/fO75441E1Q5ZlI0e9pgq/vUinRWkhayMTAmr9AK9J/src/index.ts)
|
|
10
10
|
|
|
11
|
-
```
|
|
11
|
+
```zsh
|
|
12
12
|
yarn add @spectrum-web-components/radio
|
|
13
13
|
```
|
|
14
14
|
|
|
15
15
|
Import the side effectful registration of `<sp-radio>` or `<sp-radio-group>` via:
|
|
16
16
|
|
|
17
|
-
```
|
|
17
|
+
```js
|
|
18
18
|
import '@spectrum-web-components/radio/sp-radio.js';
|
|
19
19
|
import '@spectrum-web-components/radio/sp-radio-group.js';
|
|
20
20
|
```
|
|
21
21
|
|
|
22
22
|
When looking to leverage the `Radio` or `RadioGroup` base classes as a type and/or for extension purposes, do so via:
|
|
23
23
|
|
|
24
|
-
```
|
|
25
|
-
import {
|
|
26
|
-
Radio,
|
|
27
|
-
RadioGroup
|
|
28
|
-
} from '@spectrum-web-components/radio';
|
|
24
|
+
```js
|
|
25
|
+
import { Radio, RadioGroup } from '@spectrum-web-components/radio';
|
|
29
26
|
```
|
|
30
27
|
|
|
31
28
|
### Anatomy
|
|
@@ -45,12 +42,6 @@ import {
|
|
|
45
42
|
|
|
46
43
|
The `<sp-radio>` elements are labelled with text in their default slot.
|
|
47
44
|
|
|
48
|
-
The `<sp-radio-group>` element can be labeled with the `label` property or with an <`sp-field-label>` element:
|
|
49
|
-
|
|
50
|
-
<sp-tabs selected="property" auto label="Label Anatomy">
|
|
51
|
-
<sp-tab value="property">`label` property</sp-tab>
|
|
52
|
-
<sp-tab-panel value="self">
|
|
53
|
-
|
|
54
45
|
```html
|
|
55
46
|
<sp-radio-group label="Choose an option" name="anatomy">
|
|
56
47
|
<sp-radio value="first">Option 1</sp-radio>
|
|
@@ -60,97 +51,6 @@ The `<sp-radio-group>` element can be labeled with the `label` property or with
|
|
|
60
51
|
</sp-radio-group>
|
|
61
52
|
```
|
|
62
53
|
|
|
63
|
-
</sp-tab-panel>
|
|
64
|
-
<sp-tab value="sp-field-label">Using a field bale</sp-tab>
|
|
65
|
-
<sp-tab-panel value="above">
|
|
66
|
-
|
|
67
|
-
```html
|
|
68
|
-
<sp-field-label for="options">Choose an option</sp-field-label>
|
|
69
|
-
<sp-radio-group id="options" name="anatomy">
|
|
70
|
-
<sp-radio value="first">Option 1</sp-radio>
|
|
71
|
-
<sp-radio value="second">Option 2</sp-radio>
|
|
72
|
-
<sp-radio value="third">Option 3</sp-radio>
|
|
73
|
-
<sp-radio value="fourth">Option 4</sp-radio>
|
|
74
|
-
</sp-radio-group>
|
|
75
|
-
```
|
|
76
|
-
|
|
77
|
-
</sp-tab-panel>
|
|
78
|
-
<sp-tab value="sp-field-label">Using a field bale</sp-tab>
|
|
79
|
-
<sp-tab-panel value="above">
|
|
80
|
-
|
|
81
|
-
```html
|
|
82
|
-
<sp-field-label for="options">Choose an option</sp-field-label>
|
|
83
|
-
<sp-radio-group id="options" name="anatomy">
|
|
84
|
-
<sp-radio value="first">Option 1</sp-radio>
|
|
85
|
-
<sp-radio value="second">Option 2</sp-radio>
|
|
86
|
-
<sp-radio value="third">Option 3</sp-radio>
|
|
87
|
-
<sp-radio value="fourth">Option 4</sp-radio>
|
|
88
|
-
</sp-radio-group>
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
</sp-tab-panel>
|
|
92
|
-
</sp-tabs>
|
|
93
|
-
|
|
94
|
-
#### Help Text
|
|
95
|
-
|
|
96
|
-
Help text can be accessibly associated with an `<sp-radio-group>` element by using the `help-text` or `negative-help-text` slots. When using the `negative-help-text` slot, `<sp-radio-group>` will self manage the presence of this content based on the value of the `invalid` property on your `<sp-radio-group>` element. Content within the `help-text` slot will be show by default. When your `<sp-radio-group>` should receive help text based on state outside of the complexity of `invalid` or not, manage the content addressed to the `help-text` from above to ensure that it displays the right messaging and possesses the right `variant`.
|
|
97
|
-
|
|
98
|
-
Read more about using [help text](../help-text).
|
|
99
|
-
|
|
100
|
-
<sp-tabs selected="self" auto label="Help text usage in radio groups">
|
|
101
|
-
<sp-tab value="self">Self managed</sp-tab>
|
|
102
|
-
<sp-tab-panel value="self">
|
|
103
|
-
|
|
104
|
-
```html
|
|
105
|
-
<sp-field-label for="self">
|
|
106
|
-
What is your favorite ice cream flavor?
|
|
107
|
-
</sp-field-label>
|
|
108
|
-
<sp-radio-group
|
|
109
|
-
id="self"
|
|
110
|
-
onchange="
|
|
111
|
-
this.invalid = this.selected === 'fourth';
|
|
112
|
-
"
|
|
113
|
-
>
|
|
114
|
-
<sp-radio value="first">Vanilla</sp-radio>
|
|
115
|
-
<sp-radio value="second">Chocolate</sp-radio>
|
|
116
|
-
<sp-radio value="third">Strawberry</sp-radio>
|
|
117
|
-
<sp-radio value="fourth">I don't like ice cream</sp-radio>
|
|
118
|
-
<sp-help-text slot="help-text">Everyone likes ice cream.</sp-help-text>
|
|
119
|
-
<sp-help-text slot="negative-help-text" icon>
|
|
120
|
-
You can't not like ice cream.
|
|
121
|
-
</sp-help-text>
|
|
122
|
-
</sp-radio-group>
|
|
123
|
-
```
|
|
124
|
-
|
|
125
|
-
</sp-tab-panel>
|
|
126
|
-
<sp-tab value="above">Managed from above</sp-tab>
|
|
127
|
-
<sp-tab-panel value="above">
|
|
128
|
-
|
|
129
|
-
```html
|
|
130
|
-
<sp-field-label for="managed">
|
|
131
|
-
What is your favorite ice cream flavor?
|
|
132
|
-
</sp-field-label>
|
|
133
|
-
<sp-radio-group
|
|
134
|
-
id="managed"
|
|
135
|
-
onchange="
|
|
136
|
-
const helpText = this.querySelector(`[slot='help-text']`);
|
|
137
|
-
const isInvalid = this.selected === 'fourth';
|
|
138
|
-
helpText.icon = isInvalid;
|
|
139
|
-
helpText.textContent = isInvalid ? 'You can\'t not like ice cream.' : 'Everyone likes ice cream.';
|
|
140
|
-
helpText.variant = isInvalid ? 'negative' : 'neutral';
|
|
141
|
-
"
|
|
142
|
-
>
|
|
143
|
-
<sp-radio value="first">Vanilla</sp-radio>
|
|
144
|
-
<sp-radio value="second">Chocolate</sp-radio>
|
|
145
|
-
<sp-radio value="third">Strawberry</sp-radio>
|
|
146
|
-
<sp-radio value="fourth">I don't like ice cream</sp-radio>
|
|
147
|
-
<sp-help-text slot="help-text">Everyone likes ice cream.</sp-help-text>
|
|
148
|
-
</sp-radio-group>
|
|
149
|
-
```
|
|
150
|
-
|
|
151
|
-
</sp-tab-panel>
|
|
152
|
-
</sp-tabs>
|
|
153
|
-
|
|
154
54
|
### Options
|
|
155
55
|
|
|
156
56
|
#### Sizes
|
|
@@ -320,11 +220,3 @@ Tabbing into a group of radio buttons places the focus on the first radio button
|
|
|
320
220
|
#### Provide a label
|
|
321
221
|
|
|
322
222
|
Radio groups and radio items should always have labels.
|
|
323
|
-
|
|
324
|
-
#### Provide help text in the correct location
|
|
325
|
-
|
|
326
|
-
Radio groups should use help text for error messaging and descriptions. Descriptions are valuable for giving context behind why a selection is required, or for clarifying the options.
|
|
327
|
-
|
|
328
|
-
It is [not currently possible](https://w3c.github.io/webcomponents-cg/#cross-root-aria) to provide accessible ARIA references between elements in different shadow roots. To ensure proper association between elements, help text must be included via the `slot="help-text"` or `slot="help-text-negative"`.
|
|
329
|
-
|
|
330
|
-
See [help text](../help-text) for more information.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spectrum-web-components/radio",
|
|
3
|
-
"version": "1.4.0
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -66,11 +66,11 @@
|
|
|
66
66
|
"lit-html"
|
|
67
67
|
],
|
|
68
68
|
"dependencies": {
|
|
69
|
-
"@spectrum-web-components/base": "1.4.0
|
|
70
|
-
"@spectrum-web-components/field-group": "1.4.0
|
|
71
|
-
"@spectrum-web-components/help-text": "1.4.0
|
|
72
|
-
"@spectrum-web-components/reactive-controllers": "1.4.0
|
|
73
|
-
"@spectrum-web-components/shared": "1.4.0
|
|
69
|
+
"@spectrum-web-components/base": "1.4.0",
|
|
70
|
+
"@spectrum-web-components/field-group": "1.4.0",
|
|
71
|
+
"@spectrum-web-components/help-text": "1.4.0",
|
|
72
|
+
"@spectrum-web-components/reactive-controllers": "1.4.0",
|
|
73
|
+
"@spectrum-web-components/shared": "1.4.0"
|
|
74
74
|
},
|
|
75
75
|
"devDependencies": {
|
|
76
76
|
"@spectrum-css/radio": "10.0.0-s2-foundations.17"
|