@kubex/zinc 1.0.25 → 1.0.99
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/.claude/project.md +556 -0
- package/.github/workflows/js_build_and_deploy.yaml +9 -10
- package/dist/custom-elements.json +13575 -8856
- package/dist/vscode.html-custom-data.json +583 -48
- package/dist/web-types.json +1441 -181
- package/dist/zn.d.ts +1645 -660
- package/dist/zn.min.css +1 -1
- package/dist/zn.min.js +1412 -893
- package/docs/_utilities/code-previews.cjs +10 -1
- package/docs/assets/scripts/docs.js +42 -18
- package/docs/data/data-table.json +229 -66
- package/docs/data/empty.json +6 -0
- package/docs/data/products-table.json +41 -193
- package/docs/pages/components/action-bar.md +121 -6
- package/docs/pages/components/alert.md +118 -15
- package/docs/pages/components/animated-button.md +299 -0
- package/docs/pages/components/audio-select.md +534 -0
- package/docs/pages/components/bulk-actions.md +79 -5
- package/docs/pages/components/button-group.md +235 -27
- package/docs/pages/components/button.md +139 -1
- package/docs/pages/components/chart.md +365 -9
- package/docs/pages/components/checkbox.md +387 -58
- package/docs/pages/components/chip.md +253 -33
- package/docs/pages/components/collapsible.md +393 -46
- package/docs/pages/components/cols.md +152 -30
- package/docs/pages/components/confirm.md +182 -16
- package/docs/pages/components/copy-button.md +169 -6
- package/docs/pages/components/data-select.md +194 -15
- package/docs/pages/components/data-table-filter.md +96 -5
- package/docs/pages/components/data-table-search.md +451 -0
- package/docs/pages/components/data-table-sort.md +66 -5
- package/docs/pages/components/data-table.md +727 -66
- package/docs/pages/components/datepicker.md +402 -7
- package/docs/pages/components/defined-label.md +120 -5
- package/docs/pages/components/dialog.md +339 -59
- package/docs/pages/components/dropdown.md +366 -11
- package/docs/pages/components/editor.md +604 -7
- package/docs/pages/components/empty-state.md +315 -16
- package/docs/pages/components/expanding-action.md +212 -28
- package/docs/pages/components/file.md +421 -12
- package/docs/pages/components/filter-container.md +158 -5
- package/docs/pages/components/filter-wrapper.md +167 -6
- package/docs/pages/components/form-group.md +383 -6
- package/docs/pages/components/hover-container.md +237 -6
- package/docs/pages/components/icon-picker.md +121 -0
- package/docs/pages/components/icon.md +454 -48
- package/docs/pages/components/inline-edit.md +787 -19
- package/docs/pages/components/input-group.md +207 -13
- package/docs/pages/components/input.md +194 -0
- package/docs/pages/components/item.md +18 -0
- package/docs/pages/components/key-container.md +115 -0
- package/docs/pages/components/key.md +101 -0
- package/docs/pages/components/menu.md +512 -6
- package/docs/pages/components/note.md +239 -36
- package/docs/pages/components/opt-group.md +107 -0
- package/docs/pages/components/pagination.md +332 -6
- package/docs/pages/components/pane.md +222 -6
- package/docs/pages/components/panel.md +213 -26
- package/docs/pages/components/popup.md +1354 -6
- package/docs/pages/components/priority-list.md +233 -0
- package/docs/pages/components/progress-bar.md +387 -6
- package/docs/pages/components/radio-group.md +242 -5
- package/docs/pages/components/radio.md +474 -6
- package/docs/pages/components/rating.md +331 -7
- package/docs/pages/components/reveal.md +524 -6
- package/docs/pages/components/scroll-container.md +552 -6
- package/docs/pages/components/select.md +762 -160
- package/docs/pages/components/skeleton.md +473 -30
- package/docs/pages/components/slideout.md +261 -5
- package/docs/pages/components/sp.md +99 -41
- package/docs/pages/components/split-button.md +347 -9
- package/docs/pages/components/split-pane.md +445 -6
- package/docs/pages/components/stat.md +549 -9
- package/docs/pages/components/status-indicator.md +230 -1
- package/docs/pages/components/stepper.md +563 -6
- package/docs/pages/components/tabs.md +439 -13
- package/docs/pages/components/textarea.md +415 -17
- package/docs/pages/components/tile.md +385 -26
- package/docs/pages/components/toggle.md +424 -6
- package/docs/pages/components/tooltip.md +367 -0
- package/docs/pages/components/translation-group.md +210 -0
- package/docs/pages/components/translations.md +319 -19
- package/docs/pages/components/vertical-stepper.md +401 -8
- package/docs/pages/components/well.md +300 -3
- package/docs/pages/getting-started/form-controls.md +162 -0
- package/docs/pages/index.md +116 -15
- package/package.json +5 -6
- package/scss/_global-spacing.scss +4 -0
- package/scss/_root.scss +2 -2
- package/scss/boot.scss +19 -0
- package/scss/shared/layout.scss +5 -0
- package/scss/themes/_light.scss +3 -3
- package/src/components/alert/alert.scss +1 -0
- package/src/components/animated-button/README.md +306 -0
- package/src/components/animated-button/animated-button.component.ts +229 -0
- package/src/components/animated-button/animated-button.scss +228 -0
- package/src/components/animated-button/animated-button.test.ts +143 -0
- package/src/components/animated-button/index.ts +12 -0
- package/src/components/button/button.component.ts +5 -0
- package/src/components/button-group/button-group.component.ts +25 -13
- package/src/components/button-group/button-group.scss +6 -0
- package/src/components/checkbox/checkbox.component.ts +4 -0
- package/src/components/checkbox/checkbox.scss +7 -4
- package/src/components/checkbox-group/checkbox-group.scss +7 -0
- package/src/components/chip/chip.component.ts +7 -2
- package/src/components/chip/chip.scss +16 -2
- package/src/components/collapsible/collapsible.component.ts +27 -20
- package/src/components/cols/cols.component.ts +14 -2
- package/src/components/cols/cols.scss +6 -12
- package/src/components/confirm/confirm.component.ts +7 -0
- package/src/components/copy-button/copy-button.component.ts +12 -11
- package/src/components/data-select/data-select.component.ts +215 -44
- package/src/components/data-select/data-select.scss +66 -6
- package/src/components/data-select/providers/currency-data-provider.ts +20 -6
- package/src/components/data-select/providers/provider.ts +1 -0
- package/src/components/data-select/providers/us-state-data-provider.ts +68 -0
- package/src/components/data-table/data-table.component.ts +81 -22
- package/src/components/data-table-search/data-table-search.component.ts +184 -0
- package/src/components/data-table-search/data-table-search.scss +17 -0
- package/src/components/data-table-search/data-table-search.test.ts +11 -0
- package/src/components/data-table-search/index.ts +12 -0
- package/src/components/datepicker/datepicker.component.ts +347 -13
- package/src/components/dialog/dialog.component.ts +1 -1
- package/src/components/empty-state/empty-state.scss +6 -1
- package/src/components/header/header.scss +3 -3
- package/src/components/icon/icon.component.ts +23 -1
- package/src/components/icon/icon.scss +23 -0
- package/src/components/icon-picker/brand-icons.ts +24 -0
- package/src/components/icon-picker/icon-picker.component.ts +407 -0
- package/src/components/icon-picker/icon-picker.scss +205 -0
- package/src/components/icon-picker/index.ts +12 -0
- package/src/components/icon-picker/line-icons.ts +612 -0
- package/src/components/icon-picker/material-icons.ts +14543 -0
- package/src/components/inline-edit/inline-edit.component.ts +190 -46
- package/src/components/inline-edit/inline-edit.scss +29 -0
- package/src/components/inline-edit/inline-edit.test.ts +314 -1
- package/src/components/input/input.component.ts +324 -5
- package/src/components/input/input.scss +87 -0
- package/src/components/input-group/input-group.component.ts +28 -7
- package/src/components/input-group/input-group.scss +48 -10
- package/src/components/item/item.component.ts +24 -3
- package/src/components/item/item.scss +18 -0
- package/src/components/key/index.ts +12 -0
- package/src/components/key/key.component.ts +47 -0
- package/src/components/key/key.scss +38 -0
- package/src/components/key-container/index.ts +12 -0
- package/src/components/key-container/key-container.component.ts +142 -0
- package/src/components/key-container/key-container.scss +33 -0
- package/src/components/menu-item/menu-item.component.ts +20 -0
- package/src/components/menu-item/menu-item.scss +69 -2
- package/src/components/navbar/navbar.component.ts +103 -11
- package/src/components/navbar/navbar.scss +6 -1
- package/src/components/opt-group/index.ts +12 -0
- package/src/components/opt-group/opt-group.component.ts +74 -0
- package/src/components/opt-group/opt-group.scss +37 -0
- package/src/components/opt-group/opt-group.test.ts +27 -0
- package/src/components/option/option.component.ts +1 -16
- package/src/components/option/option.scss +4 -0
- package/src/components/panel/panel.component.ts +10 -8
- package/src/components/panel/panel.scss +20 -0
- package/src/components/priority-list/index.ts +12 -0
- package/src/components/priority-list/priority-list.component.ts +611 -0
- package/src/components/priority-list/priority-list.scss +185 -0
- package/src/components/priority-list/priority-list.test.ts +139 -0
- package/src/components/progress-bar/progress-bar.component.ts +22 -16
- package/src/components/radio/radio.scss +10 -3
- package/src/components/select/select.component.ts +812 -72
- package/src/components/select/select.scss +108 -2
- package/src/components/select/select.test.ts +147 -2
- package/src/components/settings-container/settings-container.component.ts +44 -19
- package/src/components/settings-container/settings-container.scss +1 -1
- package/src/components/skeleton/skeleton.component.ts +6 -1
- package/src/components/slideout/slideout.scss +8 -3
- package/src/components/sp/sp.component.ts +3 -1
- package/src/components/sp/sp.scss +19 -0
- package/src/components/stepper/stepper.component.ts +16 -10
- package/src/components/textarea/textarea.scss +0 -4
- package/src/components/tile/tile.component.ts +12 -3
- package/src/components/tile/tile.scss +1 -1
- package/src/components/timer/timer.component.ts +15 -2
- package/src/components/toggle/toggle.component.ts +29 -26
- package/src/components/toggle/toggle.scss +13 -1
- package/src/components/translation-group/index.ts +12 -0
- package/src/components/translation-group/translation-group.component.ts +207 -0
- package/src/components/translation-group/translation-group.scss +8 -0
- package/src/components/translations/translations.component.ts +90 -44
- package/src/components/translations/translations.scss +4 -0
- package/src/components/vertical-stepper/vertical-stepper.component.ts +14 -9
- package/src/events/events.ts +12 -7
- package/src/events/zn-language-change.ts +7 -0
- package/src/events/zn-purchase.ts +11 -0
- package/src/events/zn-redirect.ts +7 -0
- package/src/events/zn-reorder.ts +7 -0
- package/src/events/zn-search-change.ts +11 -0
- package/src/events/zn-submit.ts +1 -1
- package/src/form-control.scss +4 -0
- package/src/internal/form-navigation.ts +510 -0
- package/src/internal/form.ts +6 -0
- package/src/zinc.ts +91 -83
|
@@ -1,23 +1,27 @@
|
|
|
1
1
|
---
|
|
2
2
|
meta:
|
|
3
3
|
title: Radio Group
|
|
4
|
-
description:
|
|
4
|
+
description: Radio groups are used to group multiple radios so they function as a single form control.
|
|
5
5
|
layout: component
|
|
6
6
|
---
|
|
7
7
|
|
|
8
8
|
```html:preview
|
|
9
|
-
<zn-radio-group>
|
|
9
|
+
<zn-radio-group label="Select an option">
|
|
10
10
|
<zn-radio value="1">Option 1</zn-radio>
|
|
11
11
|
<zn-radio value="2">Option 2</zn-radio>
|
|
12
12
|
<zn-radio value="3">Option 3</zn-radio>
|
|
13
13
|
</zn-radio-group>
|
|
14
14
|
```
|
|
15
15
|
|
|
16
|
+
:::tip
|
|
17
|
+
This component works with standard `<form>` elements. Please refer to the section on [form controls](/getting-started/form-controls) to learn more about form submission and client-side validation.
|
|
18
|
+
:::
|
|
19
|
+
|
|
16
20
|
## Examples
|
|
17
21
|
|
|
18
22
|
### Basic Radio Group
|
|
19
23
|
|
|
20
|
-
A basic radio group lays out multiple radio items vertically.
|
|
24
|
+
Use the `label` attribute to give the radio group an accessible label. For labels that contain HTML, use the `label` slot instead. A basic radio group lays out multiple radio items vertically.
|
|
21
25
|
|
|
22
26
|
```html:preview
|
|
23
27
|
<zn-radio-group label="Financial products permissions" name="a">
|
|
@@ -27,6 +31,18 @@ A basic radio group lays out multiple radio items vertically.
|
|
|
27
31
|
</zn-radio-group>
|
|
28
32
|
```
|
|
29
33
|
|
|
34
|
+
### Initial Values
|
|
35
|
+
|
|
36
|
+
Use the `value` attribute to set the initial selection.
|
|
37
|
+
|
|
38
|
+
```html:preview
|
|
39
|
+
<zn-radio-group label="Select a payment method" value="credit-card">
|
|
40
|
+
<zn-radio value="credit-card">Credit Card</zn-radio>
|
|
41
|
+
<zn-radio value="debit-card">Debit Card</zn-radio>
|
|
42
|
+
<zn-radio value="bank-transfer">Bank Transfer</zn-radio>
|
|
43
|
+
</zn-radio-group>
|
|
44
|
+
```
|
|
45
|
+
|
|
30
46
|
### Help Text
|
|
31
47
|
|
|
32
48
|
Add descriptive help text to a radio group with the `help-text` attribute. For help texts that contain HTML, use the
|
|
@@ -38,6 +54,13 @@ Add descriptive help text to a radio group with the `help-text` attribute. For h
|
|
|
38
54
|
<zn-radio value="approve-outbound">Approve outbound transfers </zn-radio>
|
|
39
55
|
<zn-radio value="export">Export transactions</zn-radio>
|
|
40
56
|
</zn-radio-group>
|
|
57
|
+
<br>
|
|
58
|
+
<zn-radio-group label="Financial products permissions" name="b">
|
|
59
|
+
<zn-radio value="initiate-outbound">Initiate outbound transfers</zn-radio>
|
|
60
|
+
<zn-radio value="approve-outbound">Approve outbound transfers </zn-radio>
|
|
61
|
+
<zn-radio value="export">Export transactions</zn-radio>
|
|
62
|
+
<div slot="help-text">Outbound transfers require <strong>separate</strong> initiators and approvers</div>
|
|
63
|
+
</zn-radio-group>
|
|
41
64
|
```
|
|
42
65
|
|
|
43
66
|
### Label with Tooltip
|
|
@@ -58,6 +81,30 @@ selection without errors.
|
|
|
58
81
|
</zn-radio-group>
|
|
59
82
|
```
|
|
60
83
|
|
|
84
|
+
### Sizes
|
|
85
|
+
|
|
86
|
+
Use the `size` attribute to change a radio group's size. This size will be applied to all child radios in the group. Size `medium` is the default.
|
|
87
|
+
|
|
88
|
+
```html:preview
|
|
89
|
+
<zn-radio-group label="Small size" size="small" name="size-small">
|
|
90
|
+
<zn-radio value="option-1">Option 1</zn-radio>
|
|
91
|
+
<zn-radio value="option-2">Option 2</zn-radio>
|
|
92
|
+
<zn-radio value="option-3">Option 3</zn-radio>
|
|
93
|
+
</zn-radio-group>
|
|
94
|
+
<br />
|
|
95
|
+
<zn-radio-group label="Medium size" size="medium" name="size-medium">
|
|
96
|
+
<zn-radio value="option-1">Option 1</zn-radio>
|
|
97
|
+
<zn-radio value="option-2">Option 2</zn-radio>
|
|
98
|
+
<zn-radio value="option-3">Option 3</zn-radio>
|
|
99
|
+
</zn-radio-group>
|
|
100
|
+
<br />
|
|
101
|
+
<zn-radio-group label="Large size" size="large" name="size-large">
|
|
102
|
+
<zn-radio value="option-1">Option 1</zn-radio>
|
|
103
|
+
<zn-radio value="option-2">Option 2</zn-radio>
|
|
104
|
+
<zn-radio value="option-3">Option 3</zn-radio>
|
|
105
|
+
</zn-radio-group>
|
|
106
|
+
```
|
|
107
|
+
|
|
61
108
|
### Horizontal Radio Group
|
|
62
109
|
|
|
63
110
|
Use the `horizontal` attribute to lay out multiple radio items horizontally.
|
|
@@ -112,7 +159,7 @@ This option can be combined with the `horizontal` attribute.
|
|
|
112
159
|
```
|
|
113
160
|
|
|
114
161
|
:::tip
|
|
115
|
-
When [radios](/components/radio) are wrapped with the Radio Group
|
|
162
|
+
When [radios](/components/radio) are wrapped with the Radio Group, adding the `contained` attribute to the
|
|
116
163
|
parent Radio Group or to _any_ radio in the group will create `contained` radios for the entire group.
|
|
117
164
|
:::
|
|
118
165
|
|
|
@@ -121,9 +168,199 @@ parent Radio Group or to _any_ radio in the group will create `contained` radios
|
|
|
121
168
|
Radios can be disabled by adding the `disabled` attribute to the respective options inside the radio group.
|
|
122
169
|
|
|
123
170
|
```html:preview
|
|
124
|
-
<zn-radio-group name="a"
|
|
171
|
+
<zn-radio-group name="a" label="Financial products permissions" help-text="Exporting is currently disabled for all users">
|
|
125
172
|
<zn-radio value="initiate-outbound">Initiate outbound transfers</zn-radio>
|
|
126
173
|
<zn-radio value="approve-outbound">Approve outbound transfers </zn-radio>
|
|
127
174
|
<zn-radio value="export" disabled>Export transactions</zn-radio>
|
|
128
175
|
</zn-radio-group>
|
|
129
176
|
```
|
|
177
|
+
|
|
178
|
+
### Form Integration
|
|
179
|
+
|
|
180
|
+
Radio group components work seamlessly with standard HTML forms. The radio group's `name` attribute determines the key in the form data, and the selected radio's `value` becomes the value.
|
|
181
|
+
|
|
182
|
+
```html:preview
|
|
183
|
+
<form id="radio-form">
|
|
184
|
+
<zn-radio-group name="department" label="Department" value="engineering" required>
|
|
185
|
+
<zn-radio value="engineering">Engineering</zn-radio>
|
|
186
|
+
<zn-radio value="design">Design</zn-radio>
|
|
187
|
+
<zn-radio value="marketing">Marketing</zn-radio>
|
|
188
|
+
<zn-radio value="sales">Sales</zn-radio>
|
|
189
|
+
</zn-radio-group>
|
|
190
|
+
<br />
|
|
191
|
+
<zn-radio-group name="level" label="Experience level" value="mid" required>
|
|
192
|
+
<zn-radio value="junior">Junior</zn-radio>
|
|
193
|
+
<zn-radio value="mid">Mid-level</zn-radio>
|
|
194
|
+
<zn-radio value="senior">Senior</zn-radio>
|
|
195
|
+
</zn-radio-group>
|
|
196
|
+
<br />
|
|
197
|
+
<zn-button type="submit" variant="primary">Submit</zn-button>
|
|
198
|
+
<zn-button type="reset">Reset</zn-button>
|
|
199
|
+
</form>
|
|
200
|
+
|
|
201
|
+
<script type="module">
|
|
202
|
+
const form = document.getElementById('radio-form');
|
|
203
|
+
|
|
204
|
+
form.addEventListener('submit', (e) => {
|
|
205
|
+
e.preventDefault();
|
|
206
|
+
const formData = new FormData(form);
|
|
207
|
+
const data = Object.fromEntries(formData);
|
|
208
|
+
alert('Form submitted!\n\n' + JSON.stringify(data, null, 2));
|
|
209
|
+
});
|
|
210
|
+
</script>
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
### Validation
|
|
214
|
+
|
|
215
|
+
Set the `required` attribute to make selecting an option mandatory. If a value has not been selected, it will prevent the form from submitting and display an error message.
|
|
216
|
+
|
|
217
|
+
```html:preview
|
|
218
|
+
<form class="validation">
|
|
219
|
+
<zn-radio-group name="a" label="Select one option" required>
|
|
220
|
+
<zn-radio value="option-1">Option 1</zn-radio>
|
|
221
|
+
<zn-radio value="option-2">Option 2</zn-radio>
|
|
222
|
+
<zn-radio value="option-3">Option 3</zn-radio>
|
|
223
|
+
</zn-radio-group>
|
|
224
|
+
<br />
|
|
225
|
+
<zn-button type="submit" variant="primary">Submit</zn-button>
|
|
226
|
+
</form>
|
|
227
|
+
|
|
228
|
+
<script type="module">
|
|
229
|
+
const form = document.querySelector('.validation');
|
|
230
|
+
|
|
231
|
+
// Wait for controls to be defined before attaching form listeners
|
|
232
|
+
await Promise.all([
|
|
233
|
+
customElements.whenDefined('zn-radio-group'),
|
|
234
|
+
]).then(() => {
|
|
235
|
+
form.addEventListener('submit', event => {
|
|
236
|
+
event.preventDefault();
|
|
237
|
+
alert('All fields are valid!');
|
|
238
|
+
});
|
|
239
|
+
});
|
|
240
|
+
</script>
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
### Custom Validity
|
|
244
|
+
|
|
245
|
+
Use the `setCustomValidity()` method to set a custom validation message. This will prevent the form from submitting and
|
|
246
|
+
make the browser display the error message you provide. To clear the error, call this function with an empty string.
|
|
247
|
+
|
|
248
|
+
```html:preview
|
|
249
|
+
<form class="custom-validity">
|
|
250
|
+
<zn-radio-group name="a" label="Select the second option" required>
|
|
251
|
+
<zn-radio value="option-1">I'm not the right choice</zn-radio>
|
|
252
|
+
<zn-radio value="option-2">You must choose me</zn-radio>
|
|
253
|
+
<zn-radio value="option-3">I won't work either</zn-radio>
|
|
254
|
+
</zn-radio-group>
|
|
255
|
+
<br />
|
|
256
|
+
<zn-button type="submit" variant="primary">Submit</zn-button>
|
|
257
|
+
</form>
|
|
258
|
+
|
|
259
|
+
<script type="module">
|
|
260
|
+
const form = document.querySelector('.custom-validity');
|
|
261
|
+
const radioGroup = form.querySelector('zn-radio-group');
|
|
262
|
+
const errorMessage = 'You must choose the second option';
|
|
263
|
+
|
|
264
|
+
// Set initial validity as soon as the element is defined
|
|
265
|
+
customElements.whenDefined('zn-radio').then(() => {
|
|
266
|
+
radioGroup.setCustomValidity(errorMessage);
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
// Update validity when a selection is made
|
|
270
|
+
form.addEventListener('zn-change', () => {
|
|
271
|
+
const isValid = radioGroup.value === 'option-2';
|
|
272
|
+
radioGroup.setCustomValidity(isValid ? '' : errorMessage);
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
// Wait for controls to be defined before attaching form listeners
|
|
276
|
+
await Promise.all([
|
|
277
|
+
customElements.whenDefined('zn-radio-group'),
|
|
278
|
+
]).then(() => {
|
|
279
|
+
form.addEventListener('submit', event => {
|
|
280
|
+
event.preventDefault();
|
|
281
|
+
alert('All fields are valid!');
|
|
282
|
+
});
|
|
283
|
+
});
|
|
284
|
+
</script>
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
### Programmatic Control
|
|
288
|
+
|
|
289
|
+
You can control the radio group programmatically using its methods and properties:
|
|
290
|
+
|
|
291
|
+
```html:preview
|
|
292
|
+
<div class="form-spacing">
|
|
293
|
+
<zn-radio-group id="programmatic-radio" label="Programmatic control" name="programmatic">
|
|
294
|
+
<zn-radio value="option-1">Option 1</zn-radio>
|
|
295
|
+
<zn-radio value="option-2">Option 2</zn-radio>
|
|
296
|
+
<zn-radio value="option-3">Option 3</zn-radio>
|
|
297
|
+
<zn-radio value="option-4">Option 4</zn-radio>
|
|
298
|
+
</zn-radio-group>
|
|
299
|
+
|
|
300
|
+
<div style="margin-top: 1rem; display: flex; gap: 0.5rem; flex-wrap: wrap;">
|
|
301
|
+
<zn-button id="focus-btn" size="small">Focus</zn-button>
|
|
302
|
+
<zn-button id="set-value-btn" size="small">Set Value to Option 3</zn-button>
|
|
303
|
+
<zn-button id="check-validity-btn" size="small">Check Validity</zn-button>
|
|
304
|
+
<zn-button id="get-form-btn" size="small">Get Form</zn-button>
|
|
305
|
+
</div>
|
|
306
|
+
</div>
|
|
307
|
+
|
|
308
|
+
<script type="module">
|
|
309
|
+
const radioGroup = document.getElementById('programmatic-radio');
|
|
310
|
+
|
|
311
|
+
document.getElementById('focus-btn').addEventListener('click', () => radioGroup.focus());
|
|
312
|
+
document.getElementById('set-value-btn').addEventListener('click', () => {
|
|
313
|
+
radioGroup.value = 'option-3';
|
|
314
|
+
});
|
|
315
|
+
document.getElementById('check-validity-btn').addEventListener('click', () => {
|
|
316
|
+
alert('Valid: ' + radioGroup.checkValidity());
|
|
317
|
+
});
|
|
318
|
+
document.getElementById('get-form-btn').addEventListener('click', () => {
|
|
319
|
+
const form = radioGroup.getForm();
|
|
320
|
+
alert('Form: ' + (form ? form.id || 'Form found (no ID)' : 'Not in a form'));
|
|
321
|
+
});
|
|
322
|
+
</script>
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
### Keyboard Navigation
|
|
326
|
+
|
|
327
|
+
The radio group component supports comprehensive keyboard navigation:
|
|
328
|
+
|
|
329
|
+
- **Tab** - Move focus to/from the radio group (focuses the checked radio, or the first radio if none are checked)
|
|
330
|
+
- **Arrow Up/Left** - Select the previous radio in the group (wraps around to the last option)
|
|
331
|
+
- **Arrow Down/Right** - Select the next radio in the group (wraps around to the first option)
|
|
332
|
+
- **Space** - Select the currently focused radio
|
|
333
|
+
|
|
334
|
+
### Customizing Label Position
|
|
335
|
+
|
|
336
|
+
Use [CSS parts](#css-parts) to customize the way form controls are drawn. This example uses CSS grid to position the label to the left of the control.
|
|
337
|
+
|
|
338
|
+
```html:preview
|
|
339
|
+
<zn-radio-group class="label-on-left" label="Department" name="dept-custom">
|
|
340
|
+
<zn-radio value="engineering">Engineering</zn-radio>
|
|
341
|
+
<zn-radio value="design">Design</zn-radio>
|
|
342
|
+
<zn-radio value="marketing">Marketing</zn-radio>
|
|
343
|
+
</zn-radio-group>
|
|
344
|
+
|
|
345
|
+
<style>
|
|
346
|
+
.label-on-left {
|
|
347
|
+
--label-width: 5rem;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
.label-on-left::part(form-control) {
|
|
351
|
+
display: grid;
|
|
352
|
+
grid: auto / var(--label-width) 1fr;
|
|
353
|
+
gap: var(--zn-spacing-3x-small) var(--zn-spacing-medium);
|
|
354
|
+
align-items: start;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
.label-on-left::part(form-control-label) {
|
|
358
|
+
text-align: right;
|
|
359
|
+
padding-top: 0.25rem;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
.label-on-left::part(form-control-help-text) {
|
|
363
|
+
grid-column-start: 2;
|
|
364
|
+
}
|
|
365
|
+
</style>
|
|
366
|
+
```
|