@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,466 @@
|
|
|
1
|
+
# Dropdown
|
|
2
|
+
|
|
3
|
+
> A menu that pops down.
|
|
4
|
+
|
|
5
|
+
Package: `@fibrae/semi-ui-svelte`. Web page: https://semi-design-next.pages.dev/en-US/svelte/show/dropdown/
|
|
6
|
+
|
|
7
|
+
## Demos
|
|
8
|
+
|
|
9
|
+
### How to import
|
|
10
|
+
|
|
11
|
+
```svelte
|
|
12
|
+
<script lang="ts">
|
|
13
|
+
import { Dropdown, DropdownDivider, DropdownItem, DropdownMenu, DropdownTitle } from '@fibrae/semi-ui-svelte';
|
|
14
|
+
</script>
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
`Dropdown.Menu`, `Dropdown.Item`, `Dropdown.Title` and `Dropdown.Divider` correspond to `DropdownMenu`, `DropdownItem`, `DropdownTitle` and `DropdownDivider`, imported by name.
|
|
18
|
+
|
|
19
|
+
### Basic Usage
|
|
20
|
+
|
|
21
|
+
- The Trigger is passed as the children of the Dropdown and is wrapped in a `span`. By default it is displayed on hover. You can modify it to values like `click`, `focus`, `custom`, `contextMenu`, etc. through `trigger` to specify different triggering methods. To render the trigger element yourself, use the `child` snippet and spread its `props` argument onto an element that takes focus.
|
|
22
|
+
- Use the `content` snippet to specify the specific content of the dropdown box: Use `DropdownMenu` as the parent container, and use `DropdownItem`, `DropdownDivider`, and `DropdownTitle` in combination. Of course, in simple scenarios, you can also just combine `DropdownMenu` with `DropdownItem`, and the other elements are not mandatory.
|
|
23
|
+
- `DropdownItem` can disable a certain option by setting `disabled`. By configuring `type`, text in different colors can be displayed. The `icon` snippet configures an icon quickly. For more complex custom structures, write them directly in the children of `DropdownItem`.
|
|
24
|
+
|
|
25
|
+
```svelte
|
|
26
|
+
<script lang="ts">
|
|
27
|
+
import { IconAlertCircle, IconBox, IconForward, IconRefresh, IconSearch, IconSetting } from '@fibrae/semi-icons-svelte';
|
|
28
|
+
import { IconToken } from '@fibrae/semi-icons-svelte/lab';
|
|
29
|
+
import { Button, Dropdown, HotKeys } from '@fibrae/semi-ui-svelte';
|
|
30
|
+
</script>
|
|
31
|
+
|
|
32
|
+
<Dropdown position="bottomLeft">
|
|
33
|
+
<Button theme="outline" type="tertiary">
|
|
34
|
+
{#snippet icon()}<IconToken />{/snippet}
|
|
35
|
+
Hover Me
|
|
36
|
+
</Button>
|
|
37
|
+
{#snippet content()}
|
|
38
|
+
<Dropdown.Menu>
|
|
39
|
+
<Dropdown.Title>分组1</Dropdown.Title>
|
|
40
|
+
<Dropdown.Item>
|
|
41
|
+
{#snippet icon()}<IconBox />{/snippet}
|
|
42
|
+
Menu Item 1
|
|
43
|
+
<HotKeys content={['Ctrl', 'B']} hotKeys={[HotKeys.Keys.Control, HotKeys.Keys.B]} style="margin-inline-start: 20px" />
|
|
44
|
+
</Dropdown.Item>
|
|
45
|
+
<Dropdown.Item>
|
|
46
|
+
{#snippet icon()}<IconSetting />{/snippet}
|
|
47
|
+
Menu Item 2
|
|
48
|
+
<HotKeys content={['Ctrl', 'V']} hotKeys={[HotKeys.Keys.Control, HotKeys.Keys.V]} style="margin-inline-start: 20px" />
|
|
49
|
+
</Dropdown.Item>
|
|
50
|
+
<Dropdown.Item disabled>
|
|
51
|
+
{#snippet icon()}<IconForward />{/snippet}
|
|
52
|
+
Menu Item 3
|
|
53
|
+
<HotKeys content={['Ctrl', 'F3']} hotKeys={[HotKeys.Keys.Control, HotKeys.Keys.F3]} style="margin-inline-start: 20px" />
|
|
54
|
+
</Dropdown.Item>
|
|
55
|
+
<Dropdown.Divider />
|
|
56
|
+
<Dropdown.Title>分组2</Dropdown.Title>
|
|
57
|
+
<Dropdown.Item type="tertiary">
|
|
58
|
+
{#snippet icon()}<IconRefresh />{/snippet}
|
|
59
|
+
tertiary
|
|
60
|
+
</Dropdown.Item>
|
|
61
|
+
<Dropdown.Item type="warning">
|
|
62
|
+
{#snippet icon()}<IconSearch />{/snippet}
|
|
63
|
+
warning
|
|
64
|
+
</Dropdown.Item>
|
|
65
|
+
<Dropdown.Item type="danger">
|
|
66
|
+
{#snippet icon()}<IconAlertCircle />{/snippet}
|
|
67
|
+
danger
|
|
68
|
+
</Dropdown.Item>
|
|
69
|
+
</Dropdown.Menu>
|
|
70
|
+
{/snippet}
|
|
71
|
+
</Dropdown>
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Nested Usage
|
|
75
|
+
|
|
76
|
+
Users can nested `Dropdown`, which is suitable for situations with multiple sublevel options. The trigger of a parent item uses the `child` snippet, which spreads the `props` argument onto the `DropdownItem`. From the keyboard, `Right Arrow` opens a submenu and `Left Arrow` returns to the parent item, and `Enter` or `Space` calls the `onclick` of an item at any level (see [Accessibility](#accessibility)). A nested submenu defaults to a `spacing` of 2. `showTick`, `selectionMode` and `trigger` are not inherited from the outer menu: the submenu Dropdown's own settings apply.
|
|
77
|
+
|
|
78
|
+
```svelte
|
|
79
|
+
<script lang="ts">
|
|
80
|
+
import { IconToken } from '@fibrae/semi-icons-svelte/lab';
|
|
81
|
+
import { Button, Dropdown, Toast } from '@fibrae/semi-ui-svelte';
|
|
82
|
+
</script>
|
|
83
|
+
|
|
84
|
+
{#snippet subMenu()}
|
|
85
|
+
<Dropdown.Menu>
|
|
86
|
+
<!-- Enter and Space trigger a submenu item's click too -->
|
|
87
|
+
{#each [1, 2, 3] as n (n)}
|
|
88
|
+
<Dropdown.Item onclick={() => Toast.info({ content: `点击了 Nested Menu Item ${n}` })}>Nested Menu Item {n}</Dropdown.Item>
|
|
89
|
+
{/each}
|
|
90
|
+
</Dropdown.Menu>
|
|
91
|
+
{/snippet}
|
|
92
|
+
|
|
93
|
+
<div style="margin: 100px">
|
|
94
|
+
<Dropdown>
|
|
95
|
+
<Button theme="outline" type="tertiary">
|
|
96
|
+
{#snippet icon()}<IconToken />{/snippet}
|
|
97
|
+
Hover Me
|
|
98
|
+
</Button>
|
|
99
|
+
{#snippet content()}
|
|
100
|
+
<Dropdown.Menu>
|
|
101
|
+
<Dropdown content={subMenu} position="rightTop">
|
|
102
|
+
{#snippet child(trigger)}
|
|
103
|
+
<Dropdown.Item {...trigger.props}>Menu Item 1</Dropdown.Item>
|
|
104
|
+
{/snippet}
|
|
105
|
+
</Dropdown>
|
|
106
|
+
<Dropdown content={subMenu} position="leftTop">
|
|
107
|
+
{#snippet child(trigger)}
|
|
108
|
+
<Dropdown.Item {...trigger.props}>Menu Item 2</Dropdown.Item>
|
|
109
|
+
{/snippet}
|
|
110
|
+
</Dropdown>
|
|
111
|
+
<Dropdown.Item>Menu Item 3</Dropdown.Item>
|
|
112
|
+
</Dropdown.Menu>
|
|
113
|
+
{/snippet}
|
|
114
|
+
</Dropdown>
|
|
115
|
+
</div>
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### Popup Position
|
|
119
|
+
|
|
120
|
+
The position of support is the same. [Tooltip](../show/tooltip.md#Position), commonly used are: "bottom", "bottomLeft", "bottomRight".
|
|
121
|
+
|
|
122
|
+
```svelte
|
|
123
|
+
<script lang="ts">
|
|
124
|
+
import { Dropdown, Tag } from '@fibrae/semi-ui-svelte';
|
|
125
|
+
</script>
|
|
126
|
+
|
|
127
|
+
<div>
|
|
128
|
+
<Dropdown position="bottom">
|
|
129
|
+
<Tag>Bottom</Tag>
|
|
130
|
+
{#snippet content()}
|
|
131
|
+
<Dropdown.Menu>
|
|
132
|
+
<Dropdown.Item>Menu Item 1</Dropdown.Item>
|
|
133
|
+
<Dropdown.Item>Menu Item 2</Dropdown.Item>
|
|
134
|
+
<Dropdown.Item>Menu Item 3</Dropdown.Item>
|
|
135
|
+
</Dropdown.Menu>
|
|
136
|
+
{/snippet}
|
|
137
|
+
</Dropdown>
|
|
138
|
+
<br />
|
|
139
|
+
<br />
|
|
140
|
+
<Dropdown position="bottomLeft">
|
|
141
|
+
<Tag>bottomLeft</Tag>
|
|
142
|
+
{#snippet content()}
|
|
143
|
+
<Dropdown.Menu>
|
|
144
|
+
<Dropdown.Item>Menu Item 1</Dropdown.Item>
|
|
145
|
+
<Dropdown.Item>Menu Item 2</Dropdown.Item>
|
|
146
|
+
<Dropdown.Item>Menu Item 3</Dropdown.Item>
|
|
147
|
+
</Dropdown.Menu>
|
|
148
|
+
{/snippet}
|
|
149
|
+
</Dropdown>
|
|
150
|
+
<br />
|
|
151
|
+
<br />
|
|
152
|
+
<Dropdown position="bottomRight">
|
|
153
|
+
<Tag>bottomRight</Tag>
|
|
154
|
+
{#snippet content()}
|
|
155
|
+
<Dropdown.Menu>
|
|
156
|
+
<Dropdown.Item>Menu Item 1</Dropdown.Item>
|
|
157
|
+
<Dropdown.Item>Menu Item 2</Dropdown.Item>
|
|
158
|
+
<Dropdown.Item>Menu Item 3</Dropdown.Item>
|
|
159
|
+
</Dropdown.Menu>
|
|
160
|
+
{/snippet}
|
|
161
|
+
</Dropdown>
|
|
162
|
+
</div>
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
### Trigger Mode
|
|
166
|
+
|
|
167
|
+
The default is the move-in Trigger, which can be expanded by getting focus, clicking, right-clicking (`contextMenu`), or customizing the event trigger menu. After a right click opens the menu, focus moves to the first enabled item.
|
|
168
|
+
|
|
169
|
+
```svelte
|
|
170
|
+
<script lang="ts">
|
|
171
|
+
import { Button, Dropdown, Tag } from '@fibrae/semi-ui-svelte';
|
|
172
|
+
</script>
|
|
173
|
+
|
|
174
|
+
<div>
|
|
175
|
+
<Dropdown position="bottomLeft" trigger="hover">
|
|
176
|
+
<Tag>Hover me</Tag>
|
|
177
|
+
{#snippet content()}
|
|
178
|
+
<Dropdown.Menu>
|
|
179
|
+
<Dropdown.Item>Menu Item 1</Dropdown.Item>
|
|
180
|
+
<Dropdown.Item>Menu Item 2</Dropdown.Item>
|
|
181
|
+
<Dropdown.Item>Menu Item 3</Dropdown.Item>
|
|
182
|
+
</Dropdown.Menu>
|
|
183
|
+
{/snippet}
|
|
184
|
+
</Dropdown>
|
|
185
|
+
<br />
|
|
186
|
+
<br />
|
|
187
|
+
<Dropdown position="bottomLeft" trigger="focus">
|
|
188
|
+
<div style="border: 1px solid var(--semi-color-border); border-radius: 4px; height: 36px; width: 220px">Please use Tab to focus this div</div>
|
|
189
|
+
{#snippet content()}
|
|
190
|
+
<Dropdown.Menu tabindex={-1}>
|
|
191
|
+
<Dropdown.Item>Menu Item 1</Dropdown.Item>
|
|
192
|
+
<Dropdown.Item>Menu Item 2</Dropdown.Item>
|
|
193
|
+
<Dropdown.Item>Menu Item 3</Dropdown.Item>
|
|
194
|
+
</Dropdown.Menu>
|
|
195
|
+
{/snippet}
|
|
196
|
+
</Dropdown>
|
|
197
|
+
<br />
|
|
198
|
+
<br />
|
|
199
|
+
<Dropdown position="bottomLeft" trigger="click">
|
|
200
|
+
<Button>Click me</Button>
|
|
201
|
+
{#snippet content()}
|
|
202
|
+
<Dropdown.Menu>
|
|
203
|
+
<Dropdown.Item>Menu Item 1</Dropdown.Item>
|
|
204
|
+
<Dropdown.Item>Menu Item 2</Dropdown.Item>
|
|
205
|
+
<Dropdown.Item>Menu Item 3</Dropdown.Item>
|
|
206
|
+
</Dropdown.Menu>
|
|
207
|
+
{/snippet}
|
|
208
|
+
</Dropdown>
|
|
209
|
+
<br />
|
|
210
|
+
<br />
|
|
211
|
+
<Dropdown position="bottomRight" trigger="contextMenu">
|
|
212
|
+
<Button style="margin-block-end: 20px" theme="solid" type="secondary">Right click (ContextMenu)</Button>
|
|
213
|
+
{#snippet content()}
|
|
214
|
+
<Dropdown.Menu>
|
|
215
|
+
<Dropdown.Item>Menu Item 1</Dropdown.Item>
|
|
216
|
+
<Dropdown.Item>Menu Item 2</Dropdown.Item>
|
|
217
|
+
<Dropdown.Item>Menu Item 3</Dropdown.Item>
|
|
218
|
+
</Dropdown.Menu>
|
|
219
|
+
{/snippet}
|
|
220
|
+
</Dropdown>
|
|
221
|
+
</div>
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
### Trigger Event
|
|
225
|
+
|
|
226
|
+
Click on the menu item to trigger different mouse events, support `onclick`, `onmouseenter`, `onmouseleave` and `oncontextmenu`. The `onclick` of a top-level menu fires on click, that of a submenu fires on the left button press, and `Enter` and `Space` on the keyboard fire it as well.
|
|
227
|
+
|
|
228
|
+
```svelte
|
|
229
|
+
<script lang="ts">
|
|
230
|
+
import { IconToken } from '@fibrae/semi-icons-svelte/lab';
|
|
231
|
+
import { Button, Dropdown, Toast } from '@fibrae/semi-ui-svelte';
|
|
232
|
+
</script>
|
|
233
|
+
|
|
234
|
+
<Dropdown position="bottomLeft" trigger="click">
|
|
235
|
+
<Button theme="outline" type="tertiary">
|
|
236
|
+
{#snippet icon()}<IconToken />{/snippet}
|
|
237
|
+
Click Me
|
|
238
|
+
</Button>
|
|
239
|
+
{#snippet content()}
|
|
240
|
+
<Dropdown.Menu>
|
|
241
|
+
<Dropdown.Item onclick={() => Toast.info({ content: 'You clicked me!' })}>1: click me!</Dropdown.Item>
|
|
242
|
+
<Dropdown.Item onmouseenter={() => Toast.info({ content: 'Nice to meet you!' })}>2: mouse enter</Dropdown.Item>
|
|
243
|
+
<Dropdown.Item onmouseleave={() => Toast.info({ content: 'See ya!' })}>3: mouse leave</Dropdown.Item>
|
|
244
|
+
<Dropdown.Item oncontextmenu={() => Toast.info({ content: 'Right clicked!' })}>4: right click</Dropdown.Item>
|
|
245
|
+
</Dropdown.Menu>
|
|
246
|
+
{/snippet}
|
|
247
|
+
</Dropdown>
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
### Json Usage
|
|
251
|
+
|
|
252
|
+
Can use the `menu` attribute, given an array, to configure the Dropdown content menu. Listeners in an entry use lowercase native event names such as `onclick` and `onmouseenter`, and are handed to the matching `DropdownItem`. Use the `menuIcon` snippet, whose argument is `{ item, index }`, to customize the icon of each entry. `content` wins when it is provided.
|
|
253
|
+
|
|
254
|
+
```svelte
|
|
255
|
+
<script lang="ts">
|
|
256
|
+
import { IconToken } from '@fibrae/semi-icons-svelte/lab';
|
|
257
|
+
import { Button, Dropdown, type DropdownMenuItem } from '@fibrae/semi-ui-svelte';
|
|
258
|
+
|
|
259
|
+
const menu: DropdownMenuItem[] = [
|
|
260
|
+
{ node: 'title', name: '分组1' },
|
|
261
|
+
{ node: 'item', name: 'primary1', type: 'primary', onclick: () => console.log('click primary') },
|
|
262
|
+
{ node: 'item', name: 'secondary', type: 'secondary' },
|
|
263
|
+
{ node: 'divider' },
|
|
264
|
+
{ node: 'title', name: '分组2' },
|
|
265
|
+
{ node: 'item', name: 'tertiary', type: 'tertiary' },
|
|
266
|
+
{ node: 'item', name: 'warning', type: 'warning', active: true },
|
|
267
|
+
{ node: 'item', name: 'danger', type: 'danger' },
|
|
268
|
+
];
|
|
269
|
+
</script>
|
|
270
|
+
|
|
271
|
+
<Dropdown {menu} position="bottomLeft" showTick trigger="click">
|
|
272
|
+
<Button theme="outline" type="tertiary">
|
|
273
|
+
{#snippet icon()}<IconToken />{/snippet}
|
|
274
|
+
Click Me
|
|
275
|
+
</Button>
|
|
276
|
+
</Dropdown>
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
## API Reference
|
|
280
|
+
|
|
281
|
+
### Dropdown
|
|
282
|
+
|
|
283
|
+
**Props**
|
|
284
|
+
|
|
285
|
+
| Property | Description | Type | Default |
|
|
286
|
+
| - | - | - | - |
|
|
287
|
+
| afterClose | Called after the menu has closed and its leave animation has finished. | `() => void` | - |
|
|
288
|
+
| afterOpen | Called after the menu has opened and its enter animation has finished, or right after opening when there is no enter animation, controlled or not; not called for an open that is closed before the enter animation ends. | `() => void` | - |
|
|
289
|
+
| aria-describedby | aria-describedby of the popup when its role is dialog. | `string` | - |
|
|
290
|
+
| aria-label | aria-label of the popup when its role is dialog. | `string` | - |
|
|
291
|
+
| aria-labelledby | aria-labelledby of the popup when its role is dialog. | `string` | - |
|
|
292
|
+
| autoAdjustOverflow | Whether the popup flips automatically when it would be clipped. | `boolean` | - |
|
|
293
|
+
| child | Snippet that renders the trigger element itself. Its `{ props }` argument must be spread on a focusable element, with `class` merged into your own (`class={[props.class, 'own']}`); use it for a button, a link, or the DropdownItem that is the parent in a nested menu. It wins over children. | `Snippet<[{ props: DropdownTriggerProps }]>` | - |
|
|
294
|
+
| children | The trigger, wrapped in a span that takes the trigger attributes and responds to the keyboard. | `Snippet` | - |
|
|
295
|
+
| class | Class name of the popup `.semi-dropdown-wrapper`. | `string` | - |
|
|
296
|
+
| classNames | Class names of the inner parts, keyed by `content` (the dropdown menu root element `.semi-dropdown`) and `wrapper` (the span that wraps the trigger when a wrapper is needed); merged with the built-in classes. | `Partial<Record<DropdownPart, ClassValue>>` | - |
|
|
297
|
+
| clickToHide | Whether a click inside the popup closes it. | `boolean` | - |
|
|
298
|
+
| clickTriggerToHide | Whether a click on the trigger closes an open popup. | `boolean` | - |
|
|
299
|
+
| closeOnEsc | Whether Esc on the trigger or in the popup closes the menu. With trigger custom it only calls onEscKeyDown and the caller decides whether to close. | `boolean` | `true` |
|
|
300
|
+
| condition | Whether the popup may be triggered. Only an explicit false disables the hover, click and focus triggers; with trigger custom, visible still shows the popup. Changing it from true to false closes an open popup at once; with a controlled visible it only calls onVisibleChange(false), and the popup closes once the caller writes back. | `boolean` | - |
|
|
301
|
+
| content | Menu content made of DropdownMenu with DropdownItem, DropdownTitle and DropdownDivider. Once provided, even empty, it takes precedence over menu. | `Snippet` | - |
|
|
302
|
+
| disableFocusListener | Whether keyboard focus is ignored when trigger is hover. | `boolean` | - |
|
|
303
|
+
| guardFocus | Whether Tab cycles inside the popup while focus is in it. | `boolean` | - |
|
|
304
|
+
| keepDOM | Whether the popup content stays mounted while closed. | `boolean` | - |
|
|
305
|
+
| menu | Configures the menu from data, see DropdownMenuItem below. content wins when it is provided. | `DropdownMenuItem[]` | - |
|
|
306
|
+
| menuIcon | Icon of each item entry of menu, with `{ item, index }` as its argument. The icon container is always rendered and is empty when the snippet outputs nothing. | `Snippet<[DropdownMenuIconArgs]>` | - |
|
|
307
|
+
| motion | Whether the popup is animated. | `boolean` | `true` |
|
|
308
|
+
| mouseEnterDelay | Milliseconds before the menu shows after the pointer enters the trigger. Applies to the hover and focus triggers. | `number` | - |
|
|
309
|
+
| mouseLeaveDelay | Milliseconds before the menu hides after the pointer leaves the popup. Applies to the hover and focus triggers; not less than mouseEnterDelay. | `number` | `100` |
|
|
310
|
+
| onClickOutSide | Called when the mouse is pressed outside of the trigger and the open popup. Only for trigger click, contextMenu or custom, or with clickTriggerToHide. | `(event: MouseEvent) => void` | - |
|
|
311
|
+
| onEscKeyDown | Called when Esc is pressed while the menu is open and closeOnEsc is true. | `(event: KeyboardEvent) => void` | - |
|
|
312
|
+
| onOpen | Called once per opening when the menu is shown, as its enter animation starts, before afterOpen, controlled or not; not called for a hover open withdrawn because the pointer already left. | `() => void` | - |
|
|
313
|
+
| onVisibleChange | Called when the visibility of the menu changes; with a controlled visible it reports only requests from user interaction, not changes the parent makes to visible. | `(visible: boolean) => void` | - |
|
|
314
|
+
| position | Position of the menu relative to the trigger. Common values are bottom, bottomLeft and bottomRight; see the Tooltip positions for more. | `Position` | `"bottom"` |
|
|
315
|
+
| preventScroll | Whether focusing an element avoids scrolling it into view. | `boolean` | - |
|
|
316
|
+
| returnFocusOnClose | Whether focus returns to the trigger after the menu closes. | `boolean` | `true` |
|
|
317
|
+
| role | ARIA role of the popup container around the menu. The menu itself has role menu. | `string` | `"presentation"` |
|
|
318
|
+
| selectionMode | How the items of this menu are selected; active marks the selected ones. With single the items are menuitemradio with aria-checked, with multiple menuitemcheckbox with aria-checked; unset, they are menuitemcheckbox with aria-checked when showTick is on, otherwise menuitem. It sets roles and states only: showTick alone shows the tick. Nested submenus do not inherit it. | `DropdownSelectionMode` | - |
|
|
319
|
+
| showTick | Whether an active DropdownItem shows a tick on its leading side. It applies to the menu of this Dropdown only; nested submenus do not inherit it. | `boolean` | `false` |
|
|
320
|
+
| spacing | Distance in pixels between the popup and the trigger. Defaults to 4 for a top-level menu and 2 for a nested submenu. | `number \| { x: number; y: number }` | - |
|
|
321
|
+
| stopPropagation | Whether click, mousedown and focus in/out events on the popup stop propagating. | `boolean` | - |
|
|
322
|
+
| style | Inline style string of the popup `.semi-dropdown-wrapper`. | `string` | - |
|
|
323
|
+
| styles | Inline style strings of the inner parts, keyed like `classNames`; `content` is applied after `style`. | `Partial<Record<DropdownPart, string>>` | - |
|
|
324
|
+
| trigger | What shows the menu: hover, focus, click, custom or contextMenu. With custom, visible alone decides. | `'click' \| 'contextMenu' \| 'custom' \| 'focus' \| 'hover'` | `"hover"` |
|
|
325
|
+
| visible | Whether the menu is shown. Bindable with `bind:visible` and used with trigger custom; when given, this value decides, and binding undefined returns to uncontrolled. | `boolean` | - |
|
|
326
|
+
| wrapperId | id of the popup element, referenced by the trigger's ARIA attributes. Generated when omitted. | `string` | - |
|
|
327
|
+
|
|
328
|
+
**Methods**
|
|
329
|
+
|
|
330
|
+
| Method | Description | Type |
|
|
331
|
+
| - | - | - |
|
|
332
|
+
| focusTrigger | Focuses the trigger element. Takes effect only when returnFocusOnClose is true, trigger is not custom, and the trigger is not rendered by child. | `() => void` |
|
|
333
|
+
| rePosition | Recomputes the popup position from the trigger's current position at once. The popup already follows scrolling, window resizing, trigger moves and size changes of the trigger or popup, so this is rarely needed; following a trigger move lands a frame late, so call this to align within the same frame. | `() => void` |
|
|
334
|
+
|
|
335
|
+
Dropdown has no root element of its own: `class` lands on the outer `.semi-dropdown-wrapper` of the popup, `classNames.content` on the menu container `.semi-dropdown`, and other undeclared attributes are dropped.
|
|
336
|
+
|
|
337
|
+
### Dropdown.Menu
|
|
338
|
+
|
|
339
|
+
**Props**
|
|
340
|
+
|
|
341
|
+
| Property | Description | Type | Default |
|
|
342
|
+
| - | - | - | - |
|
|
343
|
+
| children | Children of the menu, usually DropdownItem, DropdownTitle or DropdownDivider. | `Snippet` | - |
|
|
344
|
+
|
|
345
|
+
`class`, `style` and native attributes land on the `ul` of the menu. `role` and `aria-orientation` can be overridden, and an `onkeydown` bound on the menu runs before the built-in keyboard handling.
|
|
346
|
+
|
|
347
|
+
### Dropdown.Item
|
|
348
|
+
|
|
349
|
+
**Props**
|
|
350
|
+
|
|
351
|
+
| Property | Description | Type | Default |
|
|
352
|
+
| - | - | - | - |
|
|
353
|
+
| active | Whether the item is active: bolder text and a deeper color, plus a tick on its leading side when the Dropdown has showTick. | `boolean` | `false` |
|
|
354
|
+
| children | Content of the item. | `Snippet` | - |
|
|
355
|
+
| disabled | Whether the item is disabled. | `boolean` | `false` |
|
|
356
|
+
| icon | Icon of the item. The icon container is always rendered and is empty when the snippet outputs nothing. | `Snippet` | - |
|
|
357
|
+
| showTick | Takes effect only outside a Dropdown. Inside one, the showTick of the Dropdown applies. | `boolean` | - |
|
|
358
|
+
| type | Text color type: primary, secondary, tertiary, warning or danger. | `'danger' \| 'primary' \| 'secondary' \| 'tertiary' \| 'warning'` | - |
|
|
359
|
+
|
|
360
|
+
Listen for click, pointer enter and leave, and right click with `onclick`, `onmouseenter`, `onmouseleave` and `oncontextmenu`; the parameter is the native `MouseEvent`. `class`, `style` and other native attributes land on the `li`. A disabled Item does not respond to these four listeners.
|
|
361
|
+
|
|
362
|
+
### Dropdown.Title
|
|
363
|
+
|
|
364
|
+
**Props**
|
|
365
|
+
|
|
366
|
+
| Property | Description | Type | Default |
|
|
367
|
+
| - | - | - | - |
|
|
368
|
+
| children | Content of the group title. | `Snippet` | - |
|
|
369
|
+
|
|
370
|
+
`class`, `style` and native attributes land on the `li`. The divider `DropdownDivider` has no props and also receives `class`, `style` and native attributes.
|
|
371
|
+
|
|
372
|
+
### DropdownMenuItem
|
|
373
|
+
|
|
374
|
+
An entry does not accept `children`; the label comes from `name` alone.
|
|
375
|
+
|
|
376
|
+
| Properties | Instructions | Type | Default |
|
|
377
|
+
| - | - | - | - |
|
|
378
|
+
| node | Entry type: `title`, `item` or `divider` | `'title' \| 'item' \| 'divider'` | - |
|
|
379
|
+
| name | Menu text, only on `title` and `item` | `string \| number` | - |
|
|
380
|
+
| active, disabled, showTick, type | Correspond to the props of DropdownItem of the same name, only on `item` | - | - |
|
|
381
|
+
| class, style, `data-*`, `aria-*` | Handed to the matching DropdownTitle, DropdownItem or DropdownDivider; `style` is a string | - | - |
|
|
382
|
+
| onclick, onmouseenter, onmouseleave, oncontextmenu | Listeners of DropdownItem under lowercase native event names, only on `item` | `(event: MouseEvent) => void` | - |
|
|
383
|
+
|
|
384
|
+
### Methods
|
|
385
|
+
|
|
386
|
+
Get the instance with `bind:this` and call `focusTrigger()` and `rePosition()`, see the Methods of Dropdown above.
|
|
387
|
+
|
|
388
|
+
## Accessibility
|
|
389
|
+
|
|
390
|
+
Dropdown follows the WAI-ARIA APG [Menu Button](https://www.w3.org/WAI/ARIA/apg/patterns/menu-button/) and [Menu and Menubar](https://www.w3.org/WAI/ARIA/apg/patterns/menubar/) patterns.
|
|
391
|
+
|
|
392
|
+
### ARIA
|
|
393
|
+
|
|
394
|
+
- The trigger has `aria-haspopup="menu"` and `aria-expanded`, which is `true` while the menu is shown and `false` otherwise
|
|
395
|
+
- Dropdown.Menu has `role="menu"` and `aria-orientation="vertical"`
|
|
396
|
+
- Dropdown.Item has `role="menuitem"`; with the Dropdown's `selectionMode` set to `single` it has `role="menuitemradio"`, with `multiple` or with `showTick` it has `role="menuitemcheckbox"`, and in these three cases it exposes `active` as `aria-checked`; the tick icon is left out of the item name; a disabled item has `aria-disabled="true"`
|
|
397
|
+
- A Dropdown.Item that triggers a nested Dropdown (a parent item) also has `aria-haspopup="menu"` and `aria-expanded`
|
|
398
|
+
- Dropdown.Divider renders an `li` with `role="separator"`, and Dropdown.Title an `li` with `role="presentation"`
|
|
399
|
+
- The popup container around the menu has `role="presentation"`, not `tooltip`
|
|
400
|
+
|
|
401
|
+
### Keyboard and Focus
|
|
402
|
+
|
|
403
|
+
With focus on the trigger:
|
|
404
|
+
|
|
405
|
+
| Key | Behavior |
|
|
406
|
+
| - | - |
|
|
407
|
+
| `Enter`, `Space` | With `trigger="click"`, opens the menu and moves focus to the first enabled item |
|
|
408
|
+
| `Down Arrow` | While the menu is open, moves focus to the first enabled item; on a button trigger (`button`, a link with `href`, Semi Button, ...) with the menu closed, opens the menu and focuses the first enabled item |
|
|
409
|
+
| `Up Arrow` | While the menu is open, moves focus to the last enabled item; on a button trigger with the menu closed, opens the menu and focuses the last enabled item |
|
|
410
|
+
| `Tab` | While the menu is open, closes it and moves focus in the browser's default order |
|
|
411
|
+
|
|
412
|
+
When `render` (the `#content` slot in Vue) holds no menu items, `Down Arrow` and `Up Arrow` on the open popup's trigger focus its first and last focusable element.
|
|
413
|
+
|
|
414
|
+
When the trigger is text or several nodes, Dropdown wraps them in a `span`, and the keys above work on that `span` as well.
|
|
415
|
+
|
|
416
|
+
With `trigger` set to `hover` or `focus`, focusing the trigger from the keyboard opens the menu (turn this off with `disableFocusListener`), and moving focus away closes it.
|
|
417
|
+
|
|
418
|
+
With `trigger` set to `contextMenu`, focus moves to the first enabled item after a right click opens the menu.
|
|
419
|
+
|
|
420
|
+
With focus on a menu item:
|
|
421
|
+
|
|
422
|
+
| Key | Behavior |
|
|
423
|
+
| - | - |
|
|
424
|
+
| `Down Arrow`, `Up Arrow` | Moves to the next or previous item of the current menu, skipping disabled items and wrapping at either end |
|
|
425
|
+
| `Home`, `End` | Moves to the first or last item of the current menu |
|
|
426
|
+
| `Enter`, `Space` | On a parent item, opens the submenu and moves focus to its first item; on any other item, calls `onClick` (`@click` in Vue), then closes the menu with `clickToHide` |
|
|
427
|
+
| `Right Arrow` | On a parent item, opens the submenu and moves focus to its first item; no effect on other items |
|
|
428
|
+
| `Left Arrow` | In a submenu, closes it and returns focus to the parent item, regardless of `closeOnEsc` |
|
|
429
|
+
| `Tab` | Closes every menu (submenus included) and moves focus in the browser's default order, not back to the trigger |
|
|
430
|
+
| `Esc` | Closes the menu that contains focus and returns focus to the element that opened it (the parent item or the trigger); on a parent item whose submenu is open, closes the submenu first; does nothing when `closeOnEsc` is false |
|
|
431
|
+
| Printable characters | Moves to the next item of the current menu that starts with the character |
|
|
432
|
+
|
|
433
|
+
- In RTL (ConfigProvider `direction="rtl"`), `Left Arrow` and `Right Arrow` are swapped.
|
|
434
|
+
- Calling `e.preventDefault()` in an item's `onKeyDown` (`@keydown` in Vue) keeps `Enter` and `Space` from calling `onClick` (`@click` in Vue).
|
|
435
|
+
- When an item of a nested Dropdown is activated from the keyboard, its `onClick` (`@click` in Vue) receives a `click` event; with the mouse it still fires on the left button press.
|
|
436
|
+
|
|
437
|
+
## Content Guidelines
|
|
438
|
+
|
|
439
|
+
- The content of the options in the drop-down box needs to be expressed accurately and contain information to make it easier for users to choose among the options when browsing
|
|
440
|
+
- Use statement-like capitalization and write options concisely and clearly
|
|
441
|
+
- In the case of an action option, use a verb or verb phrase to describe the action that will occur when the user selects the option. For example, "Move", "Log time", or "Hide labels"
|
|
442
|
+
- do not use prepositions
|
|
443
|
+
|
|
444
|
+
| ✅ Recommended usage | ❌ Deprecated usage |
|
|
445
|
+
| - | - |
|
|
446
|
+
| | |
|
|
447
|
+
|
|
448
|
+
## Design Tokens
|
|
449
|
+
|
|
450
|
+
The design token table of this component is on the web page: <https://semi-design-next.pages.dev/en-US/svelte/show/dropdown/>
|
|
451
|
+
|
|
452
|
+
## Changes from Semi Design
|
|
453
|
+
|
|
454
|
+
From the project release notes (written in Chinese). Your knowledge of Semi Design does not cover these.
|
|
455
|
+
|
|
456
|
+
- 破坏性:删除 `contentClassName`、`wrapperClassName`,改用 `classNames`、`styles` 的 `content`(菜单容器)、`wrapper`(文本或多节点触发器外的 span)键。
|
|
457
|
+
- 行为变化:hover 菜单与嵌套子菜单,鼠标斜着移向已打开的子菜单时,途经兄弟项不再关闭它或打开兄弟项的子菜单(指针宽限,见 Tooltip、Popover 一节)。
|
|
458
|
+
- 破坏性:删除 `getPopupContainer`、`zIndex`、`margin`、`rePosKey`;Dropdown.Divider 渲染为 `li role="separator"`,Dropdown.Title 为 `li role="presentation"`,Props 元素类型改为 `ElementProps<'li'>`;`menu` 数组项类型不再含 `children`;删除 `DropdownItemProps.selected`(用 `active`)与内部 `hover` 属性。
|
|
459
|
+
- 受控 `visible` 时只上报请求:触发与内部关闭只发出 `onVisibleChange(true/false)`,使用方自行改变 `visible` 不上报,需由使用方回写才开合。`showTick` 时菜单项角色变为 `menuitemcheckbox`,按 `menuitem` 查询的测试需调整;新增 `selectionMode?: 'single' | 'multiple'`(`menuitemradio`、`menuitemcheckbox`)。
|
|
460
|
+
- 键盘按 APG menu:Enter、空格触发菜单项,方向键循环,Home、End,右键开左键关子菜单,Esc 只关当前层,菜单内 Tab 关闭全部菜单。只有原生 button、带 href 的 a、Semi Button、Dropdown.Item 等交互元素作触发器才带 `aria-haspopup`、`aria-expanded`;菜单项上的 `onKeyPress` 不再收到 Enter,改用 `onKeyDown`。
|
|
461
|
+
- Svelte:触发器用 `child` 或 `children` snippet,不克隆节点;`child` 的参数是 `{ props }`,要展开到可聚焦元素上,Dropdown 在上面补 `aria-haspopup="menu"`、`aria-expanded` 和展开状态的 `${prefixCls}-showing` class,`class` 要由使用方自己合并,例如 `class={[props.class, 'own']}`。
|
|
462
|
+
- Svelte:子组件既是 `Dropdown.Menu`、`Dropdown.Item`、`Dropdown.Title`、`Dropdown.Divider`,也是具名导出 `DropdownMenu`、`DropdownItem`、`DropdownTitle`、`DropdownDivider`;选项由 `menu` 数据属性加 snippet 提供,事件用小写 DOM 名(`onclick`、`onmouseenter`、`oncontextmenu`);`menuIcon` 是 snippet,参数 `{ item, index }`。
|
|
463
|
+
- Svelte:`visible` 可绑定,没有绑定或只单向传入时按非受控处理,受控要用 `bind:visible` 或函数绑定。
|
|
464
|
+
- Svelte:`DropdownProps` 不含 Tooltip 的 `wrapWhenSpecial`:触发器总经 `child` snippet 渲染,Tooltip 不再包裹特殊触发器,该属性没有作用。
|
|
465
|
+
- Svelte:Dropdown、Tooltip 的子元素是禁用或 loading 的 Button 时,click 与 contextMenu 触发能打开菜单(同 React、Vue)。
|
|
466
|
+
- 破坏性(类型):`menu` 数据项类型 `DropDownMenuItem`、`DropDownMenuItemItem`、`DropDownMenuItemDivider`、`DropDownMenuItemTitle` 改名 `DropdownMenuItem`、`DropdownMenuItemType`、`DropdownMenuItemDividerType`、`DropdownMenuItemTitleType`(包根与深路径均改,四个框架一致),不保留旧名。
|