@fibrae/semi-ui-svelte 0.9.1 → 0.10.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 +8 -4
- package/README.zh-CN.md +8 -4
- package/dist/components/anchor/interface.d.ts +14 -0
- package/dist/components/audio-player/interface.d.ts +5 -0
- package/dist/components/auto-complete/interface.d.ts +29 -0
- package/dist/components/avatar/interface.d.ts +24 -0
- package/dist/components/backtop/interface.d.ts +2 -0
- package/dist/components/badge/interface.d.ts +7 -0
- package/dist/components/banner/interface.d.ts +7 -0
- package/dist/components/breadcrumb/interface.d.ts +10 -0
- package/dist/components/button/interface.d.ts +18 -0
- package/dist/components/calendar/interface.d.ts +16 -0
- package/dist/components/card/interface.d.ts +18 -0
- package/dist/components/carousel/interface.d.ts +16 -0
- package/dist/components/cascader/interface.d.ts +57 -0
- package/dist/components/checkbox/interface.d.ts +19 -0
- package/dist/components/code-highlight/interface.d.ts +3 -0
- package/dist/components/collapse/interface.d.ts +16 -0
- package/dist/components/collapsible/interface.d.ts +10 -0
- package/dist/components/color-picker/interface.d.ts +10 -0
- package/dist/components/config-provider/interface.d.ts +7 -0
- package/dist/components/cropper/interface.d.ts +11 -0
- package/dist/components/date-picker/interface.d.ts +47 -0
- package/dist/components/descriptions/interface.d.ts +6 -0
- package/dist/components/divider/interface.d.ts +4 -0
- package/dist/components/dropdown/interface.d.ts +8 -0
- package/dist/components/empty/interface.d.ts +7 -0
- package/dist/components/feedback/interface.d.ts +16 -0
- package/dist/components/float-button/interface.d.ts +14 -0
- package/dist/components/form/interface.d.ts +47 -0
- package/dist/components/grid/interface.d.ts +13 -0
- package/dist/components/highlight/interface.d.ts +7 -0
- package/dist/components/hot-keys/interface.d.ts +3 -0
- package/dist/components/image/interface.d.ts +59 -0
- package/dist/components/input/interface.d.ts +67 -0
- package/dist/components/input-number/interface.d.ts +24 -0
- package/dist/components/json-viewer/interface.d.ts +7 -0
- package/dist/components/layout/interface.d.ts +3 -0
- package/dist/components/list/interface.d.ts +18 -0
- package/dist/components/locale/interface.d.ts +4 -0
- package/dist/components/lottie/interface.d.ts +2 -0
- package/dist/components/markdown-render/interface.d.ts +5 -0
- package/dist/components/modal/interface.d.ts +29 -0
- package/dist/components/navigation/interface.d.ts +47 -0
- package/dist/components/overflow-list/interface.d.ts +11 -0
- package/dist/components/pagination/interface.d.ts +12 -0
- package/dist/components/pincode/interface.d.ts +8 -0
- package/dist/components/popconfirm/interface.d.ts +12 -0
- package/dist/components/popover/interface.d.ts +30 -0
- package/dist/components/progress/interface.d.ts +13 -0
- package/dist/components/radio/interface.d.ts +22 -0
- package/dist/components/rating/interface.d.ts +12 -0
- package/dist/components/resizable/interface.d.ts +30 -0
- package/dist/components/scroll-list/interface.d.ts +6 -0
- package/dist/components/select/interface.d.ts +63 -0
- package/dist/components/side-sheet/interface.d.ts +19 -0
- package/dist/components/skeleton/interface.d.ts +7 -0
- package/dist/components/slider/interface.d.ts +23 -0
- package/dist/components/space/interface.d.ts +4 -0
- package/dist/components/spin/interface.d.ts +7 -0
- package/dist/components/steps/interface.d.ts +9 -0
- package/dist/components/switch/interface.d.ts +7 -0
- package/dist/components/table/interface.d.ts +48 -0
- package/dist/components/tabs/interface.d.ts +29 -0
- package/dist/components/tag/interface.d.ts +22 -0
- package/dist/components/tag-input/interface.d.ts +29 -0
- package/dist/components/time-picker/interface.d.ts +31 -0
- package/dist/components/timeline/interface.d.ts +5 -0
- package/dist/components/tooltip/interface.d.ts +20 -0
- package/dist/components/transfer/interface.d.ts +18 -0
- package/dist/components/tree/interface.d.ts +45 -0
- package/dist/components/tree-select/interface.d.ts +55 -0
- package/dist/components/typography/interface.d.ts +33 -0
- package/dist/components/upload/interface.d.ts +64 -0
- package/dist/components/user-guide/interface.d.ts +15 -0
- package/dist/components/video-player/interface.d.ts +22 -0
- package/docs/advanced/dark-mode.md +288 -0
- package/docs/basic/button.md +605 -0
- package/docs/basic/divider.md +103 -0
- package/docs/basic/float-button.md +246 -0
- package/docs/basic/grid.md +427 -0
- package/docs/basic/layout.md +459 -0
- package/docs/basic/resizable.md +584 -0
- package/docs/basic/space.md +163 -0
- package/docs/basic/tokens.md +425 -0
- package/docs/basic/typography.md +615 -0
- package/docs/changes-from-semi.md +105 -0
- package/docs/ecosystem/tailwind.md +210 -0
- package/docs/experience/accessibility.md +82 -0
- package/docs/experience/content-guidelines.md +819 -0
- package/docs/experience/internationalization.md +7 -0
- package/docs/feedback/banner.md +198 -0
- package/docs/feedback/feedback.md +294 -0
- package/docs/feedback/notification.md +401 -0
- package/docs/feedback/popconfirm.md +243 -0
- package/docs/feedback/progress.md +389 -0
- package/docs/feedback/skeleton.md +388 -0
- package/docs/feedback/spin.md +172 -0
- package/docs/feedback/toast.md +393 -0
- package/docs/input/auto-complete.md +399 -0
- package/docs/input/cascader.md +1558 -0
- package/docs/input/checkbox.md +408 -0
- package/docs/input/color-picker.md +175 -0
- package/docs/input/date-picker.md +942 -0
- package/docs/input/form.md +2550 -0
- package/docs/input/input-number.md +451 -0
- package/docs/input/input.md +640 -0
- package/docs/input/pincode.md +191 -0
- package/docs/input/radio.md +337 -0
- package/docs/input/rating.md +214 -0
- package/docs/input/select.md +1230 -0
- package/docs/input/slider.md +347 -0
- package/docs/input/switch.md +206 -0
- package/docs/input/tag-input.md +465 -0
- package/docs/input/time-picker.md +358 -0
- package/docs/input/transfer.md +1061 -0
- package/docs/input/tree-select.md +1300 -0
- package/docs/input/upload.md +1811 -0
- package/docs/llms.txt +147 -0
- package/docs/navigation/anchor.md +377 -0
- package/docs/navigation/backtop.md +100 -0
- package/docs/navigation/breadcrumb.md +284 -0
- package/docs/navigation/navigation.md +851 -0
- package/docs/navigation/pagination.md +217 -0
- package/docs/navigation/steps.md +315 -0
- package/docs/navigation/tabs.md +754 -0
- package/docs/navigation/tree.md +1956 -0
- package/docs/other/config-provider.md +599 -0
- package/docs/other/locale.md +353 -0
- package/docs/plus/audio-player.md +155 -0
- package/docs/plus/code-highlight.md +150 -0
- package/docs/plus/drag-move.md +214 -0
- package/docs/plus/hot-keys.md +174 -0
- package/docs/plus/json-viewer.md +392 -0
- package/docs/plus/lottie.md +176 -0
- package/docs/plus/markdown-render.md +240 -0
- package/docs/plus/video-player.md +325 -0
- package/docs/show/avatar.md +475 -0
- package/docs/show/badge.md +276 -0
- package/docs/show/calendar.md +352 -0
- package/docs/show/card.md +485 -0
- package/docs/show/carousel.md +592 -0
- package/docs/show/collapse.md +289 -0
- package/docs/show/collapsible.md +216 -0
- package/docs/show/cropper.md +285 -0
- package/docs/show/descriptions.md +325 -0
- package/docs/show/dropdown.md +466 -0
- package/docs/show/empty.md +225 -0
- package/docs/show/highlight.md +144 -0
- package/docs/show/image.md +433 -0
- package/docs/show/list.md +927 -0
- package/docs/show/modal.md +517 -0
- package/docs/show/overflow-list.md +272 -0
- package/docs/show/popover.md +534 -0
- package/docs/show/scroll-list.md +156 -0
- package/docs/show/side-sheet.md +274 -0
- package/docs/show/table.md +5437 -0
- package/docs/show/tag.md +428 -0
- package/docs/show/timeline.md +277 -0
- package/docs/show/tooltip.md +442 -0
- package/docs/show/user-guide.md +419 -0
- package/docs/start/getting-started.md +234 -0
- package/docs/start/introduction.md +57 -0
- package/docs/start/overview.md +21 -0
- package/package.json +5 -4
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
# PinCode
|
|
2
|
+
|
|
3
|
+
> For easy and intuitive verification code entry
|
|
4
|
+
|
|
5
|
+
Package: `@fibrae/semi-ui-svelte`. Web page: https://semi-design-next.pages.dev/en-US/svelte/input/pincode/
|
|
6
|
+
|
|
7
|
+
## Demos
|
|
8
|
+
|
|
9
|
+
### How to import
|
|
10
|
+
|
|
11
|
+
```svelte
|
|
12
|
+
<script lang="ts">
|
|
13
|
+
import { Button, PinCode, Typography } from '@fibrae/semi-ui-svelte';
|
|
14
|
+
</script>
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
### Basic usage
|
|
18
|
+
|
|
19
|
+
```svelte
|
|
20
|
+
<script lang="ts">
|
|
21
|
+
import { PinCode } from '@fibrae/semi-ui-svelte';
|
|
22
|
+
</script>
|
|
23
|
+
|
|
24
|
+
<div>
|
|
25
|
+
<PinCode aria-label="Verification code, small" onChange={(value) => console.log(value)} onComplete={(value) => console.log('pincode: ', value)} size="small" value="123456" />
|
|
26
|
+
<br />
|
|
27
|
+
<PinCode aria-label="Verification code, default" onChange={(value) => console.log(value)} onComplete={(value) => console.log('pincode: ', value)} size="default" value="123456" />
|
|
28
|
+
<br />
|
|
29
|
+
<PinCode aria-label="Verification code, large" onChange={(value) => console.log(value)} onComplete={(value) => console.log('pincode: ', value)} size="large" value="123456" />
|
|
30
|
+
</div>
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### Controlled
|
|
34
|
+
|
|
35
|
+
Use `bind:value` to bind the verification code string; a plain `value` is the initial content, and there is no `defaultValue`
|
|
36
|
+
|
|
37
|
+
```svelte
|
|
38
|
+
<script lang="ts">
|
|
39
|
+
import { Button, PinCode } from '@fibrae/semi-ui-svelte';
|
|
40
|
+
|
|
41
|
+
let value = $state('69af41');
|
|
42
|
+
</script>
|
|
43
|
+
|
|
44
|
+
<div>
|
|
45
|
+
<Button onclick={() => (value = String(Math.floor(Math.random() * 100000000)).slice(0, 6))}>Set Random Value</Button>
|
|
46
|
+
<br />
|
|
47
|
+
<br />
|
|
48
|
+
<PinCode aria-label="Verification code" bind:value format="mixed" onChange={(code) => console.log(code)} onComplete={(code) => console.log('pincode: ', code)} />
|
|
49
|
+
</div>
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### Limit verification code format
|
|
53
|
+
|
|
54
|
+
#### Set the number of digits
|
|
55
|
+
|
|
56
|
+
Set the number of digits through count, the default is 6 digits, the demo below is set to 4 digits
|
|
57
|
+
|
|
58
|
+
```svelte
|
|
59
|
+
<script lang="ts">
|
|
60
|
+
import { PinCode } from '@fibrae/semi-ui-svelte';
|
|
61
|
+
</script>
|
|
62
|
+
|
|
63
|
+
<PinCode aria-label="Verification code" count={4} onChange={(value) => console.log(value)} onComplete={(value) => console.log('pincode: ', value)} size="large" value="6688" />
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
#### Set character range
|
|
67
|
+
|
|
68
|
+
Use format to control the character range that can be entered
|
|
69
|
+
|
|
70
|
+
- Pass "number" to only allow numbers
|
|
71
|
+
- Pass "mixed" to allow numbers and letters
|
|
72
|
+
- Pass in a regular expression to only allow characters that can be judged by the regular expression
|
|
73
|
+
- Pass in a function, and the verification code will be passed in as parameters in units of characters for verification when entering. When the function returns true, the character is allowed to be entered into the PinCode
|
|
74
|
+
|
|
75
|
+
```svelte
|
|
76
|
+
<script lang="ts">
|
|
77
|
+
import { PinCode, Typography } from '@fibrae/semi-ui-svelte';
|
|
78
|
+
|
|
79
|
+
const isLowerCase = (char: string) => /[a-z]/.test(char);
|
|
80
|
+
</script>
|
|
81
|
+
|
|
82
|
+
<div>
|
|
83
|
+
<Typography.Text id="pincode-format-number">纯数字</Typography.Text>
|
|
84
|
+
<PinCode aria-labelledby="pincode-format-number" format="number" onComplete={(value) => console.log('pincode: ', value)} />
|
|
85
|
+
<br />
|
|
86
|
+
<Typography.Text id="pincode-format-mixed">字母和数字</Typography.Text>
|
|
87
|
+
<PinCode aria-labelledby="pincode-format-mixed" format="mixed" onComplete={(value) => console.log('pincode: ', value)} />
|
|
88
|
+
<br />
|
|
89
|
+
<Typography.Text id="pincode-format-upper">只大写字母</Typography.Text>
|
|
90
|
+
<PinCode aria-labelledby="pincode-format-upper" format={/[A-Z]/} onComplete={(value) => console.log('pincode: ', value)} />
|
|
91
|
+
<br />
|
|
92
|
+
<Typography.Text id="pincode-format-lower">只小写字母(函数判断)</Typography.Text>
|
|
93
|
+
<PinCode aria-labelledby="pincode-format-lower" format={isLowerCase} onComplete={(value) => console.log('pincode: ', value)} />
|
|
94
|
+
</div>
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### Manual focus and blur
|
|
98
|
+
|
|
99
|
+
Get the component instance with `bind:this` and call `focus(index)` and `blur(index)`; the argument is the index of the corresponding Input, counted from 0
|
|
100
|
+
|
|
101
|
+
```svelte
|
|
102
|
+
<script lang="ts">
|
|
103
|
+
import { Button, PinCode } from '@fibrae/semi-ui-svelte';
|
|
104
|
+
|
|
105
|
+
let value = $state('69af41');
|
|
106
|
+
let pinCode = $state<ReturnType<typeof PinCode>>();
|
|
107
|
+
</script>
|
|
108
|
+
|
|
109
|
+
<div>
|
|
110
|
+
<Button onclick={() => pinCode?.focus(2)}>Focus Third Input</Button>
|
|
111
|
+
<br />
|
|
112
|
+
<br />
|
|
113
|
+
<PinCode aria-label="Verification code" bind:this={pinCode} bind:value format="mixed" onChange={(code) => console.log(code)} onComplete={(code) => console.log('pincode: ', code)} />
|
|
114
|
+
</div>
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## API Reference
|
|
118
|
+
|
|
119
|
+
**Props**
|
|
120
|
+
|
|
121
|
+
| Property | Description | Type | Default |
|
|
122
|
+
| - | - | - | - |
|
|
123
|
+
| autofocus | Whether to focus the first input on mount. Turn it on only when the user has just entered the code step: focus moving at page load makes screen readers skip the content before it. | `boolean` | `false` |
|
|
124
|
+
| count | Number of digits. | `number` | `6` |
|
|
125
|
+
| disabled | Whether the input is disabled. | `boolean` | - |
|
|
126
|
+
| format | Format limit for a single character: number allows digits only, mixed allows digits and letters, and a regular expression or function judges each character. | `PinCodeFormat` | `"number"` |
|
|
127
|
+
| onBlur | Called when focus leaves the whole code. | `(event: FocusEvent) => void` | - |
|
|
128
|
+
| onChange | Called when the content changes, with the current content. | `(value: string) => void` | - |
|
|
129
|
+
| onComplete | Called once all digits are entered, with the current content. | `(value: string) => void` | - |
|
|
130
|
+
| onFocus | Called when focus enters the code from outside; moving between the inputs does not call it. | `(event: FocusEvent) => void` | - |
|
|
131
|
+
| size | Input size: large, default or small. | `InputSize` | - |
|
|
132
|
+
| validateStatus | Validation status, passed to every input; error shows the error style. | `ValidateStatus` | - |
|
|
133
|
+
| value | Input content; bind it with `bind:value`. `bind:value={get, set}` makes it fully controlled; a plain `value` is the initial value. | `string` | - |
|
|
134
|
+
|
|
135
|
+
**Methods**
|
|
136
|
+
|
|
137
|
+
| Method | Description | Type |
|
|
138
|
+
| - | - | - |
|
|
139
|
+
| blur | Blurs the input at index, counted from 0 and ignored when out of range. | `(index: number) => void` |
|
|
140
|
+
| focus | Focuses the input at index, counted from 0 and ignored when out of range, with the caret after its character. | `(index: number) => void` |
|
|
141
|
+
|
|
142
|
+
`class`, `style` (a string), `aria-label`, `aria-labelledby` and `data-*` land on the `role="group"` root element. `id` lands on the first input box, so `<label for>` points at the first digit. `aria-describedby`, `aria-errormessage`, `aria-invalid`, `aria-required` and `tabindex` land on every input box. `name`, `insetLabel` and `insetLabelId` are discarded. `onFocus` and `onBlur` are counted for the whole code. `autofocus` focuses the first input box on mount and defaults to `false`; turn it on only when the user has just entered the code step.
|
|
143
|
+
|
|
144
|
+
## Accessibility
|
|
145
|
+
|
|
146
|
+
### ARIA
|
|
147
|
+
|
|
148
|
+
- The root element is `role="group"`, named through `aria-label` or `aria-labelledby`; pass `aria-label` when there is no visible label, otherwise the group has no name.
|
|
149
|
+
- Each input box takes its accessible name from the locale, for example "Digit 1 of 6", which follows `count` and the box index, so nothing needs to be set by hand.
|
|
150
|
+
- `aria-describedby`, `aria-errormessage`, `aria-invalid` and `aria-required` land on every input box; `validateStatus` is passed to every input box.
|
|
151
|
+
- With `format` set to `"number"` the input boxes use the numeric soft keyboard (`inputmode="numeric"`); otherwise the text keyboard.
|
|
152
|
+
|
|
153
|
+
### Keyboard and Focus
|
|
154
|
+
|
|
155
|
+
- Each box is its own input; after a valid character is entered, focus moves to the next box, and entering the last box blurs it. The filled characters always run from the first box without gaps, so a character typed after an empty box lands in the first empty box. `Tab` and `Shift` + `Tab` move between boxes.
|
|
156
|
+
- `Left Arrow` and `Right Arrow` move focus between boxes, reversed when the ConfigProvider `direction` is `rtl` (`Left Arrow` moves to the next box). `Backspace` and `Delete` both delete the character in the current box and the following characters move forward; `Backspace` also moves focus to the previous box.
|
|
157
|
+
- Pasting a whole code fills the boxes by character from the current box, and stops at the first invalid character.
|
|
158
|
+
- `autoFocus` (`autofocus` in Vue) should be turned on only when the user has just entered the code step: focus moving at page load makes screen readers skip the content before it.
|
|
159
|
+
|
|
160
|
+
## Changes from Semi Design
|
|
161
|
+
|
|
162
|
+
From the project release notes (written in Chinese). Your knowledge of Semi Design does not cover these.
|
|
163
|
+
|
|
164
|
+
- 破坏性:AutoComplete 删除 `dropdownClassName`、`dropdownStyle`,改用 `classNames.dropdown`、`styles.dropdown`,落在 `role="listbox"` 元素上,样式与 `maxHeight` 合并且 `styles.dropdown` 优先。
|
|
165
|
+
- PinCode:格子间距改为逻辑属性;ConfigProvider 的 `direction` 为 `rtl` 时左右方向键反向(ArrowLeft 移到下一格)。
|
|
166
|
+
- 破坏性:AutoComplete 删除 `getPopupContainer`、`zIndex`、`AutoComplete.Option` 与 `children`(改用 `Select.Option`),删除深路径 `@fibrae/semi-ui-react/auto-complete/option`、`@fibrae/semi-foundation/auto-complete/optionFoundation`;`style.width` 不再复制为下拉最小宽度。
|
|
167
|
+
- 破坏性(类型):AutoComplete 的 `defaultValue` 收窄为 `string | number`,`onKeyDown` 参数改为 `KeyboardEvent<HTMLDivElement>`,删除 `mouseEnterDelay`、`mouseLeaveDelay`、`tabIndex`;输入框角色改为 combobox(按 textbox 查询的测试需改为 combobox),`id` 落在输入框上。
|
|
168
|
+
- 破坏性(类型):TagInput 的 `onFocus`、`onBlur` 参数改为 `React.FocusEvent<HTMLDivElement>`,`onInputChange` 第二个参数改为 `React.SyntheticEvent`,`value` 为 `string[] | null`,ref 为 `TagInputHandle { focus, blur }`;`AvatarState.hoverContent` 改为 `hovered: boolean`。
|
|
169
|
+
- 破坏性(类型):`@fibrae/semi-foundation/components/tag-input/foundation` 删除 `any` 别名 `TagInputCursorEvent`、`TagInputKeyboardEvent`、`TagInputMouseEvent`,改为 `TagInputKeyEvent`、`TagInputFocusEvent`、`TagInputClearEvent`;`TagInputFoundation`、`TagInputAdapter` 新增按键与焦点事件的类型参数 `KE`、`FE`,`notifyKeyDown`、`notifyFocus`、`notifyBlur` 的参数随之收窄。
|
|
170
|
+
- TagInput:`+N` 浮层、`suffix` 中的 Popover 等内部弹层里的按下、焦点与点击不结束也不进入激活状态,`+N` 浮层里的标签可以直接关闭(四个框架一致)。
|
|
171
|
+
- AutoComplete:对象数据项缺 `label` 时候选行显示 `value`(四个框架一致);数据项带 `show: false` 时,高亮项与 Enter 选中项是同一个可见项。`defaultActiveFirstOption` 高亮第一个可用项,首项禁用时不再停在禁用项上(与 Select 一致,四个框架一致)。
|
|
172
|
+
- 破坏性(样式钩子):TagInput 悬停改由 CSS `:hover` 提供,不再加 `semi-tagInput-hover` 类;删除 `semi-tagInput-clearBtn-invisible` 与 `semi-avatar-focus`。TagInput 清除按钮与拖拽句柄改为带名称(`TagInput.clear`、`TagInput.dragSort`)的原生 button,`onFocus`、`onBlur` 以整个组件为界。
|
|
173
|
+
- Avatar:可点击头像的焦点目标为 `role="button"`(按 `img` 查询的测试需改为 button),不再加语言包 `Avatar.clickable` 前缀(键已删除);AvatarGroup 未声明属性落在根 div,`size`、`shape` 经 context 下发到被 Tooltip、Popover 包住的头像。PinCode:`autoFocus` 默认值由 `true` 改为 `false`,需要时显式传 `autoFocus` 或用 `PinCodeHandle.focus(0)`;`onFocus`、`onBlur` 按整组计,焦点从外部进入整个 PinCode 时触发一次 `onFocus`,格子之间移动不触发。
|
|
174
|
+
- Avatar:`bottomSlot` 方形标签不换行,比头像宽时向两侧超出。
|
|
175
|
+
- Avatar:`border.motion` 的外圈动画只放大并淡出,边框粗细不再随动画变细到 0(原来每帧触发布局与重绘);删除 Sass 变量 `$animation_width-additionalBorder-end`。
|
|
176
|
+
- React、Vue、Solid:服务端渲染的 Avatar 图片在 hydration 前已加载失败时,hydration 后调用 `onError` 并显示文字(原来保留破图)。
|
|
177
|
+
- AutoComplete:受控值回显但没有匹配项时保留已输入的文本(四个框架一致)。
|
|
178
|
+
- AutoComplete:下拉中有可聚焦元素(`renderItem`、`emptyContent` 里的按钮或链接)时,方向键只移动高亮,焦点不再移入下拉。
|
|
179
|
+
- Solid 破坏性:AvatarGroup 的 `renderMore` 签名为 `(restNumber: number, restAvatars: ((props?: AvatarProps) => JSX.Element)[]) => JSX.Element`。超出 `maxCount` 的头像在组内不创建,`restAvatars` 的每一项是渲染函数,在调用处才创建该头像(独立头像,不是列表项,不取组的 `size`、`shape`),传入的属性覆盖头像自身的属性(如 `avatar({ size: 'extra-small' })`,对应 React 的 `cloneElement`);`maxCount` 与 React 一样按子节点计数,包装元素(如 Tooltip)里的头像随包装元素整体隐藏,不单独隐藏,`maxCount` 变化或增删子节点时由后面的子节点补位。默认 `+N` 头像的名称只列被隐藏头像的 `alt`。
|
|
180
|
+
- Solid 破坏性(类型):Avatar 的 `topSlot.text`、`bottomSlot.text` 改为 `AvatarSlotText`(`string | number | (() => JSX.Element)`,从包入口导出),自定义内容写成函数 `text: () => <IconPlus />`,只在标记实际显示时(预设尺寸,topSlot 另需圆形)调用;`render` 仍完全替换标记。
|
|
181
|
+
- Svelte:Avatar 的 `class`、`style`、`id` 等属性落在头像 span,存在包装层时 `style` 落在包装层;传了 `onclick` 才成为可聚焦的 button;`hoverMask`、`topSlotText`、`bottomSlotText` 是 snippet,整块替换写 `topSlot.render`、`bottomSlot.render`,`topSlot.style`、`bottomSlot.style` 是字符串;内容是文字还是元素在挂载后判定,服务端首帧一律按文字结构输出。
|
|
182
|
+
- Svelte 破坏性:AvatarGroup 不接受 Avatar 子节点,改用 `items`(每项是 Avatar 的属性,类型 `AvatarGroupItem`)加 `item` snippet(参数 `{ item, index }`,提供头像内的文字),组的 `size`、`shape` 覆盖数据项自己的值;`maxCount` 截断、`+N` 与其可访问名称在服务端首帧同步算出,默认 `+N` 的名称只列被隐藏项的 `alt`。`more` snippet 参数为 `{ restNumber, restAvatars }`,`restAvatars` 是被隐藏的完整数据项。不能再用 Tooltip 等包裹组内的单个头像,需要时在 `item` snippet 里包裹内容。
|
|
183
|
+
- Svelte:PinCode 的 `value` 可绑定,没有 `defaultValue`;回调为 `onChange`、`onComplete`、`onFocus`、`onBlur`;`autofocus` 默认 `false`;实例方法为 `focus(index)`、`blur(index)`;`id` 落在第一格,`name`、`insetLabel`、`insetLabelId` 被丢弃。
|
|
184
|
+
- Svelte:头像内容里弹层中的 Avatar 不继承 AvatarGroup 的 `size`、`shape`,也不是列表项。
|
|
185
|
+
- Svelte:TagInput 的 `value`、`inputValue` 可绑定,没有 `defaultValue`,把它们绑成 `undefined` 会清空内部状态(表单重置);回调是 `onChange`、`onInputChange(value, event)`、`onAdd`、`onRemove(value, index)`、`onExceed`、`onInputExceed`、`onFocus`、`onBlur`、`onKeyDown`。
|
|
186
|
+
- Svelte:snippet 有 `prefix`、`suffix`、`insetLabel`、`clearIcon`、`tag({ value, index, onClose })`,`tag` 返回空内容就不渲染该标签,不回落默认标签;`focus()`、`blur()` 经 `bind:this` 调用,没有 `TagInputHandle` 类型;`restTagsPopoverProps` 的类型去掉了 `content`、`child`、`children`。
|
|
187
|
+
- Svelte:`id`、`name`、`role`、`tabindex` 与全部 `aria-*` 落在内部 `<input>`(根元素是 `role="group"`),根元素上的 `onclick` 与组件自己的点击处理组合调用。
|
|
188
|
+
- Svelte:AutoComplete 的 `value` 可绑定,没有 `defaultValue`;`renderItem`、`triggerRender` 改为 `item`、`trigger` snippet(`trigger` 参数不含 `componentProps`),`prefix`、`suffix`、`insetLabel`、`clearIcon`、`emptyContent` 为 snippet,`insetLabel` 只要传了 snippet 就当作有内容。
|
|
189
|
+
- Svelte:回调为 `onChange`、`onSearch`、`onSelect`、`onClear`、`onFocus`、`onBlur`、`onDropdownVisibleChange`;`focus()`、`blur()`、`getNativeElement()` 经 `bind:this` 调用;数据项的 `class` 接受 clsx 值,`style` 与 `styles` 的值只接受字符串;`id`、`name`、`aria-*` 落在输入框,用 `trigger` 时 `id` 落在根元素。
|
|
190
|
+
- Avatar:`size`、`gap` 变化后重算文字缩放。
|
|
191
|
+
- 破坏性(类型):Avatar 图片加载失败时 `onError` 收到 error 事件,返回 `false` 保留破图:React 为 `(event: SyntheticEvent<HTMLImageElement>) => boolean | void`,Vue、Svelte 为 `(event: Event) => boolean | void`,Solid 的事件带 `currentTarget: HTMLImageElement`。
|
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
# Radio
|
|
2
|
+
|
|
3
|
+
> Radio component allows the user to select one option from a relative small set.
|
|
4
|
+
|
|
5
|
+
Package: `@fibrae/semi-ui-svelte`. Web page: https://semi-design-next.pages.dev/en-US/svelte/input/radio/
|
|
6
|
+
|
|
7
|
+
## When to use
|
|
8
|
+
|
|
9
|
+
- Used to select a single state among multiple options.
|
|
10
|
+
- The difference from Select is that all available options in Radio are visible by default, making it easier for users to choose in comparison, so there should not be too many options.
|
|
11
|
+
|
|
12
|
+
## Demos
|
|
13
|
+
|
|
14
|
+
### How to import
|
|
15
|
+
|
|
16
|
+
```svelte
|
|
17
|
+
<script lang="ts">
|
|
18
|
+
import { Radio, RadioGroup } from '@fibrae/semi-ui-svelte';
|
|
19
|
+
</script>
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
### Basic Usage
|
|
23
|
+
|
|
24
|
+
```svelte
|
|
25
|
+
<script lang="ts">
|
|
26
|
+
import { Radio } from '@fibrae/semi-ui-svelte';
|
|
27
|
+
</script>
|
|
28
|
+
|
|
29
|
+
<Radio aria-label="单选示例" name="demo-radio">Radio</Radio>
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### Extra Info
|
|
33
|
+
|
|
34
|
+
You can use the `extra` snippet to add extra information: define it inside the Radio tag with `{#snippet extra()}...{/snippet}`, and the rest of the content is the label. It can hold any content.
|
|
35
|
+
|
|
36
|
+
```svelte
|
|
37
|
+
<script lang="ts">
|
|
38
|
+
import { Radio } from '@fibrae/semi-ui-svelte';
|
|
39
|
+
</script>
|
|
40
|
+
|
|
41
|
+
<Radio aria-label="单选示例" name="demo-radio-extra">
|
|
42
|
+
Semi Design
|
|
43
|
+
{#snippet extra()}Semi Design Next 是 Semi Design 的社区版设计系统,一套组件在 React、Vue、Solid、Svelte 中原生可用{/snippet}
|
|
44
|
+
</Radio>
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### Disabled
|
|
48
|
+
|
|
49
|
+
```svelte
|
|
50
|
+
<script lang="ts">
|
|
51
|
+
import { Button, Radio } from '@fibrae/semi-ui-svelte';
|
|
52
|
+
|
|
53
|
+
let disabled = $state(true);
|
|
54
|
+
</script>
|
|
55
|
+
|
|
56
|
+
<div>
|
|
57
|
+
<Radio aria-label="单选示例" checked={false} {disabled} name="demo-radio-disabled">Disabled</Radio>
|
|
58
|
+
<br />
|
|
59
|
+
<Radio aria-label="单选示例" checked {disabled} name="demo-radio-defaultChecked-disabled">Disabled</Radio>
|
|
60
|
+
<div style="margin-top: 20px">
|
|
61
|
+
<Button type="primary" onclick={() => (disabled = !disabled)}>Toggle disabled</Button>
|
|
62
|
+
</div>
|
|
63
|
+
</div>
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### Advanced Mode
|
|
67
|
+
|
|
68
|
+
You can set `mode='advanced'` to allow options be able to unchecked when clicked again.
|
|
69
|
+
|
|
70
|
+
```svelte
|
|
71
|
+
<script lang="ts">
|
|
72
|
+
import { Radio, type RadioChangeEvent } from '@fibrae/semi-ui-svelte';
|
|
73
|
+
|
|
74
|
+
let checked = $state(true);
|
|
75
|
+
const onChange = (e: RadioChangeEvent) => console.log('radio checked', e.target.checked);
|
|
76
|
+
</script>
|
|
77
|
+
|
|
78
|
+
<Radio aria-label="单选示例" bind:checked mode="advanced" name="demo-radio-advanced" {onChange}>允许取消选择</Radio>
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Mutually Exclusive Set
|
|
82
|
+
|
|
83
|
+
You can use `RadioGroup` to create a set of mutually exclusive options.
|
|
84
|
+
|
|
85
|
+
```svelte
|
|
86
|
+
<script lang="ts">
|
|
87
|
+
import { Radio, RadioGroup, type RadioChangeEvent, type RadioValue } from '@fibrae/semi-ui-svelte';
|
|
88
|
+
|
|
89
|
+
let value = $state<RadioValue | undefined>(1);
|
|
90
|
+
const onChange = (e: RadioChangeEvent) => console.log('radio checked', e.target.value);
|
|
91
|
+
</script>
|
|
92
|
+
|
|
93
|
+
<RadioGroup aria-label="单选组合示例" bind:value name="demo-radio-group" {onChange}>
|
|
94
|
+
<Radio value={1}>A</Radio>
|
|
95
|
+
<Radio value={2}>B</Radio>
|
|
96
|
+
<Radio value={3}>C</Radio>
|
|
97
|
+
<Radio value={4}>D</Radio>
|
|
98
|
+
</RadioGroup>
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### vertical arrangement
|
|
102
|
+
|
|
103
|
+
The radio elements in the group can be arranged horizontally or vertically by setting the `direction` property to the RadioGroup
|
|
104
|
+
|
|
105
|
+
```svelte
|
|
106
|
+
<script lang="ts">
|
|
107
|
+
import { Radio, RadioGroup } from '@fibrae/semi-ui-svelte';
|
|
108
|
+
</script>
|
|
109
|
+
|
|
110
|
+
<RadioGroup aria-label="单选组合示例" direction="vertical" name="demo-radio-group-vertical">
|
|
111
|
+
<Radio value={1}>A</Radio>
|
|
112
|
+
<Radio value={2}>B</Radio>
|
|
113
|
+
<Radio value={3}>C</Radio>
|
|
114
|
+
<Radio value={4}>D</Radio>
|
|
115
|
+
</RadioGroup>
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### Button Style
|
|
119
|
+
|
|
120
|
+
You can use `type='button'` to set the button style type radio, and the button type radio supports three sizes.
|
|
121
|
+
|
|
122
|
+
It should be noted that the button type radio selector does not support auxiliary text (`extra`) and vertical arrangement (`direction='vertical'`).
|
|
123
|
+
|
|
124
|
+
```svelte
|
|
125
|
+
<script lang="ts">
|
|
126
|
+
import { Radio, RadioGroup, Space } from '@fibrae/semi-ui-svelte';
|
|
127
|
+
|
|
128
|
+
const sizes = ['small', 'middle', 'large'] as const;
|
|
129
|
+
</script>
|
|
130
|
+
|
|
131
|
+
<Space align="start" spacing="loose" vertical>
|
|
132
|
+
{#each sizes as size (size)}
|
|
133
|
+
<RadioGroup aria-label="单选组合示例" buttonSize={size} name={`demo-radio-${size}`} type="button" value={1}>
|
|
134
|
+
<Radio value={1}>即时推送</Radio>
|
|
135
|
+
<Radio value={2}>定时推送</Radio>
|
|
136
|
+
<Radio value={3}>动态推送</Radio>
|
|
137
|
+
</RadioGroup>
|
|
138
|
+
{/each}
|
|
139
|
+
</Space>
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### Card Style
|
|
143
|
+
|
|
144
|
+
You can set `type='card'` to `RadioGroup` to achieve card style with background.
|
|
145
|
+
|
|
146
|
+
```svelte
|
|
147
|
+
<script lang="ts">
|
|
148
|
+
import { Radio, RadioGroup } from '@fibrae/semi-ui-svelte';
|
|
149
|
+
|
|
150
|
+
const extraText = 'Semi Design Next 是 Semi Design 的社区版设计系统,一套组件在 React、Vue、Solid、Svelte 中原生可用';
|
|
151
|
+
</script>
|
|
152
|
+
|
|
153
|
+
<RadioGroup aria-label="单选组合示例" direction="vertical" name="demo-radio-group-card" type="card" value={2}>
|
|
154
|
+
<Radio disabled style="width: 280px" value={1}>
|
|
155
|
+
单选框标题
|
|
156
|
+
{#snippet extra()}{extraText}{/snippet}
|
|
157
|
+
</Radio>
|
|
158
|
+
<Radio style="width: 280px" value={2}>
|
|
159
|
+
单选框标题
|
|
160
|
+
{#snippet extra()}{extraText}{/snippet}
|
|
161
|
+
</Radio>
|
|
162
|
+
<Radio style="width: 280px" value={3}>
|
|
163
|
+
单选框标题
|
|
164
|
+
{#snippet extra()}{extraText}{/snippet}
|
|
165
|
+
</Radio>
|
|
166
|
+
</RadioGroup>
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
### Pure Card Style
|
|
170
|
+
|
|
171
|
+
You can set `type='pureCard'` to `RadioGroup` to achieve a pure card style with background and no radio.
|
|
172
|
+
|
|
173
|
+
```svelte
|
|
174
|
+
<script lang="ts">
|
|
175
|
+
import { Radio, RadioGroup } from '@fibrae/semi-ui-svelte';
|
|
176
|
+
|
|
177
|
+
const extraText = 'Semi Design Next 是 Semi Design 的社区版设计系统,一套组件在 React、Vue、Solid、Svelte 中原生可用';
|
|
178
|
+
</script>
|
|
179
|
+
|
|
180
|
+
<RadioGroup aria-label="单选组合示例" direction="vertical" name="demo-radio-group-pureCard" type="pureCard" value={2}>
|
|
181
|
+
<Radio disabled style="width: 280px" value={1}>
|
|
182
|
+
单选框标题
|
|
183
|
+
{#snippet extra()}{extraText}{/snippet}
|
|
184
|
+
</Radio>
|
|
185
|
+
<Radio style="width: 280px" value={2}>
|
|
186
|
+
单选框标题
|
|
187
|
+
{#snippet extra()}{extraText}{/snippet}
|
|
188
|
+
</Radio>
|
|
189
|
+
<Radio style="width: 280px" value={3}>
|
|
190
|
+
单选框标题
|
|
191
|
+
{#snippet extra()}{extraText}{/snippet}
|
|
192
|
+
</Radio>
|
|
193
|
+
</RadioGroup>
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
### Options Configuration
|
|
197
|
+
|
|
198
|
+
You can pass an array of options to `RadioGroup` using `options` property to create a set.
|
|
199
|
+
|
|
200
|
+
```svelte
|
|
201
|
+
<script lang="ts">
|
|
202
|
+
import { RadioGroup, Space, type RadioChangeEvent, type RadioValue } from '@fibrae/semi-ui-svelte';
|
|
203
|
+
|
|
204
|
+
let value1 = $state<RadioValue | undefined>('Guest');
|
|
205
|
+
let value2 = $state<RadioValue | undefined>('Developer');
|
|
206
|
+
let value3 = $state<RadioValue | undefined>('Maintainer');
|
|
207
|
+
const plainOptions = ['Guest', 'Developer', 'Maintainer'];
|
|
208
|
+
const options = [
|
|
209
|
+
{ label: 'Guest', value: 'Guest', extra: 'Semi Design', style: 'width: 120px' },
|
|
210
|
+
{ label: 'Developer', value: 'Developer', extra: 'Semi Design', style: 'width: 120px' },
|
|
211
|
+
{ label: 'Maintainer', value: 'Maintainer', extra: 'Semi Design', style: 'width: 120px' },
|
|
212
|
+
];
|
|
213
|
+
const optionsWithDisabled = [
|
|
214
|
+
{ label: 'Guest', value: 'Guest' },
|
|
215
|
+
{ label: 'Developer', value: 'Developer' },
|
|
216
|
+
{ label: 'Maintainer', value: 'Maintainer', disabled: true },
|
|
217
|
+
];
|
|
218
|
+
|
|
219
|
+
const onChange1 = (e: RadioChangeEvent) => console.log('radio1 checked', e.target.value);
|
|
220
|
+
const onChange2 = (e: RadioChangeEvent) => console.log('radio2 checked', e.target.value);
|
|
221
|
+
const onChange3 = (e: RadioChangeEvent) => console.log('radio3 checked', e.target.value);
|
|
222
|
+
</script>
|
|
223
|
+
|
|
224
|
+
<Space align="start" spacing="loose" vertical>
|
|
225
|
+
<RadioGroup aria-label="单选组合示例" bind:value={value1} name="demo-radio-group-1" onChange={onChange1} options={plainOptions} />
|
|
226
|
+
<RadioGroup aria-label="单选组合示例" bind:value={value2} name="demo-radio-group-2" onChange={onChange2} options={optionsWithDisabled} />
|
|
227
|
+
<RadioGroup aria-label="单选组合示例" bind:value={value3} name="demo-radio-group-3" onChange={onChange3} {options} />
|
|
228
|
+
</Space>
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
## API Reference
|
|
232
|
+
|
|
233
|
+
### Radio
|
|
234
|
+
|
|
235
|
+
**Props**
|
|
236
|
+
|
|
237
|
+
| Property | Description | Type | Default |
|
|
238
|
+
| - | - | - | - |
|
|
239
|
+
| addonId | Id of the addon node, which aria-labelledby points to. Generated when omitted. | `string` | - |
|
|
240
|
+
| checked | Whether the radio is checked; bind it with `bind:checked`. Ignored inside a RadioGroup. `bind:checked={get, set}` makes it fully controlled; a plain `checked` is the initial value, a click overrides it inside the component, and a new value from the parent wins again. | `boolean` | - |
|
|
241
|
+
| children | Label content snippet of the radio. The rest of the tag's content is this snippet. | `Snippet` | - |
|
|
242
|
+
| classNames | Class names of the inner parts, keyed by addon (the container wrapping the content); values take anything class takes (string, array or object) and merge with the built-in classes. | `Partial<Record<RadioPart, ClassValue>>` | - |
|
|
243
|
+
| disabled | Whether the radio is disabled. | `boolean` | - |
|
|
244
|
+
| displayMode | When set to vertical, the radio is displayed as a block and takes a line of its own. | `RadioDisplayMode` | - |
|
|
245
|
+
| extra | Snippet of the supplementary text, which aria-describedby points to. Not rendered when type is button. | `Snippet` | - |
|
|
246
|
+
| extraId | Id of the extra node, which aria-describedby points to. Generated when omitted. | `string` | - |
|
|
247
|
+
| mode | When set to advanced, a checked radio can be unchecked by clicking it or pressing Space. Inside a RadioGroup the group's mode applies. | `RadioMode` | `""` |
|
|
248
|
+
| onChange | Called when the checked state changes. The event's `target` is `{ checked, value, name, disabled }`. | `(event: RadioChangeEvent) => void` | - |
|
|
249
|
+
| preventScroll | Whether focusing prevents the browser from scrolling the element into view; applies to the focus method. | `boolean` | - |
|
|
250
|
+
| styles | Style strings of the inner parts, keyed like classNames. | `Partial<Record<RadioPart, string>>` | - |
|
|
251
|
+
| type | Style type: default, button, card or pureCard. Inside a RadioGroup the group's type applies. | `RadioType` | `"default"` |
|
|
252
|
+
| value | The radio's value, which a RadioGroup compares to decide whether it is checked. It is also the native input's value in form submission. | `RadioValue` | - |
|
|
253
|
+
|
|
254
|
+
**Methods**
|
|
255
|
+
|
|
256
|
+
| Method | Description | Type |
|
|
257
|
+
| - | - | - |
|
|
258
|
+
| blur | Removes focus from the native input. | `() => void` |
|
|
259
|
+
| focus | Focuses the native input. | `() => void` |
|
|
260
|
+
|
|
261
|
+
`class` and `style` (a string) land on the root label element. `id`, `name`, `tabindex`, `autofocus`, `aria-*`, `onfocus` and `onblur` land on the inner native input; other native attributes and events (such as `onmouseenter` and `onmouseleave`) land on the root element, and `onclick` is also on the root element but is called once, and only when the click lands on the input. `checked` supports `bind:`, a function binding, a one-way value, or nothing, and there is no `defaultChecked`. `extra` is not rendered for the button type.
|
|
262
|
+
|
|
263
|
+
### RadioGroup
|
|
264
|
+
|
|
265
|
+
**Props**
|
|
266
|
+
|
|
267
|
+
| Property | Description | Type | Default |
|
|
268
|
+
| - | - | - | - |
|
|
269
|
+
| buttonSize | Button size when type is button: small, middle or large. | `RadioGroupButtonSize` | `"middle"` |
|
|
270
|
+
| children | Radio components in the group. Ignored when options is set. | `Snippet` | - |
|
|
271
|
+
| direction | Layout direction of the radios: horizontal or vertical. Not supported when type is button. | `RadioDirection` | `"horizontal"` |
|
|
272
|
+
| disabled | Whether the whole group is disabled. | `boolean` | `false` |
|
|
273
|
+
| extra | Snippet for the extra text of each item in options, with the parameter `{ option, index }`. | `Snippet<[RadioGroupOptionSnippetParams]>` | - |
|
|
274
|
+
| label | Snippet for the label of each item in options, with the parameter `{ option, index }`. | `Snippet<[RadioGroupOptionSnippetParams]>` | - |
|
|
275
|
+
| mode | When set to advanced, a checked radio can be unchecked by clicking it or pressing Space, and the selected value becomes undefined. | `RadioMode` | `""` |
|
|
276
|
+
| name | The name of every native input in the group. A unique value is generated per group when omitted. | `string` | - |
|
|
277
|
+
| onBlur | Called when focus leaves the whole group; moving focus between its radios does not call it. | `(event: FocusEvent) => void` | - |
|
|
278
|
+
| onChange | Called when the selected value changes. The event's `target.value` is the new value, or undefined when mode is advanced and the selected radio is unchecked. | `(event: RadioChangeEvent) => void` | - |
|
|
279
|
+
| options | Declares the options as data. Each item is a string or `{ label, value, disabled, extra, class, style, classNames, styles, addonId, extraId }`, where `style` is a string; `classNames` and `styles` are keyed by addon and written like the Radio props of the same name. | `Array<string \| RadioOptionItem>` | - |
|
|
280
|
+
| type | Style type of every Radio in the group: default, button, card or pureCard. | `RadioType` | `"default"` |
|
|
281
|
+
| value | The selected value, matched against each Radio's value; bind it with `bind:value`. `bind:value={get, set}` makes it fully controlled; a plain `value` is the initial value. | `RadioValue` | - |
|
|
282
|
+
|
|
283
|
+
Each item in `options` has the fields `label`, `value`, `disabled`, `extra` (`string | number`), `class`, `style` (a string), `addonId`, `classNames`, `styles` (each part's value is a string) and `extraId`, and no `onChange`. Use the `label` and `extra` snippets, with the parameter `{ option, index }`, for custom content; a button radio does not render `extra`. `class`, `style` (a string), `onBlur` and native attributes land on the root element with `role="radiogroup"`, and so do `aria-required`, `aria-invalid` and `aria-errormessage`; `onBlur` fires only when focus leaves the whole group. The `aria-expanded`, `aria-haspopup`, `aria-controls` and `tabindex` injected by Tooltip are not rendered. `value` supports `bind:`, a function binding, a one-way value, or nothing, and there is no `defaultValue`.
|
|
284
|
+
|
|
285
|
+
## Methods
|
|
286
|
+
|
|
287
|
+
### Radio
|
|
288
|
+
|
|
289
|
+
Call `focus()` and `blur()` on the Radio instance obtained with `bind:this`; they act on the inner native input, and `preventScroll` applies to `focus()`. See Methods above.
|
|
290
|
+
|
|
291
|
+
## Accessibility
|
|
292
|
+
|
|
293
|
+
### ARIA
|
|
294
|
+
|
|
295
|
+
- `aria-label`: used to explain the role of Radio or RadioGroup
|
|
296
|
+
- `aria-labelledby` points to the addon node, used to explain the content of Radio
|
|
297
|
+
- `aria-describedby` points to the extra node, which is used to explain the content of Radio
|
|
298
|
+
|
|
299
|
+
* `aria-required`, `aria-invalid` and `aria-errormessage` apply to RadioGroup only and are set on the `role="radiogroup"` element. ARIA does not support them on a single Radio; when both `aria-invalid` and `aria-errormessage` are passed to it, the error message is linked to the input through `aria-describedby`
|
|
300
|
+
|
|
301
|
+
### Keyboard and focus
|
|
302
|
+
|
|
303
|
+
WAI-ARIA: <https://www.w3.org/WAI/ARIA/apg/patterns/radiobutton/>
|
|
304
|
+
|
|
305
|
+
- RadioGroup can be focused, the initial focus acquisition rules are as follows:
|
|
306
|
+
- When there is no selected item in the RadioGroup, the initial focus is on the first Radio item;
|
|
307
|
+
- When there are selected items in the RadioGroup, the initial focus is on the selected Radio item.
|
|
308
|
+
- For radios belonging to the same radiogroup:
|
|
309
|
+
- You can use `Right arrow` or `Down arrow` to move the focus to the next Radio item, uncheck the previously focused Radio item, and select the currently focused Radio item;
|
|
310
|
+
- You can Use `Left Arrow` or `Up Arrow` to move the focus to the previous Radio item, at the same time uncheck the previously focused Radio item, and select the currently focused Radio item.
|
|
311
|
+
- If there is no item selected in the RadioGroup, you can use the `Space` key to select the initial focus.
|
|
312
|
+
- `mode="advanced"` is still a radio: arrow keys move the selection as usual, and clicking the selected item or pressing `Space` on it unchecks it.
|
|
313
|
+
|
|
314
|
+
## Content Guidelines
|
|
315
|
+
|
|
316
|
+
- Capitalize the first letter
|
|
317
|
+
- No punctuation
|
|
318
|
+
|
|
319
|
+
## Design Tokens
|
|
320
|
+
|
|
321
|
+
The design token table of this component is on the web page: <https://semi-design-next.pages.dev/en-US/svelte/input/radio/>
|
|
322
|
+
|
|
323
|
+
## Changes from Semi Design
|
|
324
|
+
|
|
325
|
+
From the project release notes (written in Chinese). Your knowledge of Semi Design does not cover these.
|
|
326
|
+
|
|
327
|
+
- 破坏性:Radio 与 RadioGroup 删除 `addonClassName`、`addonStyle`,`options` 项删除 `addonClassName`(Vue、Solid、Svelte 为 `addonClass`)、`addonStyle`,改用 `classNames.addon`、`styles.addon`,落在 addon 容器上;`options` 项上的同名字段由 RadioGroup 下发给 Radio。
|
|
328
|
+
- 破坏性:Radio `mode="advanced"` 的 input 由 `type="checkbox"` 改回 `type="radio"`,按 `checkbox` 查询的测试需改为 `radio`;Checkbox、Radio 的 `onChange` 事件 `target` 在四个框架都只有 `{ checked, value, name, disabled }`,不再展开组件 props(原 Semi 为全部 props 加 `checked`);删除 `semi-radio-focus`、`semi-radio-focus-border` 等焦点与悬停类名,改用 CSS `:focus-visible`、`:hover`。
|
|
329
|
+
- 破坏性(类型):CheckboxGroup 的 `options` 收窄为 `Array<string | CheckboxOptionItem>`,`value`、`defaultValue`、`onChange` 参数收窄为 `Array<string | number | boolean>`,新增 `CheckboxOptionItem`;`RadioInnerProps` 不再含 `style`、`className`、`children`、`preventScroll`,新增 `id`、`value`。未传 `name` 时每组生成唯一 name,RadioGroup 内没有 `value` 的 Radio 在组值为 `undefined` 时不再判为选中。
|
|
330
|
+
- 行为变化:Radio 的 `checked` 与 `defaultChecked` 同传时取 `checked`,`checked={false}` 时内部状态不再被 `defaultChecked` 置为选中。
|
|
331
|
+
- Solid 破坏性(类型):RadioGroup `options` 项的 `label`、`extra` 收窄为 `string | number`(同 Vue),其他内容由 RadioGroup 新增的 `renderLabel(option, index)`、`renderExtra(option, index)` 提供(对应 Vue 的 `#label`、`#extra`),按钮型不调用 `renderExtra`;AIChatInput 的 `Configure.RadioButton` 同样适用。
|
|
332
|
+
- Svelte:Radio 的 `checked` 与 RadioGroup 的 `value` 可绑定,支持 `bind:`、函数绑定、单向传值、不传四种写法,不提供 `defaultChecked`、`defaultValue`,全局默认值也不能设 `value`、`checked`;`onChange(event)` 的 `target` 为 `{ checked, value, name, disabled }`。
|
|
333
|
+
- Svelte:RadioGroup 保留 `options`,自定义内容用 `label`、`extra` snippet(参数 `{ option, index }`),Radio 的 `children`、`extra` 是 snippet;`Radio.Group` 与具名导出 `RadioGroup` 是同一组件;`style`、`styles` 的值及选项里的同名字段只接受字符串。
|
|
334
|
+
- Svelte:根元素透传的是 `onclick`,只在点击落在 input 上时调用一次;`onBlur` 在焦点离开整个分组时触发;`focus()`、`blur()` 经 `bind:this` 调用。
|
|
335
|
+
- 行为变化:RadioGroup 内的 Radio 一律使用组的 `name`,Radio 自己的 `name` 不再生效(原来 Radio 的优先,设了不同 `name` 的 Radio 会脱离组的方向键导航),与 CheckboxGroup、Ant Design 一致。
|
|
336
|
+
- Vue(类型):RadioGroup 改为泛型 `RadioGroup<T extends RadioValue>`,`modelValue`、`defaultValue` 与 `update:modelValue` 的参数取 `T`,字面量联合类型的 ref 可直接 `v-model`;`RadioGroupProps`、`RadioGroupEmits` 带同名类型参数(默认 `RadioValue`),FormRadioGroup 随之泛型。
|
|
337
|
+
- 破坏性(类型):Checkbox、Radio 的 `onChange` 事件 `target` 中 `value`、`name` 改为可选属性(`value?: T`、`name?: string`),四个框架与 foundation 的 `RadioChangeEvent`、`BasicTargetObject` 一致;手写成必填属性的回调参数类型需改为可选或直接用导出的事件类型。
|