@spectrum-web-components/radio 1.3.1-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.
Files changed (2) hide show
  1. package/README.md +59 -83
  2. package/package.json +6 -6
package/README.md CHANGED
@@ -1,8 +1,6 @@
1
- ## Description
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.
4
-
5
- `<sp-radio-group>` holds a list of `<sp-radio>` elements, and is responsible for deselecting radio buttons when a new one is selected, which in turn makes it responsible for keeping track of which one is selected. `<sp-radio>` is responsible for handling user interactions and for visually reflecting if it is the one that is checked or not.
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.
6
4
 
7
5
  ### Usage
8
6
 
@@ -10,34 +8,59 @@
10
8
  [![How big is this package in your project?](https://img.shields.io/bundlephobia/minzip/@spectrum-web-components/radio?style=for-the-badge)](https://bundlephobia.com/result?p=@spectrum-web-components/radio)
11
9
  [![Try it on webcomponents.dev](https://img.shields.io/badge/Try%20it%20on-webcomponents.dev-green?style=for-the-badge)](https://webcomponents.dev/edit/collection/fO75441E1Q5ZlI0e9pgq/vUinRWkhayMTAmr9AK9J/src/index.ts)
12
10
 
13
- ```
11
+ ```zsh
14
12
  yarn add @spectrum-web-components/radio
15
13
  ```
16
14
 
17
15
  Import the side effectful registration of `<sp-radio>` or `<sp-radio-group>` via:
18
16
 
19
- ```
17
+ ```js
20
18
  import '@spectrum-web-components/radio/sp-radio.js';
21
19
  import '@spectrum-web-components/radio/sp-radio-group.js';
22
20
  ```
23
21
 
24
22
  When looking to leverage the `Radio` or `RadioGroup` base classes as a type and/or for extension purposes, do so via:
25
23
 
24
+ ```js
25
+ import { Radio, RadioGroup } from '@spectrum-web-components/radio';
26
26
  ```
27
- import {
28
- Radio,
29
- RadioGroup
30
- } from '@spectrum-web-components/radio';
27
+
28
+ ### Anatomy
29
+
30
+ `<sp-radio-group>` holds a list of `<sp-radio>` elements, and is responsible for deselecting radio buttons when a new one is selected, which in turn makes it responsible for keeping track of which one is selected. `<sp-radio>` is responsible for handling user interactions and for visually reflecting if it is the one that is checked or not.
31
+
32
+ ```html
33
+ <sp-radio-group label="Choose an option" name="anatomy">
34
+ <sp-radio value="first">Option 1</sp-radio>
35
+ <sp-radio value="second">Option 2</sp-radio>
36
+ <sp-radio value="third">Option 3</sp-radio>
37
+ <sp-radio value="fourth">Option 4</sp-radio>
38
+ </sp-radio-group>
31
39
  ```
32
40
 
33
- ## Sizes
41
+ #### Label
42
+
43
+ The `<sp-radio>` elements are labelled with text in their default slot.
44
+
45
+ ```html
46
+ <sp-radio-group label="Choose an option" name="anatomy">
47
+ <sp-radio value="first">Option 1</sp-radio>
48
+ <sp-radio value="second">Option 2</sp-radio>
49
+ <sp-radio value="third">Option 3</sp-radio>
50
+ <sp-radio value="fourth">Option 4</sp-radio>
51
+ </sp-radio-group>
52
+ ```
53
+
54
+ ### Options
55
+
56
+ #### Sizes
34
57
 
35
58
  <sp-tabs selected="m" auto label="Size Attribute Options">
36
59
  <sp-tab value="s">Small</sp-tab>
37
60
  <sp-tab-panel value="s">
38
61
 
39
62
  ```html
40
- <sp-radio-group label="Small" selected="first" name="example">
63
+ <sp-radio-group label="Small" selected="first" name="small">
41
64
  <sp-radio value="first" size="s">Option 1</sp-radio>
42
65
  <sp-radio value="second" size="s">Option 2</sp-radio>
43
66
  <sp-radio value="third" size="s">Option 3</sp-radio>
@@ -50,7 +73,7 @@ import {
50
73
  <sp-tab-panel value="m">
51
74
 
52
75
  ```html
53
- <sp-radio-group label="Medium" selected="first" name="example">
76
+ <sp-radio-group label="Medium" selected="first" name="medium">
54
77
  <sp-radio value="first" size="m">Option 1</sp-radio>
55
78
  <sp-radio value="second" size="m">Option 2</sp-radio>
56
79
  <sp-radio value="third" size="m">Option 3</sp-radio>
@@ -63,7 +86,7 @@ import {
63
86
  <sp-tab-panel value="l">
64
87
 
65
88
  ```html
66
- <sp-radio-group label="Large" selected="first" name="example">
89
+ <sp-radio-group label="Large" selected="first" name="large">
67
90
  <sp-radio value="first" size="l">Option 1</sp-radio>
68
91
  <sp-radio value="second" size="l">Option 2</sp-radio>
69
92
  <sp-radio value="third" size="l">Option 3</sp-radio>
@@ -76,7 +99,7 @@ import {
76
99
  <sp-tab-panel value="xl">
77
100
 
78
101
  ```html
79
- <sp-radio-group label="Extra large" selected="first" name="example">
102
+ <sp-radio-group label="Extra large" selected="first" name="extra-large">
80
103
  <sp-radio value="first" size="xl">Option 1</sp-radio>
81
104
  <sp-radio value="second" size="xl">Option 2</sp-radio>
82
105
  <sp-radio value="third" size="xl">Option 3</sp-radio>
@@ -87,13 +110,17 @@ import {
87
110
  </sp-tab-panel>
88
111
  </sp-tabs>
89
112
 
90
- ### Standard radio buttons
113
+ #### Styles
91
114
 
92
115
  Standard radio buttons are the default style for radio buttons. They are optimal for application panels where all visual elements are monochrome in order to direct focus to the content.
93
116
 
94
- Invalid selections in radio groups are identified using the `negative-help-text` slot. Read more about using [help text](#help-text) below.
117
+ **Emphasized** radio buttons are a secondary style for radio buttons. The blue color provides a visual prominence that is optimal for forms, settings, etc. where the radio buttons need to be noticed.
118
+
119
+ <sp-tabs selected="standard" auto label="Style Options">
120
+ <sp-tab value="standard">Standard</sp-tab>
121
+ <sp-tab-panel value="standard">
95
122
 
96
- ```html-live
123
+ ```html
97
124
  <div style="display: flex; justify-content: space-between;">
98
125
  <div style="display: flex; flex-direction: column;">
99
126
  <sp-field-label for="example-1" size="l">
@@ -130,13 +157,11 @@ Invalid selections in radio groups are identified using the `negative-help-text`
130
157
  </div>
131
158
  ```
132
159
 
133
- ### Emphasized radio buttons
134
-
135
- Emphasized radio buttons are a secondary style for radio buttons. The blue color provides a visual prominence that is optimal for forms, settings, etc. where the radio buttons need to be noticed.
136
-
137
- Invalid selections in radio groups are identified using the `negative-help-text` slot. Read more about using [help text](#help-text) below.
160
+ </sp-tab-panel>
161
+ <sp-tab value="emphasized">Emphasized</sp-tab>
162
+ <sp-tab-panel value="emphasized">
138
163
 
139
- ```html-live
164
+ ```html
140
165
  <div style="display: flex; justify-content: space-between;">
141
166
  <div style="display: flex; flex-direction: column;">
142
167
  <sp-field-label for="example-a" size="l">
@@ -173,7 +198,12 @@ Invalid selections in radio groups are identified using the `negative-help-text`
173
198
  </div>
174
199
  ```
175
200
 
176
- ### Handling events
201
+ </sp-tab-panel>
202
+ </sp-tabs>
203
+
204
+ ### Behaviors
205
+
206
+ #### Handling events
177
207
 
178
208
  Event handlers for clicks and other user actions can be registered on an `<sp-radio>` similar to a standard `<input type="radio">` element.
179
209
 
@@ -183,64 +213,10 @@ Event handlers for clicks and other user actions can be registered on an `<sp-ra
183
213
  </sp-radio>
184
214
  ```
185
215
 
186
- ## Help text
187
-
188
- 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`.
189
-
190
- <sp-tabs selected="self" auto label="Help text usage in radio groups">
191
- <sp-tab value="self">Self managed</sp-tab>
192
- <sp-tab-panel value="self">
193
-
194
- ```html
195
- <sp-field-label for="self">
196
- What is your favorite ice cream flavor?
197
- </sp-field-label>
198
- <sp-radio-group
199
- id="self"
200
- onchange="
201
- this.invalid = this.selected === 'fourth';
202
- "
203
- >
204
- <sp-radio value="first">Vanilla</sp-radio>
205
- <sp-radio value="second">Chocolate</sp-radio>
206
- <sp-radio value="third">Strawberry</sp-radio>
207
- <sp-radio value="fourth">I don't like ice cream</sp-radio>
208
- <sp-help-text slot="help-text">Everyone likes ice cream.</sp-help-text>
209
- <sp-help-text slot="negative-help-text" icon>
210
- You can't not like ice cream.
211
- </sp-help-text>
212
- </sp-radio-group>
213
- ```
214
-
215
- </sp-tab-panel>
216
- <sp-tab value="above">Managed from above</sp-tab>
217
- <sp-tab-panel value="above">
218
-
219
- ```html
220
- <sp-field-label for="managed">
221
- What is your favorite ice cream flavor?
222
- </sp-field-label>
223
- <sp-radio-group
224
- id="managed"
225
- onchange="
226
- const helpText = this.querySelector(`[slot='help-text']`);
227
- const isInvalid = this.selected === 'fourth';
228
- helpText.icon = isInvalid;
229
- helpText.textContent = isInvalid ? 'You can\'t not like ice cream.' : 'Everyone likes ice cream.';
230
- helpText.variant = isInvalid ? 'negative' : 'neutral';
231
- "
232
- >
233
- <sp-radio value="first">Vanilla</sp-radio>
234
- <sp-radio value="second">Chocolate</sp-radio>
235
- <sp-radio value="third">Strawberry</sp-radio>
236
- <sp-radio value="fourth">I don't like ice cream</sp-radio>
237
- <sp-help-text slot="help-text">Everyone likes ice cream.</sp-help-text>
238
- </sp-radio-group>
239
- ```
216
+ ### Accessibility
240
217
 
241
- </sp-tab-panel>
242
- </sp-tabs>
218
+ Tabbing into a group of radio buttons places the focus on the first radio button selected. If none of the radio buttons are selected, the focus is set on the first one in the group. Space selects the radio button in focus (if not already selected). Using the arrow keys moves focus and selection to the previous or next radio button in the group (last becomes first, and first becomes last). The new radio button in focus gets selected even if the previous one was not.
243
219
 
244
- ## Accessibility
220
+ #### Provide a label
245
221
 
246
- Radio buttons are accessible by default, rendered in HTML using the `<input type="radio">` element. Tabbing into a group of radio buttons places the focus on the first radio button selected. If none of the radio buttons are selected, the focus is set on the first one in the group. Space selects the radio button in focus (if not already selected). Using the arrow keys moves focus and selection to the previous or next radio button in the group (last becomes first, and first becomes last). The new radio button in focus gets selected even if the previous one was not.
222
+ Radio groups and radio items should always have labels.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spectrum-web-components/radio",
3
- "version": "1.3.1-beta.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.3.1-beta.0",
70
- "@spectrum-web-components/field-group": "1.3.1-beta.0",
71
- "@spectrum-web-components/help-text": "1.3.1-beta.0",
72
- "@spectrum-web-components/reactive-controllers": "1.3.1-beta.0",
73
- "@spectrum-web-components/shared": "1.3.1-beta.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"