@fibrae/semi-ui-svelte 0.9.0 → 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/cascader.svelte +1 -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/form/label.svelte +2 -2
- 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/tooltip/tooltip.svelte +3 -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/dist/styles.css +1 -1
- 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,347 @@
|
|
|
1
|
+
# Slider
|
|
2
|
+
|
|
3
|
+
> Selector to quickly select a number or range of values using drag interaction, more intuitive than InputNumber
|
|
4
|
+
|
|
5
|
+
Package: `@fibrae/semi-ui-svelte`. Web page: https://semi-design-next.pages.dev/en-US/svelte/input/slider/
|
|
6
|
+
|
|
7
|
+
## Demos
|
|
8
|
+
|
|
9
|
+
### How to import
|
|
10
|
+
|
|
11
|
+
```svelte
|
|
12
|
+
<script lang="ts">
|
|
13
|
+
import { Button, InputNumber, Slider } from '@fibrae/semi-ui-svelte';
|
|
14
|
+
</script>
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
### Basic Usage
|
|
18
|
+
|
|
19
|
+
Basic slider. When `range` is `true`, both ends can be dragged. When `disabled` is `true`, the slider is unavailable.
|
|
20
|
+
|
|
21
|
+
```svelte
|
|
22
|
+
<script lang="ts">
|
|
23
|
+
import { Slider } from '@fibrae/semi-ui-svelte';
|
|
24
|
+
</script>
|
|
25
|
+
|
|
26
|
+
<div>
|
|
27
|
+
<div>
|
|
28
|
+
<div>默认</div>
|
|
29
|
+
<Slider aria-label="默认滑动输入条" showBoundary />
|
|
30
|
+
</div>
|
|
31
|
+
<br />
|
|
32
|
+
<br />
|
|
33
|
+
<div>
|
|
34
|
+
<div>范围</div>
|
|
35
|
+
<Slider aria-label="范围滑动输入条" range value={[20, 60]} />
|
|
36
|
+
</div>
|
|
37
|
+
<br />
|
|
38
|
+
<br />
|
|
39
|
+
<div>
|
|
40
|
+
<div>禁用</div>
|
|
41
|
+
<Slider aria-label="禁用滑动输入条" disabled value={40} />
|
|
42
|
+
</div>
|
|
43
|
+
</div>
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### With Input
|
|
47
|
+
|
|
48
|
+
Synchronize slider with input value.
|
|
49
|
+
|
|
50
|
+
```svelte
|
|
51
|
+
<script lang="ts">
|
|
52
|
+
import { InputNumber, Slider } from '@fibrae/semi-ui-svelte';
|
|
53
|
+
|
|
54
|
+
let value = $state(10);
|
|
55
|
+
|
|
56
|
+
const getSliderValue = (newValue: number | string | number[]) => {
|
|
57
|
+
if (isNaN(Number(newValue))) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
value = Number(newValue);
|
|
61
|
+
};
|
|
62
|
+
</script>
|
|
63
|
+
|
|
64
|
+
<div>
|
|
65
|
+
<div style="width: 320px; margin-inline-end: 15px">
|
|
66
|
+
<Slider aria-label="数值" onChange={getSliderValue} step={1} {value} />
|
|
67
|
+
</div>
|
|
68
|
+
<InputNumber aria-label="数值" max={100} min={0} onChange={getSliderValue} style="width: 100px" {value} />
|
|
69
|
+
</div>
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### Tooltip
|
|
73
|
+
|
|
74
|
+
Use `tipFormatter` to format the Tooltip content, or pass `null` to hide the Tooltip. `getAriaValueText` gives the current value a user-friendly name, which matters to screen reader users.
|
|
75
|
+
|
|
76
|
+
Use the `tip` snippet when the tooltip needs node content; in its parameter `{ value, handle }`, `value` is the result of `tipFormatter` and `handle` is `min` or `max`.
|
|
77
|
+
|
|
78
|
+
```svelte
|
|
79
|
+
<script lang="ts">
|
|
80
|
+
import { Slider } from '@fibrae/semi-ui-svelte';
|
|
81
|
+
|
|
82
|
+
const formatPercent = (value: number) => `${value}%`;
|
|
83
|
+
</script>
|
|
84
|
+
|
|
85
|
+
<div>
|
|
86
|
+
<Slider aria-label="带提示的滑块" getAriaValueText={formatPercent} tipFormatter={formatPercent} />
|
|
87
|
+
<br />
|
|
88
|
+
<br />
|
|
89
|
+
<Slider aria-label="不带提示的滑块" tipFormatter={null} />
|
|
90
|
+
</div>
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### With Tag
|
|
94
|
+
|
|
95
|
+
Use `marks` to label measures on sliders, and `value` to set the handle position. Mark labels accept only strings or numbers; use the `mark` snippet, with the parameter `{ value, label }`, when a label needs node content. It is rendered once for the label and once for the tooltip when `tooltipOnMark` is on.
|
|
96
|
+
|
|
97
|
+
```svelte
|
|
98
|
+
<script lang="ts">
|
|
99
|
+
import { Slider } from '@fibrae/semi-ui-svelte';
|
|
100
|
+
|
|
101
|
+
const stepTenMarks = { 0: '0', 10: '10', 20: '20', 30: '30', 40: '40', 50: '50', 100: '100' };
|
|
102
|
+
const stepTenthMarks = { 0.1: '0.1', 0.2: '0.2', 0.3: '0.3', 0.4: '0.4', 0.5: '0.5' };
|
|
103
|
+
const celsiusMarks = { 20: '20°C', 40: '40°C' };
|
|
104
|
+
const formatCelsius = (value: number) => `${value}°C`;
|
|
105
|
+
</script>
|
|
106
|
+
|
|
107
|
+
<div>
|
|
108
|
+
<div id="slider-marks-step-10">step=10</div>
|
|
109
|
+
<Slider aria-labelledby="slider-marks-step-10" marks={stepTenMarks} range step={10} value={[10, 100]} />
|
|
110
|
+
<br />
|
|
111
|
+
<br />
|
|
112
|
+
<div id="slider-marks-step-01">step=0.1</div>
|
|
113
|
+
<Slider aria-labelledby="slider-marks-step-01" marks={stepTenthMarks} max={1} min={0} range step={0.1} value={[0.1, 0.5]} />
|
|
114
|
+
<br />
|
|
115
|
+
<br />
|
|
116
|
+
<div id="slider-marks-marks">Marks</div>
|
|
117
|
+
<Slider aria-labelledby="slider-marks-marks" getAriaValueText={formatCelsius} marks={celsiusMarks} range tipFormatter={formatCelsius} value={[0, 100]} />
|
|
118
|
+
<br />
|
|
119
|
+
<br />
|
|
120
|
+
<div id="slider-marks-included">Included</div>
|
|
121
|
+
<Slider aria-labelledby="slider-marks-included" getAriaValueText={formatCelsius} included={false} marks={celsiusMarks} range tipFormatter={formatCelsius} value={[0, 100]} />
|
|
122
|
+
</div>
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### Segmented Background
|
|
126
|
+
|
|
127
|
+
To create a slider with segmented background, you could use CSS property `linear-gradient` for `styles.rail` (a string) along with `bind:value` to change background dynamically.
|
|
128
|
+
|
|
129
|
+
```svelte
|
|
130
|
+
<script lang="ts">
|
|
131
|
+
import { Slider } from '@fibrae/semi-ui-svelte';
|
|
132
|
+
|
|
133
|
+
const range = [10, 100];
|
|
134
|
+
|
|
135
|
+
const getRailStyle = (value: number[]) => {
|
|
136
|
+
// transparent lets the middle segment show the track color
|
|
137
|
+
const color = ['var(--semi-color-danger)', 'transparent', 'var(--semi-color-success)'];
|
|
138
|
+
const gradientPos = value.map((val) => Number(((val - range[0]) / (range[1] - range[0])).toFixed(2)) * 100);
|
|
139
|
+
return `background: linear-gradient(to right, ${color[0]} ${gradientPos[0]}%, ${color[1]} ${gradientPos[0]}%, ${color[1]} ${gradientPos[1]}%, ${color[2]} ${gradientPos[1]}%)`;
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
let value = $state([20, 60]);
|
|
143
|
+
|
|
144
|
+
const changeValue = (newValue: number | number[]) => {
|
|
145
|
+
if (Array.isArray(newValue)) {
|
|
146
|
+
value = newValue;
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
const railStyle = $derived(getRailStyle(value));
|
|
151
|
+
</script>
|
|
152
|
+
|
|
153
|
+
<Slider aria-label="Value range" max={range[1]} min={range[0]} onChange={changeValue} range styles={{ rail: railStyle }} {value} />
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
### Controlled Component
|
|
157
|
+
|
|
158
|
+
The handle position is the Slider's `value`; keep it in sync with a `$state` variable through `bind:value`. To refuse or rewrite a drag result, use a function binding `bind:value={() => value, (next) => { ... }}`. A plain `value` without a binding is only the initial value, and a new value from the parent wins again.
|
|
159
|
+
|
|
160
|
+
```svelte
|
|
161
|
+
<script lang="ts">
|
|
162
|
+
import { Button, Slider } from '@fibrae/semi-ui-svelte';
|
|
163
|
+
|
|
164
|
+
let value = $state<number | number[]>(10);
|
|
165
|
+
|
|
166
|
+
const changeValue = () => {
|
|
167
|
+
value = Number(value) + 10;
|
|
168
|
+
};
|
|
169
|
+
</script>
|
|
170
|
+
|
|
171
|
+
<div>
|
|
172
|
+
<Button style="margin-inline-end: 20px" onclick={changeValue}>点击改变value值</Button>
|
|
173
|
+
<br />
|
|
174
|
+
<br />
|
|
175
|
+
<Slider aria-label="受控滑块" bind:value />
|
|
176
|
+
</div>
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
### Vertical
|
|
180
|
+
|
|
181
|
+
```svelte
|
|
182
|
+
<script lang="ts">
|
|
183
|
+
import { Slider } from '@fibrae/semi-ui-svelte';
|
|
184
|
+
|
|
185
|
+
const boxStyle = 'height: 300px; margin-inline-start: 30px; margin-block-start: 10px; padding-inline-end: 30px; display: inline-block';
|
|
186
|
+
const marks = { 20: '20°C', 40: '40°C' };
|
|
187
|
+
</script>
|
|
188
|
+
|
|
189
|
+
<div>
|
|
190
|
+
<div style={boxStyle}>
|
|
191
|
+
<Slider aria-label="Vertical slider" vertical />
|
|
192
|
+
</div>
|
|
193
|
+
<div style={boxStyle}>
|
|
194
|
+
<Slider aria-label="Reversed vertical slider" vertical verticalReverse />
|
|
195
|
+
</div>
|
|
196
|
+
<div style={boxStyle}>
|
|
197
|
+
<Slider aria-label="Vertical range slider" range value={[20, 60]} vertical />
|
|
198
|
+
</div>
|
|
199
|
+
<div style={boxStyle}>
|
|
200
|
+
<Slider aria-label="Reversed vertical range slider" range value={[20, 60]} vertical verticalReverse />
|
|
201
|
+
</div>
|
|
202
|
+
<div style={boxStyle}>
|
|
203
|
+
<Slider aria-label="Vertical range slider with marks" {marks} range step={10} value={[20, 60]} vertical />
|
|
204
|
+
</div>
|
|
205
|
+
<div style={boxStyle}>
|
|
206
|
+
<Slider aria-label="Reversed vertical range slider with marks" {marks} range step={10} value={[20, 60]} vertical verticalReverse />
|
|
207
|
+
</div>
|
|
208
|
+
</div>
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
### Handle with dot
|
|
212
|
+
|
|
213
|
+
```svelte
|
|
214
|
+
<script lang="ts">
|
|
215
|
+
import { Slider } from '@fibrae/semi-ui-svelte';
|
|
216
|
+
</script>
|
|
217
|
+
|
|
218
|
+
<div>
|
|
219
|
+
<div>
|
|
220
|
+
<div id="slider-handle-dot-default">Default</div>
|
|
221
|
+
<Slider aria-labelledby="slider-handle-dot-default" handleDot={{ size: '4px', color: 'blue' }} showBoundary />
|
|
222
|
+
</div>
|
|
223
|
+
<br />
|
|
224
|
+
<br />
|
|
225
|
+
<div>
|
|
226
|
+
<div id="slider-handle-dot-range">Range</div>
|
|
227
|
+
<Slider
|
|
228
|
+
aria-labelledby="slider-handle-dot-range"
|
|
229
|
+
handleDot={[
|
|
230
|
+
{ size: '4px', color: 'blue' },
|
|
231
|
+
{ size: '4px', color: 'pink' },
|
|
232
|
+
]}
|
|
233
|
+
range
|
|
234
|
+
value={[20, 60]}
|
|
235
|
+
/>
|
|
236
|
+
</div>
|
|
237
|
+
</div>
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
## API Reference
|
|
241
|
+
|
|
242
|
+
**Props**
|
|
243
|
+
|
|
244
|
+
| Property | Description | Type | Default |
|
|
245
|
+
| - | - | - | - |
|
|
246
|
+
| aria-label | Accessible name of the handle. In range mode, the locale's start and end texts are appended for the two handles. | `string \| null` | - |
|
|
247
|
+
| aria-labelledby | The id of the labelling element, used as the handle's accessible name. In range mode each handle adds its start or end text. | `string \| null` | - |
|
|
248
|
+
| aria-valuetext | A user-friendly name for the current value. | `string \| null` | - |
|
|
249
|
+
| classNames | Class names of the inner parts, keyed by rail; values take anything class takes (string, array or object) and merge with the built-in classes. | `Partial<Record<SliderPart, ClassValue>>` | - |
|
|
250
|
+
| disabled | Whether the slider is disabled. | `boolean` | `false` |
|
|
251
|
+
| getAriaValueText | Provides a user-friendly name for the current value, called with the handle's value and its index. | `(value: number, index?: number) => string` | - |
|
|
252
|
+
| handleDot | Dot on the handle: one object for a single handle, an array with one per handle for a range. | `HandleDot \| HandleDot[]` | - |
|
|
253
|
+
| id | Applied to the first handle's input, so a label for focuses that handle. | `string` | - |
|
|
254
|
+
| included | Takes effect when marks is not empty. true makes the marks nested, false makes them independent. | `boolean` | `true` |
|
|
255
|
+
| mark | Snippet for custom mark labels, also used for the tooltipOnMark tooltip. Its parameter is `{ value, label }`, the mark's value and label. | `Snippet<[SliderMarkSnippetProps]>` | - |
|
|
256
|
+
| marks | Marks. Keys are numbers in the closed range \[min, max], values are strings or numbers; use the mark snippet for node content. | `Record<number, string \| number>` | - |
|
|
257
|
+
| max | Maximum value. | `number` | `100` |
|
|
258
|
+
| min | Minimum value. | `number` | `0` |
|
|
259
|
+
| onAfterChange | Called after a change is complete, with the current value. With a bound or one-way `value` it is called on every change in addition to onChange; without `value`, only onChange is called while dragging and this is called once on release. | `(value: number \| number[]) => void` | - |
|
|
260
|
+
| onBlur | Called when focus leaves the whole Slider; moving between the two handles does not call it. | `(event: FocusEvent) => void` | - |
|
|
261
|
+
| onChange | Called when the value changes, with the current value. | `(value: number \| number[]) => void` | - |
|
|
262
|
+
| onFocus | Called when focus enters the Slider. It is the wrapper's focusin, so it is called each time focus moves between handles. | `(event: FocusEvent) => void` | - |
|
|
263
|
+
| onKeyDown | Called for keys on the handle inputs, before the Slider's own handling; `preventDefault()` keeps a value key from moving the handle. | `(event: KeyboardEvent) => void` | - |
|
|
264
|
+
| onMouseUp | Called when the pointer (mouse, touch, pen) dragging a handle is released or cancelled, and when a value key is released. | `(event: PointerEvent \| KeyboardEvent) => void` | - |
|
|
265
|
+
| range | Whether both ends can be dragged. | `boolean` | `false` |
|
|
266
|
+
| showArrow | Whether the tooltip has an arrow. | `boolean` | `true` |
|
|
267
|
+
| showBoundary | Whether to show the maximum and minimum on hover. | `boolean` | `false` |
|
|
268
|
+
| showMarkLabel | Whether to show the mark labels. | `boolean` | `true` |
|
|
269
|
+
| step | Step, counted from min. | `number` | `1` |
|
|
270
|
+
| styles | Style strings of the inner parts, keyed by rail. | `Partial<Record<SliderPart, string>>` | - |
|
|
271
|
+
| tip | Snippet for custom handle tooltip content. Its parameter is `{ value, handle }`; value is the result of tipFormatter and handle is min or max. | `Snippet<[SliderTipSnippetProps]>` | - |
|
|
272
|
+
| tipFormatter | Format of the tooltip, called once per handle with that handle's value. Shows the current value by default; null hides the tooltip. | `((value: number) => string \| number) \| null` | `(tipValue: number) => tipValue` |
|
|
273
|
+
| tooltipOnMark | Whether the marks on the rail have a tooltip. | `boolean` | `false` |
|
|
274
|
+
| tooltipVisible | Whether the tooltip is always visible. | `boolean` | - |
|
|
275
|
+
| value | Current value; bind it with `bind:value`. `bind:value={get, set}` makes it fully controlled; a plain `value` is the initial value and a new value from the parent wins again; without it the Slider manages the value itself, starting at min. | `number \| number[]` | - |
|
|
276
|
+
| vertical | Whether the slider is vertical. | `boolean` | `false` |
|
|
277
|
+
| verticalReverse | Reverses the vertical direction, so the larger value is on top. | `boolean` | `false` |
|
|
278
|
+
|
|
279
|
+
`class`, `style` (a string) and other native attributes (such as `data-*`) land on `.semi-slider-wrapper`; `onFocus` is its focusin, and `onBlur` is called only when focus leaves the whole Slider. `id` (on the first handle only), `name`, `autofocus`, `aria-describedby`, `aria-invalid`, `aria-errormessage` and `onKeyDown` land on each handle's native input. In `range` mode both inputs share `name` and submit two values in order. `tabindex` and `aria-required` are not rendered. `value` is bindable and there is no `defaultValue`.
|
|
280
|
+
|
|
281
|
+
## RTL/LTR
|
|
282
|
+
|
|
283
|
+
- Slider supports RTL for horizontal direction. You can enable it by setting `direction="rtl"` via [ConfigProvider](../other/config-provider.md).
|
|
284
|
+
- In RTL mode, the minimum value of the horizontal slider is on the right side and the maximum value is on the left side. The drag direction is reversed compared to LTR.
|
|
285
|
+
- Vertical direction (`vertical`) is not affected by RTL.
|
|
286
|
+
- In RTL mode, keyboard arrow keys behavior is mirrored: `Left Arrow` increases the value, `Right Arrow` decreases the value.
|
|
287
|
+
|
|
288
|
+
## Accessibility
|
|
289
|
+
|
|
290
|
+
### ARIA
|
|
291
|
+
|
|
292
|
+
- Each handle holds a visually hidden native `<input type="range">`, which is the real focus and form control (implicit role `slider`); the visible handle only draws the thumb and takes the drag. Query the control with `getByRole('slider')` or `input[type="range"]`, not `.semi-slider-handle`.
|
|
293
|
+
- The input's `value`, `min` and `max` give assistive technology the current, minimum and maximum values. In `range` mode both inputs span the whole slider, and a handle stops where the other one is.
|
|
294
|
+
- If the slider is vertically oriented, the input has `aria-orientation="vertical"` and a `writing-mode: vertical-lr` layout.
|
|
295
|
+
- If the value is not user-friendly, e.g., the day of the week is represented by a number, support setting API `aria-valuetext` property to a string that makes the slider value understandable, e.g., "Monday". And you can use API `getAriaValueText(value, index)` to specify `aria-valuetext`.
|
|
296
|
+
- Supporting API `aria-label` `aria-labelledby` to specify Slider label, or a `<label for>` pointing at `id`: the `id` lands on the first handle's input, and clicking the label focuses that handle.
|
|
297
|
+
- When `disabled`, the locale text no longer overrides the handle's name: the native `disabled` expresses the state, and the name given by `aria-label`, `aria-labelledby` or `<label for>` stays. With no naming at all, a disabled handle has no name, just like an enabled one.
|
|
298
|
+
- In `range` mode each handle has its own name: the locale's "Start" or "End" is appended to `aria-label` (e.g. `Price Start`, `Price End`); with `aria-labelledby`, each handle is named by that label followed by "Start" or "End"; with neither, the name is just "Start" or "End". The wrapper has no role and carries no `aria-label`.
|
|
299
|
+
- Inside Form, the injected `id`, `aria-labelledby`, `aria-describedby`, `aria-invalid` and `aria-errormessage` land on the input; `aria-required` is not rendered because the slider role does not support it.
|
|
300
|
+
- With a `name`, Slider submits with a native `<form>`: a single value submits one entry, and in `range` mode both inputs share the `name` and submit two entries in order (`FormData.getAll(name)` gives `[min, max]`). Like other native controls, a disabled Slider is not submitted.
|
|
301
|
+
|
|
302
|
+
### Keyboard and Focus
|
|
303
|
+
|
|
304
|
+
- The slider handles arrow keys itself, consistently across browsers; the native range input handles `Home`, `End`, `Page Up` and `Page Down`. A handle can get the focus; keyboard focus draws the focus outline on the visible handle and shows the prompt information of the current handle. Pressing a handle with a pointer also moves focus to it, without the focus outline.
|
|
305
|
+
- `onKeyDown` (`onKeydown` in Vue) is bound on the handle's input and is called for every key before the slider handles it. Value keys (arrow keys, `Home`, `End`, `Page Up`, `Page Down`) do not bubble to ancestors by default; calling `preventDefault` in the callback intercepts the key and the slider no longer handles it.
|
|
306
|
+
- When the user uses the `range` API, you can use `Tab` and `Shift` + `Tab` to switch the focus of the left and right sliders.
|
|
307
|
+
- Arrow keys follow the direction the handle moves on screen: horizontally `Right Arrow` and `Up Arrow` increase the value, `Left Arrow` and `Down Arrow` decrease it (left and right mirrored in RTL); a vertical slider grows from top to bottom, so `Down Arrow` increases and `Up Arrow` decreases; with `verticalReverse` it grows from bottom to top, so `Up Arrow` increases and `Down Arrow` decreases; on a vertical slider `Right Arrow` always increases and `Left Arrow` always decreases.
|
|
308
|
+
- If you want the slider to change more than the step size, `Page Up` and `Page Down` change the value by 10% of the range, rounded to the step:
|
|
309
|
+
- Windows users: `Page Up` for increasing, `Page Down` for decreasing;
|
|
310
|
+
- Mac users:`Fn` + `Up Arrow` for increasing, `Fn` + `Down Arrow` for decreasing;
|
|
311
|
+
- When the user uses the `range` property, the Page Up key of the previous slider is only supported until it meets the next slider, and then using the Page Up key on the previous slider will not respond. The same is true for the latter slider. After encountering, there is no response to the Page Down key.
|
|
312
|
+
- To move the slider to the minimum value of the slider:
|
|
313
|
+
- Windows users: `Home`;
|
|
314
|
+
- Mac users: `Fn` + `left arrow`;
|
|
315
|
+
- When the user uses the `range` property, the `Home`(`Fn` + `left arrow`) button of the latter slider only supports until it meets the previous slider, and the `Home`(`Fn` + `left arrow`) button is unresponsive after the overlap.
|
|
316
|
+
- To move the slider to the maximum value of the slider:
|
|
317
|
+
- Windows users: `End`;
|
|
318
|
+
- Mac users: `Fn` + `right arrow`;
|
|
319
|
+
- When the user uses the `range` property, the `End`(`Fn` + `right arrow`) key of the previous slider is only supported until it meets the next slider, and the `End`(`Fn` + `right arrow`) key is unresponsive after the overlap.
|
|
320
|
+
|
|
321
|
+
## Design Tokens
|
|
322
|
+
|
|
323
|
+
### Focus Style Variables
|
|
324
|
+
|
|
325
|
+
The Slider component has two focus-related design tokens, each corresponding to different interaction scenarios:
|
|
326
|
+
|
|
327
|
+
| Token Name | CSS Variable | Trigger Scenario | Description |
|
|
328
|
+
| - | - | - | - |
|
|
329
|
+
| Handle outline - focus | `--semi-color-primary-light-active` | Keyboard navigation (Tab focus) | Drawn on the visible handle while its input matches `:focus-visible` (`.semi-slider-handle:has(> input:focus-visible)`), so only on keyboard focus |
|
|
330
|
+
| Handle border color - active | `--semi-color-focus-border` | Mouse click/drag | Uses `.semi-slider-handle-clicked` class, displays border during mouse interaction |
|
|
331
|
+
|
|
332
|
+
If you want to modify the focus style of the handle in theme configuration, please note that these two variables correspond to different interaction scenarios.
|
|
333
|
+
|
|
334
|
+
The design token table of this component is on the web page: <https://semi-design-next.pages.dev/en-US/svelte/input/slider/>
|
|
335
|
+
|
|
336
|
+
## Changes from Semi Design
|
|
337
|
+
|
|
338
|
+
From the project release notes (written in Chinese). Your knowledge of Semi Design does not cover these.
|
|
339
|
+
|
|
340
|
+
- 破坏性:删除 `railStyle`,改用 `classNames.rail`、`styles.rail`,落在轨道上。
|
|
341
|
+
- 破坏性(类型):`SliderState.focusPos` 改名 `activeHandle`;`tipFormatter` 参数为 `number`(每个手柄单独调用),删除类型 `tipFormatterBasicType`;`handleDot` 改为 `HandleDot | HandleDot[]`。
|
|
342
|
+
- 每个手柄内改为视觉隐藏的原生 `input type="range"`(`.semi-slider-handle-input`):`getByRole('slider')` 返回该 input,`aria-valuenow` 等不再输出,改读 `value`、`min`、`max`、`disabled`,`onKeyDown` 绑定在它上;新增 `name`;方向键由组件处理,各浏览器一致:`vertical` 时指向 `max` 一端的方向键(默认下,`verticalReverse` 时上)与右方向键增加值,水平 RTL 时左方向键增加值;Home、End 也由组件处理,设为最小值与最大值(Safari 原生垂直 range 会对调二者);PageUp、PageDown 仍由原生 range 处理;foundation 的 `handleKeyDown` 改为 `(event, pos)`;步长网格从 `min` 起算;无 `value` 时初始位置为 `min`(原为 0);指针按下轨道或手柄聚焦 input 时不显示键盘焦点环。
|
|
343
|
+
- Solid 破坏性(类型):`marks` 只收字符串或数字,节点用 `renderMark(value, label)`。
|
|
344
|
+
- Svelte:`value` 可绑定(`bind:value`、函数绑定、单向传值、不传),没有 `defaultValue`;`onChange`、`onAfterChange`、`onMouseUp`、`onFocus`、`onBlur`、`onKeyDown` 是回调 prop;节点型刻度与提示用 `mark({ value, label })`、`tip({ value, handle })` snippet;`style` 与 `styles` 的值只接受字符串。
|
|
345
|
+
- 破坏性(类型,React):`onKeyDown` 的类型改为 `KeyboardEventHandler<HTMLInputElement>`,与它实际绑定的手柄 input 一致(原来继承 div 的事件类型)。
|
|
346
|
+
- `onKeyDown` 中 `preventDefault()` 拦截的取值键松开时不再触发 `onAfterChange`、`onMouseUp`。刻度标签 `marks` 不换行(`white-space: nowrap`),靠近末端时可超出轨道。
|
|
347
|
+
- Svelte:`onFocus` 是外层的 focusin,`onBlur` 只在焦点离开整个 Slider 时触发,`onKeyDown` 落在手柄的 input 上;`value` 绑定或单向传值时,每次值变化除 `onChange` 外也触发 `onAfterChange`(同 Vue 的 v-model),不传 `value` 时拖动期间只触发 `onChange`,松开后触发一次 `onAfterChange`。
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
# Switch
|
|
2
|
+
|
|
3
|
+
> Switch is an interactive form used to switch two mutually exclusive states.
|
|
4
|
+
|
|
5
|
+
Package: `@fibrae/semi-ui-svelte`. Web page: https://semi-design-next.pages.dev/en-US/svelte/input/switch/
|
|
6
|
+
|
|
7
|
+
## Demos
|
|
8
|
+
|
|
9
|
+
### How to import
|
|
10
|
+
|
|
11
|
+
```svelte
|
|
12
|
+
<script lang="ts">
|
|
13
|
+
import { Switch } from '@fibrae/semi-ui-svelte';
|
|
14
|
+
</script>
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
### Basic Usage
|
|
18
|
+
|
|
19
|
+
You can monitor state changes through `onChange`. A plain `checked` sets the initial state, which the user then toggles; to read and write the state, use `bind:checked` (see Controlled component).\
|
|
20
|
+
Use `aria-label` to describe the specific function of the Switch
|
|
21
|
+
|
|
22
|
+
```svelte
|
|
23
|
+
<script lang="ts">
|
|
24
|
+
import { Switch } from '@fibrae/semi-ui-svelte';
|
|
25
|
+
</script>
|
|
26
|
+
|
|
27
|
+
<div>
|
|
28
|
+
<Switch aria-label="a switch for demo" onChange={(checked) => console.log(checked)} />
|
|
29
|
+
<br />
|
|
30
|
+
<Switch aria-label="a switch for semi demo" checked onChange={(checked) => console.log(checked)} />
|
|
31
|
+
</div>
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### Size
|
|
35
|
+
|
|
36
|
+
```svelte
|
|
37
|
+
<script lang="ts">
|
|
38
|
+
import { Space, Switch } from '@fibrae/semi-ui-svelte';
|
|
39
|
+
</script>
|
|
40
|
+
|
|
41
|
+
<div>
|
|
42
|
+
<Space style="display: block; margin-bottom: 10px">
|
|
43
|
+
<Switch aria-label="a switch for demo" size="small" />
|
|
44
|
+
<Switch aria-label="a switch for demo" checked size="small" />
|
|
45
|
+
<Switch aria-label="a switch for demo" loading size="small" />
|
|
46
|
+
<Switch aria-label="a switch for demo" checked loading size="small" />
|
|
47
|
+
</Space>
|
|
48
|
+
<Space style="display: block; margin-bottom: 10px">
|
|
49
|
+
<Switch aria-label="a switch for demo" />
|
|
50
|
+
<Switch aria-label="a switch for demo" checked />
|
|
51
|
+
<Switch aria-label="a switch for demo" loading />
|
|
52
|
+
<Switch aria-label="a switch for demo" checked loading />
|
|
53
|
+
</Space>
|
|
54
|
+
<Space>
|
|
55
|
+
<Switch aria-label="a switch for demo" size="large" />
|
|
56
|
+
<Switch aria-label="a switch for demo" checked size="large" />
|
|
57
|
+
<Switch aria-label="a switch for demo" loading size="large" />
|
|
58
|
+
<Switch aria-label="a switch for demo" checked loading size="large" />
|
|
59
|
+
</Space>
|
|
60
|
+
</div>
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Disabled
|
|
64
|
+
|
|
65
|
+
```svelte
|
|
66
|
+
<script lang="ts">
|
|
67
|
+
import { Switch } from '@fibrae/semi-ui-svelte';
|
|
68
|
+
</script>
|
|
69
|
+
|
|
70
|
+
<div>
|
|
71
|
+
<Switch aria-label="a switch for demo" disabled />
|
|
72
|
+
<br />
|
|
73
|
+
<Switch aria-label="a switch for demo" checked disabled />
|
|
74
|
+
</div>
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### With text
|
|
78
|
+
|
|
79
|
+
`checkedText` and `uncheckedText` take snippets: define them with `{#snippet}` and pass them as props, or write them inside the Switch tag as snippets of the same name.\
|
|
80
|
+
Note: This does not work with the smallest switch (size = 'small')
|
|
81
|
+
|
|
82
|
+
```svelte
|
|
83
|
+
<script lang="ts">
|
|
84
|
+
import { Switch } from '@fibrae/semi-ui-svelte';
|
|
85
|
+
</script>
|
|
86
|
+
|
|
87
|
+
{#snippet on()}开{/snippet}
|
|
88
|
+
{#snippet off()}关{/snippet}
|
|
89
|
+
{#snippet bar()}|{/snippet}
|
|
90
|
+
{#snippet ring()}〇{/snippet}
|
|
91
|
+
|
|
92
|
+
<div>
|
|
93
|
+
<Switch aria-label="带开关文字的开关" checkedText={on} uncheckedText={off} />
|
|
94
|
+
<Switch aria-label="带符号文字的开关" checkedText={bar} style="margin-left: 5px" uncheckedText={ring} />
|
|
95
|
+
<br />
|
|
96
|
+
<br />
|
|
97
|
+
<Switch aria-label="带开关文字的开关,已开启" checked checkedText={on} uncheckedText={off} />
|
|
98
|
+
<Switch aria-label="带符号文字的开关,已开启" checked checkedText={bar} style="margin-left: 5px" uncheckedText={ring} />
|
|
99
|
+
<br />
|
|
100
|
+
<br />
|
|
101
|
+
<Switch aria-label="大号带开关文字的开关" checkedText={on} size="large" uncheckedText={off} />
|
|
102
|
+
<Switch aria-label="大号带符号文字的开关" checkedText={bar} size="large" style="margin-left: 5px" uncheckedText={ring} />
|
|
103
|
+
<br />
|
|
104
|
+
<br />
|
|
105
|
+
<Switch aria-label="大号带开关文字的开关,已开启" checked checkedText={on} size="large" uncheckedText={off} />
|
|
106
|
+
<Switch aria-label="大号带符号文字的开关,已开启" checked checkedText={bar} size="large" style="margin-left: 5px" uncheckedText={ring} />
|
|
107
|
+
</div>
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
Compared to setting the embedded text through checkedText and uncheckedText, we recommend placing the text description outside the Switch
|
|
111
|
+
|
|
112
|
+
```svelte
|
|
113
|
+
<script lang="ts">
|
|
114
|
+
import { Switch, Typography } from '@fibrae/semi-ui-svelte';
|
|
115
|
+
|
|
116
|
+
let open = $state<boolean>();
|
|
117
|
+
</script>
|
|
118
|
+
|
|
119
|
+
<div style="display: flex; align-items: center">
|
|
120
|
+
<Typography.Title heading={6} style="margin: 8px">{open ? '已开启' : '已关闭'}</Typography.Title>
|
|
121
|
+
<Switch aria-label="a switch for demo" bind:checked={open} />
|
|
122
|
+
</div>
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### Controlled component
|
|
126
|
+
|
|
127
|
+
Use `bind:checked` to keep the checked state in sync with a `$state` variable. To reject or rewrite a toggle, use a function binding `bind:checked={() => value, (next) => { ... }}`; the switch shows what the getter returns. A plain `checked` without a binding is only the initial value: a click toggles it inside the component, and a new value from the parent wins again.
|
|
128
|
+
|
|
129
|
+
```svelte
|
|
130
|
+
<script lang="ts">
|
|
131
|
+
import { Switch } from '@fibrae/semi-ui-svelte';
|
|
132
|
+
|
|
133
|
+
let checked = $state(true);
|
|
134
|
+
</script>
|
|
135
|
+
|
|
136
|
+
<Switch aria-label="a switch for demo" bind:checked />
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### loading
|
|
140
|
+
|
|
141
|
+
You can turn on the loading state by setting loading="true".
|
|
142
|
+
|
|
143
|
+
```svelte
|
|
144
|
+
<script lang="ts">
|
|
145
|
+
import { Switch } from '@fibrae/semi-ui-svelte';
|
|
146
|
+
</script>
|
|
147
|
+
|
|
148
|
+
<div>
|
|
149
|
+
<Switch aria-label="Loading switch" loading />
|
|
150
|
+
<br />
|
|
151
|
+
<Switch aria-label="Loading switch, on" checked loading />
|
|
152
|
+
</div>
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
## API reference
|
|
156
|
+
|
|
157
|
+
**Props**
|
|
158
|
+
|
|
159
|
+
| Property | Description | Type | Default |
|
|
160
|
+
| - | - | - | - |
|
|
161
|
+
| checked | Checked state; bind it with `bind:checked`. `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` | - |
|
|
162
|
+
| checkedText | Snippet shown when checked. Not shown when size is small. | `Snippet` | - |
|
|
163
|
+
| disabled | Whether the switch is disabled. | `boolean` | `false` |
|
|
164
|
+
| loading | Whether the switch is loading. While loading, the input stays focusable with `aria-disabled`; toggles are ignored and onChange is not called. | `boolean` | `false` |
|
|
165
|
+
| onChange | Called when the user toggles the switch, with the new checked state and the native change event. Not called while loading. | `(checked: boolean, event: Event) => void` | - |
|
|
166
|
+
| size | Switch size: large, default or small. | `Size` | `"default"` |
|
|
167
|
+
| uncheckedText | Snippet shown when unchecked. Not shown when size is small. | `Snippet` | - |
|
|
168
|
+
|
|
169
|
+
`class`, `style` and other native attributes and listeners (such as `onmouseenter`) land on the root element. `id`, `name`, `tabindex`, `autofocus`, `aria-*`, and `onfocus` and `onblur` land on the inner native input.
|
|
170
|
+
|
|
171
|
+
## Accessibility
|
|
172
|
+
|
|
173
|
+
### ARIA
|
|
174
|
+
|
|
175
|
+
- The inner input of Switch has a `switch` role, and its on or off state is expressed by the native checked state of the input.
|
|
176
|
+
- As a form field, it should have a Label.
|
|
177
|
+
|
|
178
|
+
* It is recommended to use `aria-label` to describe the current label function, or `aria-labelledby` to point to a visible label on the page.
|
|
179
|
+
|
|
180
|
+
### Keyboard and Focus
|
|
181
|
+
|
|
182
|
+
- Keyboard users can use `Tab` and `Shift + Tab` to switch focus.
|
|
183
|
+
- When focusing, you can switch on or off by pressing the `Space` key.
|
|
184
|
+
|
|
185
|
+
## Content Guidelines
|
|
186
|
+
|
|
187
|
+
- Switch description
|
|
188
|
+
- First letter is capitalized, no punctuation is required
|
|
189
|
+
- Indirectly and explicitly state whether the setting is on or off
|
|
190
|
+
- If needed, explain to the user what the on and off states represent
|
|
191
|
+
|
|
192
|
+
## Design Tokens
|
|
193
|
+
|
|
194
|
+
The design token table of this component is on the web page: <https://semi-design-next.pages.dev/en-US/svelte/input/switch/>
|
|
195
|
+
|
|
196
|
+
## Changes from Semi Design
|
|
197
|
+
|
|
198
|
+
From the project release notes (written in Chinese). Your knowledge of Semi Design does not cover these.
|
|
199
|
+
|
|
200
|
+
- 破坏性(样式钩子):删除 `semi-switch-focus`(及 `cssClasses.FOCUS`)、`semi-checkbox-focus`、`semi-checkbox-focus-border`,焦点环改由 CSS `:has(input:focus-visible)` 绘制;`SwitchState.nativeControlChecked` 改名 `checked`;Switch 的 `checked` 与 `defaultChecked` 同传时取 `checked`。
|
|
201
|
+
- 行为变化:Checkbox、Radio 的 `id` 落在原生 input 上(用 `#id` 选根元素的写法需改选 input 的父级),input 带 `value`;Checkbox 不再响应 Enter 切换(仅空格);`onClick` 在切换前调用;Switch 的 `loading` 期间切换被忽略且不通知 `onChange`;Switch 的全部 `aria-*` 落在 `role="switch"` 的 input 上,不再有任何 `aria-*` 落在根元素。
|
|
202
|
+
- CheckboxGroup 内没有 `value` 的 Checkbox 不参与分组取值,也不再继承分组的 `aria-invalid`、`aria-errormessage`。
|
|
203
|
+
- Svelte:Switch 的 `checked` 可绑定,`checkedText`、`uncheckedText` 为 snippet;`aria-*`、`id`、`name`、`tabindex`、`autofocus` 与焦点监听落在原生 input 上,其余未声明属性落在根元素。
|
|
204
|
+
- Svelte:Checkbox 的 `checked` 与 CheckboxGroup 的 `value` 可绑定,不提供 `defaultChecked`、`defaultValue`;`onChange` 对 Checkbox 收 `(event)`,`target` 为 `{ checked, value, name, disabled }`,对 CheckboxGroup 收 `(value)`。
|
|
205
|
+
- Svelte:`extra` 以及分组选项的 `label`、`extra` 是 snippet,参数 `{ option, index }`;`Checkbox.Group` 与具名导出 `CheckboxGroup` 是同一组件;`onclick` 在切换前调用,`onBlur` 在焦点离开整个分组时触发;`focus()`、`blur()` 经 `bind:this` 调用。
|
|
206
|
+
- Svelte:Switch、Checkbox 作为 Tooltip `child` snippet 的触发器时,`{...props}` 里的 attachment 会传到根元素。
|