@ui-sdk/vue 0.0.0-stage → 0.1.0-beta.1
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/LICENSE +202 -0
- package/README.md +10 -2
- package/dist/accordion.d.ts +561 -0
- package/dist/accordion.js +24 -0
- package/dist/agent.d.ts +2 -0
- package/dist/agent.js +7 -0
- package/dist/alert-dialog.d.ts +231 -0
- package/dist/alert-dialog.js +33 -0
- package/dist/async-options.d.ts +18 -0
- package/dist/async-options.js +40 -0
- package/dist/autocomplete.d.ts +384 -0
- package/dist/autocomplete.js +344 -0
- package/dist/avatar.d.ts +40 -0
- package/dist/avatar.js +28 -0
- package/dist/button.d.ts +52 -0
- package/dist/button.js +43 -0
- package/dist/calendar-context.d.ts +10 -0
- package/dist/calendar-context.js +7 -0
- package/dist/calendar.d.ts +311 -0
- package/dist/calendar.js +349 -0
- package/dist/carousel.d.ts +236 -0
- package/dist/carousel.js +204 -0
- package/dist/checkbox.d.ts +211 -0
- package/dist/checkbox.js +151 -0
- package/dist/children.d.ts +41 -0
- package/dist/children.js +135 -0
- package/dist/collapsible.d.ts +54 -0
- package/dist/collapsible.js +18 -0
- package/dist/color-picker.d.ts +187 -0
- package/dist/color-picker.js +158 -0
- package/dist/color.d.ts +2 -0
- package/dist/color.js +21 -0
- package/dist/combobox.d.ts +517 -0
- package/dist/combobox.js +531 -0
- package/dist/command.d.ts +322 -0
- package/dist/command.js +345 -0
- package/dist/controller-target.d.ts +49 -0
- package/dist/controller-target.js +112 -0
- package/dist/create-parts.d.ts +126 -0
- package/dist/create-parts.js +206 -0
- package/dist/date-input.d.ts +133 -0
- package/dist/date-input.js +31 -0
- package/dist/date-picker.d.ts +328 -0
- package/dist/date-picker.js +354 -0
- package/dist/date.d.ts +2 -0
- package/dist/date.js +59 -0
- package/dist/dialog-parts.d.ts +259 -0
- package/dist/dialog-parts.js +300 -0
- package/dist/dialog.d.ts +251 -0
- package/dist/dialog.js +25 -0
- package/dist/drawer.d.ts +304 -0
- package/dist/drawer.js +373 -0
- package/dist/editor-context.d.ts +4 -0
- package/dist/editor-context.js +5 -0
- package/dist/field-context.d.ts +26 -0
- package/dist/field-context.js +44 -0
- package/dist/field.d.ts +154 -0
- package/dist/field.js +240 -0
- package/dist/file-input.d.ts +212 -0
- package/dist/file-input.js +255 -0
- package/dist/form-inputs.d.ts +16 -0
- package/dist/form-inputs.js +25 -0
- package/dist/gesture.d.ts +1 -0
- package/dist/gesture.js +15 -0
- package/dist/history.d.ts +2 -0
- package/dist/history.js +11 -0
- package/dist/hover-card.d.ts +137 -0
- package/dist/hover-card.js +153 -0
- package/dist/image-cropper.d.ts +74 -0
- package/dist/image-cropper.js +36 -0
- package/dist/image.d.ts +2 -0
- package/dist/image.js +5 -0
- package/dist/index.d.ts +59 -0
- package/dist/index.js +60 -0
- package/dist/input.d.ts +120 -0
- package/dist/input.js +73 -0
- package/dist/item-icon.d.ts +34 -0
- package/dist/item-icon.js +63 -0
- package/dist/label.d.ts +16 -0
- package/dist/label.js +8 -0
- package/dist/lifecycle.d.ts +11 -0
- package/dist/lifecycle.js +91 -0
- package/dist/list-items.d.ts +38 -0
- package/dist/list-items.js +59 -0
- package/dist/list-text.d.ts +7 -0
- package/dist/list-text.js +15 -0
- package/dist/listbox.d.ts +273 -0
- package/dist/listbox.js +126 -0
- package/dist/menu.d.ts +678 -0
- package/dist/menu.js +607 -0
- package/dist/menubar-context.d.ts +5 -0
- package/dist/menubar-context.js +5 -0
- package/dist/menubar.d.ts +61 -0
- package/dist/menubar.js +48 -0
- package/dist/meter.d.ts +41 -0
- package/dist/meter.js +37 -0
- package/dist/navigation-menu.d.ts +228 -0
- package/dist/navigation-menu.js +195 -0
- package/dist/number-input.d.ts +176 -0
- package/dist/number-input.js +231 -0
- package/dist/number.d.ts +2 -0
- package/dist/number.js +39 -0
- package/dist/nuxt/entries.json +977 -0
- package/dist/nuxt/module.d.ts +18 -0
- package/dist/nuxt/module.js +31 -0
- package/dist/nuxt/registrations.d.ts +22 -0
- package/dist/nuxt/registrations.js +22 -0
- package/dist/observe.d.ts +2 -0
- package/dist/observe.js +7 -0
- package/dist/otp-input.d.ts +142 -0
- package/dist/otp-input.js +130 -0
- package/dist/overlays.d.ts +40 -0
- package/dist/overlays.js +118 -0
- package/dist/pagination.d.ts +201 -0
- package/dist/pagination.js +146 -0
- package/dist/password-input.d.ts +144 -0
- package/dist/password-input.js +134 -0
- package/dist/popover.d.ts +211 -0
- package/dist/popover.js +258 -0
- package/dist/popup.d.ts +60 -0
- package/dist/popup.js +89 -0
- package/dist/preferences.d.ts +44 -0
- package/dist/preferences.js +102 -0
- package/dist/primitive.d.ts +2 -0
- package/dist/primitive.js +11 -0
- package/dist/progress.d.ts +41 -0
- package/dist/progress.js +37 -0
- package/dist/radio.d.ts +164 -0
- package/dist/radio.js +145 -0
- package/dist/rating.d.ts +149 -0
- package/dist/rating.js +146 -0
- package/dist/renderless.d.ts +4 -0
- package/dist/renderless.js +28 -0
- package/dist/resizable.d.ts +54 -0
- package/dist/resizable.js +22 -0
- package/dist/scroll-area.d.ts +72 -0
- package/dist/scroll-area.js +77 -0
- package/dist/segmented-control.d.ts +151 -0
- package/dist/segmented-control.js +110 -0
- package/dist/segmented-input.d.ts +76 -0
- package/dist/segmented-input.js +115 -0
- package/dist/select.d.ts +458 -0
- package/dist/select.js +468 -0
- package/dist/separator.d.ts +14 -0
- package/dist/separator.js +8 -0
- package/dist/shortcuts.d.ts +32 -0
- package/dist/shortcuts.js +56 -0
- package/dist/slider.d.ts +65 -0
- package/dist/slider.js +194 -0
- package/dist/switch.d.ts +103 -0
- package/dist/switch.js +71 -0
- package/dist/tabs.d.ts +338 -0
- package/dist/tabs.js +27 -0
- package/dist/text-control.d.ts +89 -0
- package/dist/text-control.js +51 -0
- package/dist/text-match.d.ts +2 -0
- package/dist/text-match.js +7 -0
- package/dist/textarea.d.ts +106 -0
- package/dist/textarea.js +68 -0
- package/dist/time-input.d.ts +131 -0
- package/dist/time-input.js +32 -0
- package/dist/timeline.d.ts +81 -0
- package/dist/timeline.js +30 -0
- package/dist/toast-parts.d.ts +203 -0
- package/dist/toast-parts.js +270 -0
- package/dist/toast.d.ts +2 -0
- package/dist/toast.js +21 -0
- package/dist/toggle-props.d.ts +22 -0
- package/dist/toggle-props.js +14 -0
- package/dist/toggle.d.ts +199 -0
- package/dist/toggle.js +129 -0
- package/dist/token-input.d.ts +136 -0
- package/dist/token-input.js +214 -0
- package/dist/toolbar-context.d.ts +7 -0
- package/dist/toolbar-context.js +20 -0
- package/dist/toolbar.d.ts +120 -0
- package/dist/toolbar.js +77 -0
- package/dist/tooltip.d.ts +160 -0
- package/dist/tooltip.js +224 -0
- package/dist/tree.d.ts +300 -0
- package/dist/tree.js +209 -0
- package/dist/trigger-menu.d.ts +452 -0
- package/dist/trigger-menu.js +254 -0
- package/dist/use-primitive.d.ts +132 -0
- package/dist/use-primitive.js +462 -0
- package/dist/waterfall.d.ts +201 -0
- package/dist/waterfall.js +171 -0
- package/docs/README.md +89 -0
- package/docs/agents.md +1523 -0
- package/docs/components/accordion.md +1369 -0
- package/docs/components/alert-dialog.md +799 -0
- package/docs/components/autocomplete.md +1857 -0
- package/docs/components/avatar.md +272 -0
- package/docs/components/button.md +435 -0
- package/docs/components/calendar.md +1589 -0
- package/docs/components/carousel.md +1171 -0
- package/docs/components/checkbox.md +1008 -0
- package/docs/components/collapsible.md +536 -0
- package/docs/components/color-picker.md +706 -0
- package/docs/components/combobox.md +3504 -0
- package/docs/components/command.md +1481 -0
- package/docs/components/date-input.md +536 -0
- package/docs/components/date-picker.md +1244 -0
- package/docs/components/dialog.md +1397 -0
- package/docs/components/drawer.md +1166 -0
- package/docs/components/field.md +538 -0
- package/docs/components/file-input.md +611 -0
- package/docs/components/hover-card.md +505 -0
- package/docs/components/image-cropper.md +556 -0
- package/docs/components/input.md +306 -0
- package/docs/components/label.md +203 -0
- package/docs/components/listbox.md +1004 -0
- package/docs/components/menu.md +1229 -0
- package/docs/components/menubar.md +443 -0
- package/docs/components/meter.md +315 -0
- package/docs/components/navigation-menu.md +1523 -0
- package/docs/components/number-input.md +1029 -0
- package/docs/components/otp-input.md +512 -0
- package/docs/components/pagination.md +613 -0
- package/docs/components/password-input.md +649 -0
- package/docs/components/popover.md +1448 -0
- package/docs/components/preferences.md +208 -0
- package/docs/components/progress.md +423 -0
- package/docs/components/radio.md +785 -0
- package/docs/components/rating.md +416 -0
- package/docs/components/resizable.md +910 -0
- package/docs/components/scroll-area.md +915 -0
- package/docs/components/segmented-control.md +435 -0
- package/docs/components/select.md +2015 -0
- package/docs/components/separator.md +229 -0
- package/docs/components/slider.md +1084 -0
- package/docs/components/switch.md +565 -0
- package/docs/components/tabs.md +944 -0
- package/docs/components/textarea.md +299 -0
- package/docs/components/time-input.md +224 -0
- package/docs/components/timeline.md +654 -0
- package/docs/components/toast.md +1224 -0
- package/docs/components/toggle.md +500 -0
- package/docs/components/token-input.md +953 -0
- package/docs/components/toolbar.md +739 -0
- package/docs/components/tooltip.md +818 -0
- package/docs/components/tree.md +1306 -0
- package/docs/components/trigger-menu.md +1223 -0
- package/docs/components/waterfall.md +717 -0
- package/docs/controllers.md +71 -0
- package/docs/core.md +8027 -0
- package/docs/custom-parts.md +89 -0
- package/docs/first-component.md +83 -0
- package/docs/forms.md +122 -0
- package/docs/installation.md +72 -0
- package/docs/introduction.md +32 -0
- package/docs/lists-and-menus.md +122 -0
- package/docs/llms.txt +1502 -0
- package/docs/parts-and-composition.md +85 -0
- package/docs/popups.md +108 -0
- package/docs/rendering.md +56 -0
- package/docs/server-rendering.md +180 -0
- package/docs/state-and-events.md +100 -0
- package/docs/styling-and-animation.md +148 -0
- package/docs/utilities/async-options.md +348 -0
- package/docs/utilities/shortcuts.md +159 -0
- package/package.json +352 -3
|
@@ -0,0 +1,1166 @@
|
|
|
1
|
+
# Drawer
|
|
2
|
+
|
|
3
|
+
A sheet you can open, drag, and resize from an edge of the screen.
|
|
4
|
+
|
|
5
|
+
A drawer gives a task its own sheet without leaving the page. It shares [Dialog’s](./dialog.md) focus and dismissal behavior, then adds dragging, snap points, and a handle you can use with the keyboard.
|
|
6
|
+
|
|
7
|
+
```vue title="basic.vue"
|
|
8
|
+
<script setup lang="ts">
|
|
9
|
+
import { MinusIcon, PlusIcon } from "@lucide/vue"
|
|
10
|
+
import {
|
|
11
|
+
Drawer,
|
|
12
|
+
DrawerBackdrop,
|
|
13
|
+
DrawerClose,
|
|
14
|
+
DrawerContent,
|
|
15
|
+
DrawerDescription,
|
|
16
|
+
DrawerTitle,
|
|
17
|
+
DrawerTrigger,
|
|
18
|
+
} from "@ui-sdk/vue/drawer"
|
|
19
|
+
import { ref } from "vue"
|
|
20
|
+
const goal = { initial: 350, min: 200, max: 400, step: 10 }
|
|
21
|
+
|
|
22
|
+
const calories = ref(goal.initial)
|
|
23
|
+
</script>
|
|
24
|
+
|
|
25
|
+
<template>
|
|
26
|
+
<Drawer>
|
|
27
|
+
<DrawerTrigger>Open Drawer</DrawerTrigger>
|
|
28
|
+
<DrawerBackdrop />
|
|
29
|
+
<DrawerContent>
|
|
30
|
+
<div data-slot="grip" aria-hidden="true" />
|
|
31
|
+
|
|
32
|
+
<div data-slot="stack">
|
|
33
|
+
<DrawerTitle>Move goal</DrawerTitle>
|
|
34
|
+
<DrawerDescription>Set your daily activity goal.</DrawerDescription>
|
|
35
|
+
</div>
|
|
36
|
+
|
|
37
|
+
<div data-slot="row">
|
|
38
|
+
<button
|
|
39
|
+
type="button"
|
|
40
|
+
aria-label="Decrease"
|
|
41
|
+
:disabled="calories <= goal.min"
|
|
42
|
+
@click="calories -= goal.step"
|
|
43
|
+
>
|
|
44
|
+
<MinusIcon aria-hidden="true" />
|
|
45
|
+
</button>
|
|
46
|
+
<div data-slot="stack">
|
|
47
|
+
<div aria-live="polite">{{ calories }}</div>
|
|
48
|
+
<div data-slot="hint">Calories/day</div>
|
|
49
|
+
</div>
|
|
50
|
+
<button
|
|
51
|
+
type="button"
|
|
52
|
+
aria-label="Increase"
|
|
53
|
+
:disabled="calories >= goal.max"
|
|
54
|
+
@click="calories += goal.step"
|
|
55
|
+
>
|
|
56
|
+
<PlusIcon aria-hidden="true" />
|
|
57
|
+
</button>
|
|
58
|
+
</div>
|
|
59
|
+
|
|
60
|
+
<div data-slot="stack">
|
|
61
|
+
<DrawerClose data-variant="solid" value="submit">Submit</DrawerClose>
|
|
62
|
+
<DrawerClose>Cancel</DrawerClose>
|
|
63
|
+
</div>
|
|
64
|
+
</DrawerContent>
|
|
65
|
+
</Drawer>
|
|
66
|
+
</template>
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Open the drawer, adjust the daily goal, then Submit or Cancel. You can also press Escape, press outside, or drag the sheet toward its edge to close it.
|
|
70
|
+
|
|
71
|
+
## Installation
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
npm install @ui-sdk/vue @ui-sdk/core
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Composition
|
|
78
|
+
|
|
79
|
+
Use the following composition to build a `Drawer`:
|
|
80
|
+
|
|
81
|
+
```text
|
|
82
|
+
Drawer
|
|
83
|
+
├── DrawerTrigger
|
|
84
|
+
├── DrawerBackdrop
|
|
85
|
+
└── DrawerContent
|
|
86
|
+
├── DrawerTitle
|
|
87
|
+
├── DrawerDescription
|
|
88
|
+
└── DrawerClose
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
The content is the sheet. The drawer positions it inside a full-screen viewport and moves it with `translate`. Give it a size, a surface, and corners; leave positioning and translation to the drawer. Give the backdrop a color, such as `bg-black/30`; the drawer manages its opacity.
|
|
92
|
+
|
|
93
|
+
## Usage
|
|
94
|
+
|
|
95
|
+
Import the parts and put them together:
|
|
96
|
+
|
|
97
|
+
```vue
|
|
98
|
+
<script setup lang="ts">
|
|
99
|
+
import {
|
|
100
|
+
Drawer,
|
|
101
|
+
DrawerBackdrop,
|
|
102
|
+
DrawerClose,
|
|
103
|
+
DrawerContent,
|
|
104
|
+
DrawerDescription,
|
|
105
|
+
DrawerTitle,
|
|
106
|
+
DrawerTrigger,
|
|
107
|
+
} from "@ui-sdk/vue/drawer"
|
|
108
|
+
</script>
|
|
109
|
+
|
|
110
|
+
<template>
|
|
111
|
+
<Drawer>
|
|
112
|
+
<DrawerTrigger>Filters</DrawerTrigger>
|
|
113
|
+
<DrawerBackdrop />
|
|
114
|
+
<DrawerContent>
|
|
115
|
+
<DrawerTitle>Filters</DrawerTitle>
|
|
116
|
+
<DrawerDescription>Narrow down the results.</DrawerDescription>
|
|
117
|
+
<DrawerClose>Done</DrawerClose>
|
|
118
|
+
</DrawerContent>
|
|
119
|
+
</Drawer>
|
|
120
|
+
</template>
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## Scrollable Content
|
|
124
|
+
|
|
125
|
+
Put long content in an inner `min-h-0 flex-1 overflow-y-auto` area. A downward drag scrolls that area first; when it reaches the top, the same gesture can move the drawer. `initial-focus="content"` starts focus on the sheet itself.
|
|
126
|
+
|
|
127
|
+
```vue title="scrollable.vue"
|
|
128
|
+
<script setup lang="ts">
|
|
129
|
+
import {
|
|
130
|
+
Drawer,
|
|
131
|
+
DrawerBackdrop,
|
|
132
|
+
DrawerClose,
|
|
133
|
+
DrawerContent,
|
|
134
|
+
DrawerDescription,
|
|
135
|
+
DrawerTitle,
|
|
136
|
+
DrawerTrigger,
|
|
137
|
+
} from "@ui-sdk/vue/drawer"
|
|
138
|
+
|
|
139
|
+
const paragraphs = [
|
|
140
|
+
"The drawer rises from any edge, rests on snap points and follows your finger with the same spring as a system sheet.",
|
|
141
|
+
"Snap points take fractions of the screen, pixels, rem, percentages or the content's own size. Points that land within a pixel of each other merge into one.",
|
|
142
|
+
"Dragging a list scrolls it until it reaches the top, and then the same gesture moves the drawer, so closing a long sheet never needs two tries.",
|
|
143
|
+
"The handle steps through the snap points with a press, the arrow keys, Home and End. Screen readers on phones adjust it like a slider.",
|
|
144
|
+
"Below a snap point you choose, the page behind stays usable and undimmed, like a map with a sheet of results.",
|
|
145
|
+
"Drawers opened from inside each other stack, and the one beneath steps back while the new one rises.",
|
|
146
|
+
"The on-screen keyboard pushes the drawer up, and the focused field scrolls into view inside it, never the page.",
|
|
147
|
+
"With reduced motion, drawers fade in and out instead of sliding.",
|
|
148
|
+
]
|
|
149
|
+
</script>
|
|
150
|
+
|
|
151
|
+
<template>
|
|
152
|
+
<Drawer>
|
|
153
|
+
<DrawerTrigger>Scrollable Content</DrawerTrigger>
|
|
154
|
+
<DrawerBackdrop />
|
|
155
|
+
<DrawerContent initial-focus="content">
|
|
156
|
+
<div data-slot="grip" aria-hidden="true" />
|
|
157
|
+
<div data-slot="stack">
|
|
158
|
+
<DrawerTitle>Release notes</DrawerTitle>
|
|
159
|
+
<DrawerDescription>Everything new in the drawer.</DrawerDescription>
|
|
160
|
+
</div>
|
|
161
|
+
<div data-slot="scroll">
|
|
162
|
+
<p data-slot="hint" v-for="(paragraph, index) in [...paragraphs, ...paragraphs]" :key="index">
|
|
163
|
+
{{ paragraph }}
|
|
164
|
+
</p>
|
|
165
|
+
</div>
|
|
166
|
+
<div data-slot="stack">
|
|
167
|
+
<DrawerClose data-variant="solid">Got It</DrawerClose>
|
|
168
|
+
</div>
|
|
169
|
+
</DrawerContent>
|
|
170
|
+
</Drawer>
|
|
171
|
+
</template>
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
Open the long sheet and scroll its text. At the top, drag downward to move the sheet; on a keyboard, Tab reaches the controls and Escape closes it.
|
|
175
|
+
|
|
176
|
+
## Sides
|
|
177
|
+
|
|
178
|
+
`side` chooses bottom, top, left, or right. Logical `start` and `end` follow text direction. The content’s `data-side` tells you which physical edge to style.
|
|
179
|
+
|
|
180
|
+
Side drawers can opt into `prevent-edge-swipe` to keep an edge gesture from starting iOS Safari’s back or forward navigation. It also prevents clicks right at those edges, so use it only when you need that tradeoff.
|
|
181
|
+
|
|
182
|
+
```vue title="sides.vue"
|
|
183
|
+
<script setup lang="ts">
|
|
184
|
+
import {
|
|
185
|
+
Drawer,
|
|
186
|
+
DrawerBackdrop,
|
|
187
|
+
DrawerClose,
|
|
188
|
+
DrawerContent,
|
|
189
|
+
DrawerDescription,
|
|
190
|
+
DrawerTitle,
|
|
191
|
+
DrawerTrigger,
|
|
192
|
+
} from "@ui-sdk/vue/drawer"
|
|
193
|
+
|
|
194
|
+
const sides = [
|
|
195
|
+
{
|
|
196
|
+
side: "top",
|
|
197
|
+
label: "Top",
|
|
198
|
+
title: "Notifications",
|
|
199
|
+
description: "You're all caught up.",
|
|
200
|
+
},
|
|
201
|
+
{
|
|
202
|
+
side: "right",
|
|
203
|
+
label: "Right",
|
|
204
|
+
title: "Cart",
|
|
205
|
+
description: "2 items, $84.00.",
|
|
206
|
+
},
|
|
207
|
+
{
|
|
208
|
+
side: "bottom",
|
|
209
|
+
label: "Bottom",
|
|
210
|
+
title: "Share",
|
|
211
|
+
description: "Send this page to your team.",
|
|
212
|
+
},
|
|
213
|
+
{
|
|
214
|
+
side: "left",
|
|
215
|
+
label: "Left",
|
|
216
|
+
title: "Menu",
|
|
217
|
+
description: "Jump to a section of the docs.",
|
|
218
|
+
},
|
|
219
|
+
] as const
|
|
220
|
+
</script>
|
|
221
|
+
|
|
222
|
+
<template>
|
|
223
|
+
<div data-slot="row">
|
|
224
|
+
<Drawer
|
|
225
|
+
v-for="{ side, label, title, description } in sides"
|
|
226
|
+
:key="side"
|
|
227
|
+
:side="side"
|
|
228
|
+
:prevent-edge-swipe="side === 'left' || side === 'right'"
|
|
229
|
+
>
|
|
230
|
+
<DrawerTrigger>{{ label }}</DrawerTrigger>
|
|
231
|
+
<DrawerBackdrop />
|
|
232
|
+
<DrawerContent>
|
|
233
|
+
<div data-slot="stack">
|
|
234
|
+
<DrawerTitle>{{ title }}</DrawerTitle>
|
|
235
|
+
<DrawerDescription>{{ description }}</DrawerDescription>
|
|
236
|
+
</div>
|
|
237
|
+
<DrawerClose data-variant="solid">Close</DrawerClose>
|
|
238
|
+
</DrawerContent>
|
|
239
|
+
</Drawer>
|
|
240
|
+
</div>
|
|
241
|
+
</template>
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
Open a sheet from each edge. Drag it back toward that edge, press outside, or press Escape to close it.
|
|
245
|
+
|
|
246
|
+
## Snap Points
|
|
247
|
+
|
|
248
|
+
`snap-points` are the places the drawer can rest. It opens at the first, or at `default-snap-point`, and settles at another after a drag. A fast fling can skip intermediate points.
|
|
249
|
+
|
|
250
|
+
| Value | Size |
|
|
251
|
+
| ------------------ | ------------------------------------------ |
|
|
252
|
+
| `0.5` | Half the viewport along the drawer’s axis. |
|
|
253
|
+
| `320` or `"320px"` | Pixels; numbers above 1 are pixel values. |
|
|
254
|
+
| `"20rem"` | A multiple of the root font size. |
|
|
255
|
+
| `"50%"` | A percentage of the viewport. |
|
|
256
|
+
| `"content"` | The sheet’s own size, the default. |
|
|
257
|
+
|
|
258
|
+
The sheet’s CSS size is the limit: `1` cannot make a short sheet fill the screen. Use a height such as `h-[calc(100dvh-3rem)]` when the largest point should nearly fill it. The drawer measures again when content or available space changes; a moved resting point reports `content-resize`.
|
|
259
|
+
|
|
260
|
+
A Handle is a button with an accessible name. Pressing it moves to the next larger snap point, then wraps to the smallest. Arrow keys along the drawer’s axis move one point without wrapping; Home and End move to the ends. `canExpand` and `canCollapse` let the example show which moves remain.
|
|
261
|
+
|
|
262
|
+
For a sheet with one snap point, use a decorative bar instead of an inactive button.
|
|
263
|
+
|
|
264
|
+
```vue title="snap-points.vue"
|
|
265
|
+
<script setup lang="ts">
|
|
266
|
+
import {
|
|
267
|
+
Drawer,
|
|
268
|
+
DrawerBackdrop,
|
|
269
|
+
DrawerContent,
|
|
270
|
+
DrawerDescription,
|
|
271
|
+
DrawerHandle,
|
|
272
|
+
DrawerTitle,
|
|
273
|
+
DrawerTrigger,
|
|
274
|
+
} from "@ui-sdk/vue/drawer"
|
|
275
|
+
|
|
276
|
+
const places = [
|
|
277
|
+
{ name: "Blue Bottle Coffee", detail: "Coffee · 0.2 mi" },
|
|
278
|
+
{ name: "Tartine Bakery", detail: "Bakery · 0.4 mi" },
|
|
279
|
+
{ name: "Dolores Park", detail: "Park · 0.5 mi" },
|
|
280
|
+
{ name: "Mission Dolores", detail: "Landmark · 0.6 mi" },
|
|
281
|
+
{ name: "Ritual Coffee Roasters", detail: "Coffee · 0.7 mi" },
|
|
282
|
+
{ name: "Bi-Rite Creamery", detail: "Ice cream · 0.7 mi" },
|
|
283
|
+
{ name: "Alamo Square", detail: "Park · 1.1 mi" },
|
|
284
|
+
{ name: "The Castro Theatre", detail: "Cinema · 1.2 mi" },
|
|
285
|
+
{ name: "Ferry Building", detail: "Market · 2.3 mi" },
|
|
286
|
+
{ name: "Coit Tower", detail: "Landmark · 2.9 mi" },
|
|
287
|
+
{ name: "Golden Gate Park", detail: "Park · 3.0 mi" },
|
|
288
|
+
{ name: "Lands End", detail: "Trail · 5.4 mi" },
|
|
289
|
+
]
|
|
290
|
+
</script>
|
|
291
|
+
|
|
292
|
+
<template>
|
|
293
|
+
<Drawer :snap-points="[0.25, 0.5, 1]" :default-snap-point="0.5" expand-on-scroll>
|
|
294
|
+
<DrawerTrigger>Find a Place</DrawerTrigger>
|
|
295
|
+
<DrawerBackdrop />
|
|
296
|
+
<DrawerContent>
|
|
297
|
+
<DrawerHandle aria-label="Resize" />
|
|
298
|
+
<div data-slot="stack">
|
|
299
|
+
<DrawerTitle>Places nearby</DrawerTitle>
|
|
300
|
+
<DrawerDescription
|
|
301
|
+
>Drag the drawer, or press the handle, to see more.</DrawerDescription
|
|
302
|
+
>
|
|
303
|
+
</div>
|
|
304
|
+
<div data-slot="scroll">
|
|
305
|
+
<ul data-slot="list">
|
|
306
|
+
<li v-for="place in places" :key="place.name">
|
|
307
|
+
<div>{{ place.name }}</div>
|
|
308
|
+
<div data-slot="hint">{{ place.detail }}</div>
|
|
309
|
+
</li>
|
|
310
|
+
</ul>
|
|
311
|
+
</div>
|
|
312
|
+
</DrawerContent>
|
|
313
|
+
</Drawer>
|
|
314
|
+
</template>
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
Open the sheet at its middle snap point. Drag it, press the handle, or Tab to the handle and use Up, Down, Home and End to try the other resting points.
|
|
318
|
+
|
|
319
|
+
## Controlled
|
|
320
|
+
|
|
321
|
+
Use `v-model:open`, or `v-model:snap-point`, to keep the drawer's state in your component. You can control opening and snap points independently. Cancel a proposed change with `details.cancel()` in `@open-change` or `@snap-point-change`; a canceled swipe springs back. `@open-change-complete` runs after the sheet settles.
|
|
322
|
+
|
|
323
|
+
```vue
|
|
324
|
+
<script setup lang="ts">
|
|
325
|
+
const open = ref(false)
|
|
326
|
+
const snapPoint = ref<SnapPoint>(0.5)
|
|
327
|
+
</script>
|
|
328
|
+
|
|
329
|
+
<template>
|
|
330
|
+
<Drawer
|
|
331
|
+
v-model:open="open"
|
|
332
|
+
:snap-points="[0.25, 0.5, 1]"
|
|
333
|
+
v-model:snap-point="snapPoint"
|
|
334
|
+
>
|
|
335
|
+
<!-- … -->
|
|
336
|
+
</Drawer>
|
|
337
|
+
</template>
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
## Not Dismissible
|
|
341
|
+
|
|
342
|
+
With `dismissible` false, Escape, outside presses, back gestures, and swipes leave the drawer open. `@dismiss-attempt` tells you what was tried, so you can offer a way to discard unsaved work. Close parts, triggers, and controllers can still close it deliberately.
|
|
343
|
+
|
|
344
|
+
```vue
|
|
345
|
+
<Drawer
|
|
346
|
+
:dismissible="false"
|
|
347
|
+
@dismiss-attempt="(details) => (attempt = details.reason)"
|
|
348
|
+
>
|
|
349
|
+
<DrawerTrigger>Write a Post</DrawerTrigger>
|
|
350
|
+
<DrawerBackdrop />
|
|
351
|
+
<DrawerContent>
|
|
352
|
+
<DrawerClose v-if="attempt">Discard</DrawerClose>
|
|
353
|
+
<DrawerClose value="post">Post</DrawerClose>
|
|
354
|
+
</DrawerContent>
|
|
355
|
+
</Drawer>
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
## Modal
|
|
359
|
+
|
|
360
|
+
Set `modal-above` when the page should stay usable beside a small sheet. At or below that point there is no dim, inert page, scroll lock, or `aria-modal`. Above it, `modal` applies. The switch happens when the drawer settles and does not move focus; `data-interactive` exposes the usable-page state.
|
|
361
|
+
|
|
362
|
+
`modal` has the same choices as [Dialog](./dialog.md#modal): `true` blocks the page, `"trap-focus"` keeps Tab inside while leaving the page usable, and `false` allows focus to leave. A click on the page also closes a `"trap-focus"` drawer, while a non-modal drawer closes on an outside press only when `close-on-outside-press` is enabled.
|
|
363
|
+
|
|
364
|
+
```vue title="non-modal.vue"
|
|
365
|
+
<script setup lang="ts">
|
|
366
|
+
import {
|
|
367
|
+
Drawer,
|
|
368
|
+
DrawerBackdrop,
|
|
369
|
+
DrawerClose,
|
|
370
|
+
DrawerContent,
|
|
371
|
+
DrawerDescription,
|
|
372
|
+
DrawerHandle,
|
|
373
|
+
DrawerTitle,
|
|
374
|
+
DrawerTrigger,
|
|
375
|
+
} from "@ui-sdk/vue/drawer"
|
|
376
|
+
import { ref } from "vue"
|
|
377
|
+
|
|
378
|
+
const places = [
|
|
379
|
+
{ name: "Blue Bottle Coffee", detail: "Coffee · 0.2 mi" },
|
|
380
|
+
{ name: "Tartine Bakery", detail: "Bakery · 0.4 mi" },
|
|
381
|
+
{ name: "Dolores Park", detail: "Park · 0.5 mi" },
|
|
382
|
+
{ name: "Mission Dolores", detail: "Landmark · 0.6 mi" },
|
|
383
|
+
{ name: "Ritual Coffee Roasters", detail: "Coffee · 0.7 mi" },
|
|
384
|
+
]
|
|
385
|
+
|
|
386
|
+
const destination = ref(places[0].name)
|
|
387
|
+
</script>
|
|
388
|
+
|
|
389
|
+
<template>
|
|
390
|
+
<div data-slot="stack">
|
|
391
|
+
<ul data-slot="list" aria-label="Places">
|
|
392
|
+
<li v-for="place in places" :key="place.name">
|
|
393
|
+
<button type="button" :aria-pressed="destination === place.name" @click="destination = place.name">
|
|
394
|
+
{{ place.name }}
|
|
395
|
+
<span data-slot="hint">{{ place.detail }}</span>
|
|
396
|
+
</button>
|
|
397
|
+
</li>
|
|
398
|
+
</ul>
|
|
399
|
+
<Drawer :snap-points="[0.2, 0.6]" :modal-above="0.2">
|
|
400
|
+
<DrawerTrigger>Get Directions</DrawerTrigger>
|
|
401
|
+
<DrawerBackdrop />
|
|
402
|
+
<DrawerContent v-slot="{ state }">
|
|
403
|
+
<DrawerHandle aria-label="Resize" />
|
|
404
|
+
<div data-slot="row">
|
|
405
|
+
<div data-slot="stack">
|
|
406
|
+
<DrawerTitle>To {{ destination }}</DrawerTitle>
|
|
407
|
+
<DrawerDescription>
|
|
408
|
+
{{
|
|
409
|
+
state.interactive
|
|
410
|
+
? "12 min walk. Pick another place behind the sheet."
|
|
411
|
+
: "12 min walk. Drag the sheet down to see the places."
|
|
412
|
+
}}
|
|
413
|
+
</DrawerDescription>
|
|
414
|
+
</div>
|
|
415
|
+
<DrawerClose>Done</DrawerClose>
|
|
416
|
+
</div>
|
|
417
|
+
<ol data-slot="stack">
|
|
418
|
+
<li>Head north on Valencia St.</li>
|
|
419
|
+
<li>Turn left onto 18th St.</li>
|
|
420
|
+
<li>Arrive at {{ destination }}.</li>
|
|
421
|
+
</ol>
|
|
422
|
+
</DrawerContent>
|
|
423
|
+
</Drawer>
|
|
424
|
+
</div>
|
|
425
|
+
</template>
|
|
426
|
+
```
|
|
427
|
+
|
|
428
|
+
Open directions at the small snap point and choose another place behind the sheet. Expand it to make the sheet modal, then collapse it to use the page again.
|
|
429
|
+
|
|
430
|
+
## Nested Drawers
|
|
431
|
+
|
|
432
|
+
A drawer opened inside another joins its stack. Escape and outside presses affect the topmost one; closing a parent closes its children. `--drawer-stack` follows the sheets above it as they open and drag, so a parent can scale back with `[scale:calc(1-var(--drawer-stack)*0.04)]`.
|
|
433
|
+
|
|
434
|
+
```vue title="nested.vue"
|
|
435
|
+
<script setup lang="ts">
|
|
436
|
+
import {
|
|
437
|
+
Drawer,
|
|
438
|
+
DrawerBackdrop,
|
|
439
|
+
DrawerClose,
|
|
440
|
+
DrawerContent,
|
|
441
|
+
DrawerDescription,
|
|
442
|
+
DrawerTitle,
|
|
443
|
+
DrawerTrigger,
|
|
444
|
+
} from "@ui-sdk/vue/drawer"
|
|
445
|
+
import { Field, FieldLabel } from "@ui-sdk/vue/field"
|
|
446
|
+
import { Input } from "@ui-sdk/vue/input"
|
|
447
|
+
</script>
|
|
448
|
+
|
|
449
|
+
<template>
|
|
450
|
+
<Drawer>
|
|
451
|
+
<DrawerTrigger>Account</DrawerTrigger>
|
|
452
|
+
<DrawerBackdrop />
|
|
453
|
+
<DrawerContent>
|
|
454
|
+
<div data-slot="grip" aria-hidden="true" />
|
|
455
|
+
<div data-slot="stack">
|
|
456
|
+
<DrawerTitle>Account</DrawerTitle>
|
|
457
|
+
<DrawerDescription>Manage how you sign in.</DrawerDescription>
|
|
458
|
+
</div>
|
|
459
|
+
<dl>
|
|
460
|
+
<div data-slot="row">
|
|
461
|
+
<dt>Email</dt>
|
|
462
|
+
<dd>hollis@example.com</dd>
|
|
463
|
+
</div>
|
|
464
|
+
<div data-slot="row">
|
|
465
|
+
<dt>Password</dt>
|
|
466
|
+
<dd>Changed 3 months ago</dd>
|
|
467
|
+
</div>
|
|
468
|
+
<div data-slot="row">
|
|
469
|
+
<dt>Two-factor</dt>
|
|
470
|
+
<dd>On</dd>
|
|
471
|
+
</div>
|
|
472
|
+
</dl>
|
|
473
|
+
<div data-slot="stack">
|
|
474
|
+
<Drawer>
|
|
475
|
+
<DrawerTrigger>Change Password</DrawerTrigger>
|
|
476
|
+
<DrawerBackdrop />
|
|
477
|
+
<DrawerContent>
|
|
478
|
+
<div data-slot="grip" aria-hidden="true" />
|
|
479
|
+
<div data-slot="stack">
|
|
480
|
+
<DrawerTitle>Change password</DrawerTitle>
|
|
481
|
+
<DrawerDescription>Use at least 12 characters.</DrawerDescription>
|
|
482
|
+
</div>
|
|
483
|
+
<Field>
|
|
484
|
+
<FieldLabel>New password</FieldLabel>
|
|
485
|
+
<Input type="password" />
|
|
486
|
+
</Field>
|
|
487
|
+
<div data-slot="stack">
|
|
488
|
+
<DrawerClose data-variant="solid">Update</DrawerClose>
|
|
489
|
+
</div>
|
|
490
|
+
</DrawerContent>
|
|
491
|
+
</Drawer>
|
|
492
|
+
<DrawerClose data-variant="solid">Done</DrawerClose>
|
|
493
|
+
</div>
|
|
494
|
+
</DrawerContent>
|
|
495
|
+
</Drawer>
|
|
496
|
+
</template>
|
|
497
|
+
```
|
|
498
|
+
|
|
499
|
+
Open Account, then Change Password. The parent steps back as the child opens; Escape closes one sheet at a time.
|
|
500
|
+
|
|
501
|
+
## Forms
|
|
502
|
+
|
|
503
|
+
A Close part’s `@action` handler can return a Promise. The sheet stays open while it runs, including through Escape or a swipe. A rejection leaves the action’s error state available for a retry. See [Alert Dialog’s async action](./alert-dialog.md#async-action) for the shared pending and error contract.
|
|
504
|
+
|
|
505
|
+
`keep-mounted` preserves unfinished fields, and `final-focus` returns focus to the updated profile.
|
|
506
|
+
|
|
507
|
+
```vue
|
|
508
|
+
<DrawerContent keep-mounted :final-focus="() => summary">
|
|
509
|
+
<form ref="form"><!-- fields --></form>
|
|
510
|
+
<DrawerClose v-slot="{ state }" @action="save">
|
|
511
|
+
{{ state.pending ? "Saving…" : state.error ? "Try Again" : "Save Changes" }}
|
|
512
|
+
</DrawerClose>
|
|
513
|
+
</DrawerContent>
|
|
514
|
+
```
|
|
515
|
+
|
|
516
|
+
## Outlets
|
|
517
|
+
|
|
518
|
+
An Outlet makes another element follow the sheet’s progress. Its `keyframes` run from collapsed to fully expanded; this example scales and rounds the inbox behind a compose sheet. An outlet outside the drawer connects through its controller.
|
|
519
|
+
|
|
520
|
+
```vue title="outlet.vue"
|
|
521
|
+
<script setup lang="ts">
|
|
522
|
+
import {
|
|
523
|
+
Drawer,
|
|
524
|
+
DrawerBackdrop,
|
|
525
|
+
DrawerClose,
|
|
526
|
+
DrawerContent,
|
|
527
|
+
DrawerDescription,
|
|
528
|
+
DrawerOutlet,
|
|
529
|
+
DrawerTitle,
|
|
530
|
+
DrawerTrigger,
|
|
531
|
+
} from "@ui-sdk/vue/drawer"
|
|
532
|
+
import { Field, FieldLabel } from "@ui-sdk/vue/field"
|
|
533
|
+
import { Textarea } from "@ui-sdk/vue/textarea"
|
|
534
|
+
import { Input } from "@ui-sdk/vue/input"
|
|
535
|
+
|
|
536
|
+
const messages = [
|
|
537
|
+
{ from: "Inès", text: "The proofs are back from the printer." },
|
|
538
|
+
{ from: "Kofi", text: "Lunch on Thursday?" },
|
|
539
|
+
{ from: "Wren", text: "Pushed the fix for the release build." },
|
|
540
|
+
{ from: "Tomasz", text: "Can you review the launch checklist?" },
|
|
541
|
+
]
|
|
542
|
+
</script>
|
|
543
|
+
|
|
544
|
+
<template>
|
|
545
|
+
<Drawer>
|
|
546
|
+
<div>
|
|
547
|
+
<DrawerOutlet :keyframes="{ scale: [1, 0.94], borderRadius: ['0px', '24px'] }">
|
|
548
|
+
<div data-slot="row">
|
|
549
|
+
<span>Inbox</span>
|
|
550
|
+
<DrawerTrigger data-variant="solid">Compose</DrawerTrigger>
|
|
551
|
+
</div>
|
|
552
|
+
<ul data-slot="list">
|
|
553
|
+
<li v-for="message in messages" :key="message.from">
|
|
554
|
+
<div>{{ message.from }}</div>
|
|
555
|
+
<div data-slot="hint">{{ message.text }}</div>
|
|
556
|
+
</li>
|
|
557
|
+
</ul>
|
|
558
|
+
</DrawerOutlet>
|
|
559
|
+
</div>
|
|
560
|
+
<DrawerBackdrop />
|
|
561
|
+
<DrawerContent>
|
|
562
|
+
<div data-slot="grip" aria-hidden="true" />
|
|
563
|
+
<div data-slot="stack">
|
|
564
|
+
<DrawerTitle>New message</DrawerTitle>
|
|
565
|
+
<DrawerDescription>Write a quick note to the team.</DrawerDescription>
|
|
566
|
+
</div>
|
|
567
|
+
<Field>
|
|
568
|
+
<FieldLabel>To</FieldLabel>
|
|
569
|
+
<Input defaultValue="Design team" />
|
|
570
|
+
</Field>
|
|
571
|
+
<Field>
|
|
572
|
+
<FieldLabel>Message</FieldLabel>
|
|
573
|
+
<Textarea placeholder="What's new?" />
|
|
574
|
+
</Field>
|
|
575
|
+
<div data-slot="stack">
|
|
576
|
+
<DrawerClose data-variant="solid" value="send">Send</DrawerClose>
|
|
577
|
+
</div>
|
|
578
|
+
</DrawerContent>
|
|
579
|
+
</Drawer>
|
|
580
|
+
</template>
|
|
581
|
+
```
|
|
582
|
+
|
|
583
|
+
Open Compose, then drag the sheet slowly. The inbox behind it scales and rounds with the sheet’s progress.
|
|
584
|
+
|
|
585
|
+
## Opening from Anywhere
|
|
586
|
+
|
|
587
|
+
Connect external triggers and the drawer to one `createDrawerController<Payload, Result>()`. Each trigger passes a `payload`; a typed content alias, such as `DrawerContent<SharedFile>`, reads it from `state.payload` in its default slot. This lets one sheet serve every row, including disabled triggers for unavailable actions.
|
|
588
|
+
|
|
589
|
+
Calling `open({ payload })` on the controller returns a Promise with the closing `reason` and `returnValue`. `getSnapPoint()` and `setSnapPoint()` also let code read or move the sheet. The [controller guide](../controllers.md) covers the shared result and payload flow.
|
|
590
|
+
|
|
591
|
+
```vue
|
|
592
|
+
<script setup lang="ts">
|
|
593
|
+
const share = createDrawerController<SharedFile, "copy" | "email">()
|
|
594
|
+
const ShareContent = DrawerContent<SharedFile>
|
|
595
|
+
|
|
596
|
+
async function shareRoadmap() {
|
|
597
|
+
const { reason, returnValue } = await share.open({ payload: roadmap })
|
|
598
|
+
}
|
|
599
|
+
</script>
|
|
600
|
+
|
|
601
|
+
<template>
|
|
602
|
+
<DrawerTrigger :controller="share" :payload="file" :disabled="file.uploading"
|
|
603
|
+
>Share</DrawerTrigger
|
|
604
|
+
>
|
|
605
|
+
|
|
606
|
+
<Drawer :controller="share">
|
|
607
|
+
<DrawerBackdrop />
|
|
608
|
+
<ShareContent v-slot="{ state }">
|
|
609
|
+
<DrawerTitle>Share {{ state.payload?.name }}</DrawerTitle>
|
|
610
|
+
</ShareContent>
|
|
611
|
+
</Drawer>
|
|
612
|
+
</template>
|
|
613
|
+
```
|
|
614
|
+
|
|
615
|
+
## Action Sheet
|
|
616
|
+
|
|
617
|
+
A sheet can offer choices instead of a form. Give each Close part a `value`; the open Promise returns the chosen action. Escape, an outside press, or a swipe returns no value, which this example treats as Cancel.
|
|
618
|
+
|
|
619
|
+
Put the least risky action first because a keyboard or code open starts there. Use an [Alert Dialog](./alert-dialog.md) when a choice needs confirmation.
|
|
620
|
+
|
|
621
|
+
```vue title="action-sheet.vue"
|
|
622
|
+
<script setup lang="ts">
|
|
623
|
+
import {
|
|
624
|
+
createDrawerController,
|
|
625
|
+
Drawer,
|
|
626
|
+
DrawerBackdrop,
|
|
627
|
+
DrawerClose,
|
|
628
|
+
DrawerContent,
|
|
629
|
+
DrawerDescription,
|
|
630
|
+
DrawerTitle,
|
|
631
|
+
} from "@ui-sdk/vue/drawer"
|
|
632
|
+
import { useLog } from "./log"
|
|
633
|
+
|
|
634
|
+
type PhotoAction = "share" | "duplicate" | "delete" | "cancel"
|
|
635
|
+
|
|
636
|
+
const photoActions = createDrawerController<undefined, PhotoAction>()
|
|
637
|
+
const log = useLog()
|
|
638
|
+
|
|
639
|
+
async function choose() {
|
|
640
|
+
const { returnValue = "cancel" } = await photoActions.open()
|
|
641
|
+
log(returnValue === "cancel" ? "Canceled" : `Chose ${returnValue}`)
|
|
642
|
+
}
|
|
643
|
+
</script>
|
|
644
|
+
|
|
645
|
+
<template>
|
|
646
|
+
<div data-slot="row">
|
|
647
|
+
<button type="button" @click="choose">Photo Options</button>
|
|
648
|
+
<Drawer :controller="photoActions">
|
|
649
|
+
<DrawerBackdrop />
|
|
650
|
+
<DrawerContent>
|
|
651
|
+
<div data-slot="stack">
|
|
652
|
+
<DrawerTitle>Beach.jpg</DrawerTitle>
|
|
653
|
+
<DrawerDescription>Taken today at 9:41.</DrawerDescription>
|
|
654
|
+
</div>
|
|
655
|
+
<div data-slot="stack">
|
|
656
|
+
<DrawerClose value="share">Share</DrawerClose>
|
|
657
|
+
<DrawerClose value="duplicate">Duplicate</DrawerClose>
|
|
658
|
+
<DrawerClose value="delete">Delete</DrawerClose>
|
|
659
|
+
<DrawerClose value="cancel">Cancel</DrawerClose>
|
|
660
|
+
</div>
|
|
661
|
+
</DrawerContent>
|
|
662
|
+
</Drawer>
|
|
663
|
+
</div>
|
|
664
|
+
</template>
|
|
665
|
+
```
|
|
666
|
+
|
|
667
|
+
Open Photo Options and choose an action. The console logs the returned value; dismissing the sheet counts as Cancel.
|
|
668
|
+
|
|
669
|
+
## Responsive
|
|
670
|
+
|
|
671
|
+
This recipe uses a media query to choose a Drawer on a narrow screen and a Dialog on a wide screen. It replaces the component tree at the breakpoint, so an open sheet closes and local field edits reset. Lift the open and field values above that branch if they must survive the switch.
|
|
672
|
+
|
|
673
|
+
```vue
|
|
674
|
+
<script setup lang="ts">
|
|
675
|
+
const isDesktop = useMediaQuery("(min-width: 768px)")
|
|
676
|
+
</script>
|
|
677
|
+
|
|
678
|
+
<template>
|
|
679
|
+
<Dialog v-if="isDesktop">
|
|
680
|
+
<DialogTrigger>Edit Profile</DialogTrigger>
|
|
681
|
+
<DialogBackdrop />
|
|
682
|
+
<DialogContent>
|
|
683
|
+
<ProfileForm />
|
|
684
|
+
</DialogContent>
|
|
685
|
+
</Dialog>
|
|
686
|
+
<Drawer v-else>
|
|
687
|
+
<DrawerTrigger>Edit Profile</DrawerTrigger>
|
|
688
|
+
<DrawerBackdrop />
|
|
689
|
+
<DrawerContent>
|
|
690
|
+
<ProfileForm />
|
|
691
|
+
</DrawerContent>
|
|
692
|
+
</Drawer>
|
|
693
|
+
</template>
|
|
694
|
+
```
|
|
695
|
+
|
|
696
|
+
## Driver and Physics
|
|
697
|
+
|
|
698
|
+
`driver` picks how the sheet moves. `"scroll-snap"` uses native scrolling and CSS snap points for a bottom sheet; `"pointer"` uses pointer dragging and spring motion on every side. The default `"auto"` chooses native scrolling for a bottom sheet on a touch screen, and pointer dragging for mouse and pen, other sides, `modal-above`, or `expand-on-scroll` false. `data-driver` reports the active choice.
|
|
699
|
+
|
|
700
|
+
Override part of `sheetPhysics.ios` with `physics` to tune the pointer driver: `response` changes spring timing, `dampingRatio` changes settling, `momentumDampingRatio` affects flings, and `rubberBand` changes resistance past the largest point.
|
|
701
|
+
|
|
702
|
+
```vue
|
|
703
|
+
<Drawer driver="pointer" :physics="{ response: 0.3, dampingRatio: 0.9 }" />
|
|
704
|
+
```
|
|
705
|
+
|
|
706
|
+
## Page Integration
|
|
707
|
+
|
|
708
|
+
`theme-color` dims an existing `<meta name="theme-color">` with the backdrop, so the browser's toolbars can follow it; pages without that tag are left alone. `persistent-elements` keeps selected elements usable while the drawer is modal: an array of elements or selectors, or a function returning elements. Something that must stay above the backdrop also needs its own top-layer surface.
|
|
709
|
+
|
|
710
|
+
Drawers render in place and use the top layer. `container` moves the backdrop and viewport elsewhere, for example into a shadow root or out of a surrounding form. See the shared [popup guide](../popups.md#mounting-and-containers).
|
|
711
|
+
|
|
712
|
+
```vue
|
|
713
|
+
<Drawer theme-color :persistent-elements="['#chat-launcher']">
|
|
714
|
+
<DrawerContent :container="shadowRoot" />
|
|
715
|
+
</Drawer>
|
|
716
|
+
```
|
|
717
|
+
|
|
718
|
+
## Custom Rendering
|
|
719
|
+
|
|
720
|
+
Every part takes a `render` slot, which receives the props to bind and the part's state, and the default slot receives the state too.
|
|
721
|
+
|
|
722
|
+
```vue
|
|
723
|
+
<DrawerTrigger shortcut="mod+j">
|
|
724
|
+
<template #render="{ props, state }">
|
|
725
|
+
<button v-bind="props">{{ state.open ? "Viewing" : "View Details" }}</button>
|
|
726
|
+
</template>
|
|
727
|
+
</DrawerTrigger>
|
|
728
|
+
<DrawerContent v-slot="{ state }">
|
|
729
|
+
<DrawerTitle>
|
|
730
|
+
<template #render="{ props }">
|
|
731
|
+
<h3 v-bind="props">Quarterly report</h3>
|
|
732
|
+
</template>
|
|
733
|
+
</DrawerTitle>
|
|
734
|
+
<DrawerDescription>{{ state.expanded ? "Showing all of it." : "Drag up to see more." }}</DrawerDescription>
|
|
735
|
+
<DrawerClose>
|
|
736
|
+
<template #render="{ props }">
|
|
737
|
+
<a v-bind="props" href="/reports/q3">Open the Full Page</a>
|
|
738
|
+
</template>
|
|
739
|
+
</DrawerClose>
|
|
740
|
+
</DrawerContent>
|
|
741
|
+
```
|
|
742
|
+
|
|
743
|
+
## Styling
|
|
744
|
+
|
|
745
|
+
Each part has a `data-slot`, such as `drawer-content`, and shows its state through the attributes listed under [Data Attributes](#data-attributes).
|
|
746
|
+
|
|
747
|
+
Leave the content's `translate` and the backdrop's opacity to the drawer. You can style scale, corners, colors, and the inner scroll area. A bottom sheet can use an `after` element below its edge to cover the gap during overscroll, as the examples do. The drawer respects reduced motion, fading instead of sliding.
|
|
748
|
+
|
|
749
|
+
### DrawerContent
|
|
750
|
+
- `--drawer-progress`: How far open the sheet is, from 0 closed to 1 at its largest snap point. Never past 1.
|
|
751
|
+
- `--drawer-dim`: How dim the page behind is, from 0 to 1. The backdrop's opacity follows it.
|
|
752
|
+
- `--drawer-expand`: 0 at the second-largest snap point and below, 1 at the largest. With one snap point, the whole travel.
|
|
753
|
+
- `--drawer-stack`: How many sheets opened from inside this one are open above it, rising smoothly as each one opens. Push it back with it.
|
|
754
|
+
|
|
755
|
+
### Viewport
|
|
756
|
+
- `--keyboard-inset`: How many pixels of the page the on-screen keyboard covers, 0 without one.
|
|
757
|
+
- `--visual-viewport-width`: The width of the part of the page you can see.
|
|
758
|
+
- `--visual-viewport-height`: The height of the part of the page you can see, above the keyboard.
|
|
759
|
+
- `--visual-viewport-top`: How far the part of the page you can see is scrolled from the top of the layout, as when the keyboard pushes it up.
|
|
760
|
+
|
|
761
|
+
### DrawerOutlet
|
|
762
|
+
- `--drawer-progress`: How far open the sheet is, from 0 closed to 1 at its largest snap point. Never past 1.
|
|
763
|
+
- `--drawer-dim`: How dim the page behind is, from 0 to 1. The backdrop's opacity follows it.
|
|
764
|
+
- `--drawer-expand`: 0 at the second-largest snap point and below, 1 at the largest. With one snap point, the whole travel.
|
|
765
|
+
|
|
766
|
+
## Data Attributes
|
|
767
|
+
|
|
768
|
+
### DrawerTrigger
|
|
769
|
+
`[data-slot="drawer-trigger"]`
|
|
770
|
+
|
|
771
|
+
- `data-closed`: Present while the drawer is closed, including while it animates out.
|
|
772
|
+
- `data-disabled`: Present when the trigger is disabled.
|
|
773
|
+
- `data-open`: Present while the drawer is open. On a trigger, while it's open from that trigger.
|
|
774
|
+
|
|
775
|
+
### DrawerBackdrop
|
|
776
|
+
`[data-slot="drawer-backdrop"]`
|
|
777
|
+
|
|
778
|
+
- `data-closed`: Present while the drawer is closed, including while it animates out.
|
|
779
|
+
- `data-open`: Present while the drawer is open. On a trigger, while it's open from that trigger.
|
|
780
|
+
- `data-interactive`: Present while it rests at or below `modalAbove`, so the page behind is usable. The backdrop lets presses through.
|
|
781
|
+
- `data-starting-style`: Present for the first frame. The drawer slides itself, so leave the content's translate and the backdrop's opacity alone.
|
|
782
|
+
- `data-ending-style`: Present while the drawer animates out.
|
|
783
|
+
- `data-dragging`: Present while a finger, mouse or pen drags it.
|
|
784
|
+
|
|
785
|
+
### Viewport
|
|
786
|
+
`[data-slot="drawer-viewport"]`
|
|
787
|
+
|
|
788
|
+
- `data-side` (`top`, `right`, `bottom`, `left`): The edge it comes from, with `start` and `end` resolved for the writing direction.
|
|
789
|
+
- `data-closed`: Present while the drawer is closed, including while it animates out.
|
|
790
|
+
- `data-open`: Present while the drawer is open. On a trigger, while it's open from that trigger.
|
|
791
|
+
- `data-keyboard`: Present on the viewport while the on-screen keyboard covers part of the page.
|
|
792
|
+
|
|
793
|
+
### DrawerContent
|
|
794
|
+
`[data-slot="drawer-content"]`
|
|
795
|
+
|
|
796
|
+
- `data-closed`: Present while the drawer is closed, including while it animates out.
|
|
797
|
+
- `data-side` (`top`, `right`, `bottom`, `left`): The edge it comes from, with `start` and `end` resolved for the writing direction.
|
|
798
|
+
- `data-open`: Present while the drawer is open. On a trigger, while it's open from that trigger.
|
|
799
|
+
- `data-snap-point` (`content`, `0.2`): The snap point it rests on or is moving to, as written, like `0.5` or `content`.
|
|
800
|
+
- `data-interactive`: Present while it rests at or below `modalAbove`, so the page behind is usable. The backdrop lets presses through.
|
|
801
|
+
- `data-starting-style`: Present for the first frame. The drawer slides itself, so leave the content's translate and the backdrop's opacity alone.
|
|
802
|
+
- `data-ending-style`: Present while the drawer animates out.
|
|
803
|
+
- `data-driver` (`pointer`, `scroll-snap`): What moves it.
|
|
804
|
+
- `data-expanded`: Present while it rests at its largest snap point.
|
|
805
|
+
- `data-dragging`: Present while a finger, mouse or pen drags it.
|
|
806
|
+
|
|
807
|
+
### DrawerHandle
|
|
808
|
+
`[data-slot="drawer-handle"]`
|
|
809
|
+
|
|
810
|
+
- `data-snap-point` (`content`, `0.2`): The snap point it rests on or is moving to, as written, like `0.5` or `content`.
|
|
811
|
+
- `data-expanded`: Present while it rests at its largest snap point.
|
|
812
|
+
|
|
813
|
+
### DrawerClose
|
|
814
|
+
`[data-slot="drawer-close"]`
|
|
815
|
+
|
|
816
|
+
- `data-pending`: Present on a Close part while its action runs.
|
|
817
|
+
|
|
818
|
+
### DrawerOutlet
|
|
819
|
+
`[data-slot="drawer-outlet"]`
|
|
820
|
+
|
|
821
|
+
- `data-closed`: Present while the drawer is closed, including while it animates out.
|
|
822
|
+
- `data-open`: Present while the drawer is open. On a trigger, while it's open from that trigger.
|
|
823
|
+
|
|
824
|
+
## API Reference
|
|
825
|
+
|
|
826
|
+
Props are the same as below, and callbacks are events.
|
|
827
|
+
|
|
828
|
+
### Drawer
|
|
829
|
+
|
|
830
|
+
- `debug?` (`boolean`): Logs every state change with its reason to the console, in development builds.
|
|
831
|
+
- `container?` (`DocumentFragment | Element | null`): Renders the popup into this element instead of in place, like a container inside a shadow root or an iframe. On web components, a CSS selector. Nested popups stay inside their parent.
|
|
832
|
+
- `open?` (`boolean`): Whether the dialog is open. Pass it to control the dialog.
|
|
833
|
+
- `defaultOpen?` (`boolean`): Whether the dialog starts open, when uncontrolled. Focus moves into it once it's on the page.
|
|
834
|
+
- `@open-change-complete` (`((open: boolean) => void)`): Runs once the dialog has finished opening or closing, after any animation.
|
|
835
|
+
- `dismissible?` (`boolean`): Whether Escape, an outside press and Android's back gesture can close the dialog. Close parts, triggers and the controller always can. Pass `false` while a form has unsaved changes, and ask in `@dismiss-attempt`.
|
|
836
|
+
- `persistentElements?` (`(string | Element)[] | (() => Element[])`): Elements that stay usable while the dialog makes the page inert, like a chat launcher or a password manager's button. Elements, CSS selectors, or a function that returns elements, read when the dialog opens. Presses on them never close it.
|
|
837
|
+
- `pendingAnnouncement?` (`string`): What screen readers hear once a Close part's action has been running for a second, so a slow action doesn't pass in silence. Set it in the page's language. An empty string says nothing.
|
|
838
|
+
- `@open-change` (`((open: boolean, details: DialogOpenChangeDetails<DrawerOpenChangeReason>) => void)`): Runs when the drawer wants to open or close. `details.reason` says why, `"swipe"` included, `details.cancel()` stops it, and `details.returnValue` carries what closed it.
|
|
839
|
+
- `@payload-change` (`((payload: unknown, details: ChangeDetails<DrawerPayloadChangeReason>) => void)`): Runs when the payload the content shows changes: a trigger with another payload opens the drawer, or takes a non-modal drawer over while it's open, which fires no `@open-change`, and so does a controller's `open({ payload })` on the open drawer. `details.cancel()` keeps the previous payload.
|
|
840
|
+
- `@dismiss-attempt` (`((details: DrawerDismissAttemptDetails) => void)`): Runs when a dismissal was refused because `dismissible` is false, including a swipe. The drawer resists and springs back. Ask "Discard changes?" here.
|
|
841
|
+
- `modal?` (`"trap-focus" | boolean`): `true`: the rest of the page is inert and doesn't scroll, focus is trapped, and an outside press only closes the drawer. `"trap-focus"`: traps focus and leaves the page usable. `false`: a drawer beside the page. See `modalAbove` to make it modal only above a snap point.
|
|
842
|
+
- `closeOnOutsidePress?` (`boolean`): Whether pressing outside the drawer, like on its backdrop, closes it.
|
|
843
|
+
- `controller?` (`DrawerController<any, any>`): Opens, closes and moves the drawer from anywhere, and connects triggers and outlets outside it. Create one with `createDrawerController()`.
|
|
844
|
+
- `snapPoints?` (`SnapPoint[]`): Where the drawer can rest, from the edge it comes from: a fraction of the screen up to 1, pixels above 1, `"…px"`, `"…rem"`, `"…%"`, or `"content"` for its own size. None can be larger than the drawer, which you size with CSS.
|
|
845
|
+
- `snapPoint?` (`SnapPoint | null`): The snap point it rests on. Pass it to control it.
|
|
846
|
+
- `defaultSnapPoint?` (`SnapPoint`): The snap point it opens at, when uncontrolled. It opens there again each time.
|
|
847
|
+
- `@snap-point-change` (`((snapPoint: SnapPoint, details: ChangeDetails<DrawerSnapPointChangeReason>) => void)`): Runs when the drawer moves to another snap point. `details.reason` says why: a swipe, the handle, the keyboard, a resize or the controller.
|
|
848
|
+
- `side?` (`Side`): The edge it comes from. `"start"` and `"end"` follow the writing direction.
|
|
849
|
+
- `modalAbove?` (`SnapPoint`): At or below this snap point the page stays usable and undimmed, like Maps: no inert page, no scroll lock, no `aria-modal`, and presses beside the drawer reach the page. Above it, `modal` applies. Changes once the drawer comes to rest.
|
|
850
|
+
- `driver?` (`SheetDriverName`): How it moves. `"pointer"` follows touch, mouse and pen with a spring fitted to iOS. `"scroll-snap"` uses the browser's own scrolling for bottom drawers. `"auto"` picks scroll snap for a bottom drawer on a touch screen, unless `modalAbove` is set or `expandOnScroll` is false, and the pointer driver otherwise.
|
|
851
|
+
- `expandOnScroll?` (`boolean`): Whether dragging toward a larger snap point on scrollable content moves the drawer first, until it's at its largest.
|
|
852
|
+
- `physics?` (`Partial<SheetPhysics>`): Overrides the motion: spring, projection, rubber band and dim. Starts from `sheetPhysics.ios`.
|
|
853
|
+
- `themeColor?` (`boolean`): Whether `<meta name="theme-color">` dims with the backdrop, so Safari's toolbars darken too. Written where motion starts and ends, never per frame.
|
|
854
|
+
- `preventEdgeSwipe?` (`boolean`): Whether presses on the drawer near the screen's left and right edges are kept from starting iOS Safari's back and forward swipe. Taps right at those edges then don't click. Read when the content mounts.
|
|
855
|
+
|
|
856
|
+
### DrawerTrigger
|
|
857
|
+
|
|
858
|
+
A trigger outside the drawer also takes `controller`.
|
|
859
|
+
|
|
860
|
+
- `disabled?` (`boolean`): Stops the trigger from opening the dialog. A native button can't be focused or pressed, unless `focusableWhenDisabled` is set.
|
|
861
|
+
- `focusableWhenDisabled?` (`boolean`): Keeps a disabled trigger in the tab order with `aria-disabled` instead of the native attribute, so it can host a tooltip that says why. Presses still do nothing.
|
|
862
|
+
- `payload?` (`unknown`): Data for the content to render when this trigger opens the dialog, like the row it belongs to.
|
|
863
|
+
- `shortcut?` (`string`): A keyboard shortcut that presses the trigger, like `"mod+k"`. `mod` is Command on Apple platforms and Control elsewhere. Sets `aria-keyshortcuts`, and a Shortcut part inside shows it. A modal dialog pauses the page's shortcuts while it's open.
|
|
864
|
+
- `controller?` (`PopupController<any, DialogOpenChangeReason, {}, any, DialogPayloadChangeReason>`): Connects a trigger outside the dialog, like one per table row, to the dialog with this controller.
|
|
865
|
+
|
|
866
|
+
### DrawerBackdrop
|
|
867
|
+
|
|
868
|
+
Dims the page behind a modal drawer, which manages its opacity. Renders a `div`.
|
|
869
|
+
|
|
870
|
+
### DrawerContent
|
|
871
|
+
|
|
872
|
+
- `container?` (`DocumentFragment | Element | null`): Renders the popup into this element instead of in place, like a container inside a shadow root or an iframe. On web components, a CSS selector. Nested popups stay inside their parent.
|
|
873
|
+
- `initialFocus?` (`DialogInitialFocus`): Where focus goes when the dialog opens. Opening with touch focuses the dialog itself, so no on-screen keyboard appears.
|
|
874
|
+
- `finalFocus?` (`PopupFocusTarget`): Where focus goes when the dialog closes while focus is inside it.
|
|
875
|
+
- `keepMounted?` (`boolean`): Whether the dialog stays in the page, hidden, while closed. For animation libraries that drive the exit from state.
|
|
876
|
+
|
|
877
|
+
### DrawerHandle
|
|
878
|
+
|
|
879
|
+
Resizes the sheet: a press moves to the next snap point, and arrow keys, Home and End choose one. Renders a `button`.
|
|
880
|
+
|
|
881
|
+
### DrawerTitle
|
|
882
|
+
|
|
883
|
+
Names the drawer. Renders an `h2`.
|
|
884
|
+
|
|
885
|
+
### DrawerDescription
|
|
886
|
+
|
|
887
|
+
Describes the drawer while it's rendered. Renders a `p`.
|
|
888
|
+
|
|
889
|
+
### DrawerClose
|
|
890
|
+
|
|
891
|
+
- `value?` (`string`): Reported as `returnValue` in `@open-change` and by the controller's `open()`. `createConfirm()` resolves `true` for `"confirm"`.
|
|
892
|
+
- `action?` (`((event: Event | undefined, details: ActionDetails) => unknown)`): Runs when the part is pressed, before the dialog closes. A returned Promise keeps the dialog open while it runs: the part gets `data-pending`, `aria-busy` and `aria-disabled`, screen readers hear the dialog's `pendingAnnouncement` after a second, and nothing but the controller closes the dialog. It closes with reason `"action"` once the Promise resolves. A rejection keeps it open and puts the reason in the part's `error` state until the next press, or until the dialog opens again. `details.source` says how the part was pressed, for changes made after an `await`.
|
|
893
|
+
|
|
894
|
+
### DrawerShortcut
|
|
895
|
+
|
|
896
|
+
- `shortcut?` (`string`): The keys to show. Inside a trigger, its `shortcut`.
|
|
897
|
+
|
|
898
|
+
### DrawerOutlet
|
|
899
|
+
|
|
900
|
+
An outlet outside the drawer also takes `controller`.
|
|
901
|
+
|
|
902
|
+
- `keyframes?` (`SheetKeyframes`): Keyframes it plays as the drawer expands, like `{ scale: [1, 0.94] }`: the first while collapsed, the last at the largest snap point. They run on the compositor when they're transforms or opacity.
|
|
903
|
+
- `controller?` (`DrawerController<any, any>`): Connects an outlet outside the drawer, like the app's shell, to the drawer with this controller.
|
|
904
|
+
|
|
905
|
+
### State
|
|
906
|
+
|
|
907
|
+
What render functions, state-based class names and slots receive, per part.
|
|
908
|
+
|
|
909
|
+
`DrawerTrigger`:
|
|
910
|
+
|
|
911
|
+
- `open` (`boolean`): Whether the dialog is open from this trigger.
|
|
912
|
+
- `disabled` (`boolean`): Set by the trigger's `disabled` prop, which stops it opening the dialog.
|
|
913
|
+
|
|
914
|
+
`DrawerBackdrop`:
|
|
915
|
+
|
|
916
|
+
- `open` (`boolean`): Whether the dialog is open. False while it animates out.
|
|
917
|
+
- `nested` (`boolean`): Whether the dialog was opened from inside another dialog.
|
|
918
|
+
- `nestedOpen` (`boolean`): Whether a dialog opened from inside this one is open.
|
|
919
|
+
- `interactive` (`boolean`): Whether the page behind is usable, so the backdrop lets presses through.
|
|
920
|
+
|
|
921
|
+
`DrawerContent`:
|
|
922
|
+
|
|
923
|
+
- `open` (`boolean`): Whether the dialog is open. False while it animates out.
|
|
924
|
+
- `modal` (`boolean | "trap-focus"`): The `modal` setting. Always true for an alert dialog.
|
|
925
|
+
- `nested` (`boolean`): Whether the dialog was opened from inside another dialog.
|
|
926
|
+
- `nestedOpen` (`boolean`): Whether a dialog opened from inside this one is open.
|
|
927
|
+
- `stack` (`number`): How many dialogs are open above this one, nested inside it.
|
|
928
|
+
- `payload` (`Payload | undefined`): The payload of the last open, from the trigger that opened it or a controller, typed as the controller's `Payload`.
|
|
929
|
+
- `pending` (`boolean`): Whether a Close part's action is running.
|
|
930
|
+
- `snapPoint` (`SnapPoint | null`): The snap point it rests on or is moving to.
|
|
931
|
+
- `expanded` (`boolean`): Whether it's at its largest snap point.
|
|
932
|
+
- `dragging` (`boolean`): Whether a finger, mouse or pen is dragging it.
|
|
933
|
+
- `side` (`PhysicalSide`): The edge it comes from, with `start` and `end` resolved.
|
|
934
|
+
- `interactive` (`boolean`): Whether the page behind is usable, because it rests at or below `modalAbove`.
|
|
935
|
+
|
|
936
|
+
`DrawerHandle`:
|
|
937
|
+
|
|
938
|
+
- `snapPoint` (`SnapPoint | null`): The snap point it rests on.
|
|
939
|
+
- `canExpand` (`boolean`): Whether there's a larger snap point to move to.
|
|
940
|
+
- `canCollapse` (`boolean`): Whether there's a smaller snap point to move to.
|
|
941
|
+
|
|
942
|
+
`DrawerClose`:
|
|
943
|
+
|
|
944
|
+
- `pending` (`boolean`): Whether this part's action is running.
|
|
945
|
+
- `error` (`unknown`): Why this part's last action failed, until it's pressed again or the dialog opens again.
|
|
946
|
+
|
|
947
|
+
`DrawerOutlet`:
|
|
948
|
+
|
|
949
|
+
- `open` (`boolean`): Whether the drawer is open. False as soon as it starts closing, while it still animates out.
|
|
950
|
+
|
|
951
|
+
### Reasons
|
|
952
|
+
|
|
953
|
+
`details.reason` says why the drawer opened or closed.
|
|
954
|
+
|
|
955
|
+
- `trigger-press` (`MouseEvent | KeyboardEvent | TouchEvent`): Click, tap, Enter or Space on the part that opens, closes or toggles. Arrow keys that open a menu or submenu count too. A tap on a combobox's input that opens a sheet reports its `touchend`.
|
|
956
|
+
- `close-press` (`MouseEvent | KeyboardEvent | SubmitEvent`): A Close part was pressed, or a form with `method="dialog"` was submitted.
|
|
957
|
+
- `outside-press` (`MouseEvent`): A press outside the layer.
|
|
958
|
+
- `escape-key` (`KeyboardEvent`): Escape, or a submenu's close key (ArrowLeft in left-to-right layouts).
|
|
959
|
+
- `parent-close` (`none`): The parent layer closed.
|
|
960
|
+
- `back` (`Event`): Going back: the Android back button or gesture, or Backspace in an empty command input, which returns to the previous page.
|
|
961
|
+
- `action` (`MouseEvent | KeyboardEvent`): A Close part's `action` finished.
|
|
962
|
+
- `shortcut` (`KeyboardEvent`): A keyboard shortcut, like a trigger's `shortcut`.
|
|
963
|
+
- `swipe` (`TouchEvent | PointerEvent`): A swipe gesture: a finger, mouse or pen dragged it.
|
|
964
|
+
- `imperative` (`none`): A controller or `api` call, or a property set on a web component.
|
|
965
|
+
|
|
966
|
+
For a payload change, it says what opened the drawer or took it over.
|
|
967
|
+
|
|
968
|
+
- `trigger-press` (`MouseEvent | KeyboardEvent | TouchEvent`): Click, tap, Enter or Space on the part that opens, closes or toggles. Arrow keys that open a menu or submenu count too. A tap on a combobox's input that opens a sheet reports its `touchend`.
|
|
969
|
+
- `shortcut` (`KeyboardEvent`): A keyboard shortcut, like a trigger's `shortcut`.
|
|
970
|
+
- `imperative` (`none`): A controller or `api` call, or a property set on a web component.
|
|
971
|
+
|
|
972
|
+
Why it moved to another snap point:
|
|
973
|
+
|
|
974
|
+
- `back` (`Event`): Going back: the Android back button or gesture, or Backspace in an empty command input, which returns to the previous page.
|
|
975
|
+
- `swipe` (`TouchEvent | PointerEvent`): A swipe gesture: a finger, mouse or pen dragged it.
|
|
976
|
+
- `imperative` (`none`): A controller or `api` call, or a property set on a web component.
|
|
977
|
+
- `handle-press` (`MouseEvent | KeyboardEvent`): A drawer's handle was pressed, which moved it to its next snap point.
|
|
978
|
+
- `handle-key` (`KeyboardEvent`): Arrow keys, Home or End on a drawer's handle moved it between snap points.
|
|
979
|
+
- `content-resize` (`none`): The content or the screen changed size, and the drawer's snap point or the carousel's page went away, so it moved to the nearest one.
|
|
980
|
+
|
|
981
|
+
The dismissals `dismissible` can refuse:
|
|
982
|
+
|
|
983
|
+
- `outside-press` (`MouseEvent`): A press outside the layer.
|
|
984
|
+
- `escape-key` (`KeyboardEvent`): Escape, or a submenu's close key (ArrowLeft in left-to-right layouts).
|
|
985
|
+
- `back` (`Event`): Going back: the Android back button or gesture, or Backspace in an empty command input, which returns to the previous page.
|
|
986
|
+
- `swipe` (`TouchEvent | PointerEvent`): A swipe gesture: a finger, mouse or pen dragged it.
|
|
987
|
+
|
|
988
|
+
### Controller
|
|
989
|
+
|
|
990
|
+
Create one with `createDrawerController<Payload, Result>()` and pass it as `controller`, to the drawer and to any
|
|
991
|
+
triggers and outlets outside it.
|
|
992
|
+
|
|
993
|
+
Every write method takes an optional `{ reason, event }`, passed to the events. Closing with a controller always works, even when the drawer isn't dismissible or an action is running.
|
|
994
|
+
|
|
995
|
+
- `isOpen()` (`() => boolean`): Whether it's open. False as soon as it starts closing, while it still animates out.
|
|
996
|
+
- `setOpen(open, options?)` (`(open: boolean, options?: PopupChangeOptions<DrawerOpenChangeReason> | undefined) => boolean`): Opens or closes it. Returns false when the change was canceled or it was already open or closed.
|
|
997
|
+
- `open(options?)` (`(options?: (PopupChangeOptions<DialogPayloadChangeReason> & { payload?: Payload | undefined; anchor?: Anchor | undefined; signal?: AbortSignal | undefined; }) | undefined) => Promise<...>`): Opens it, and resolves once it closes, with why, how and any return value. Resolves exactly once and never rejects: on the next close from any source, when `signal` aborts, or with reason `"unmount"` when the component leaves the page.
|
|
998
|
+
- `close(options?)` (`(options?: (PopupChangeOptions<DrawerOpenChangeReason> & { returnValue?: Result | undefined; }) | undefined) => boolean`): Closes it. `returnValue` is passed to the promise `open()` returned. Returns false when the close was canceled or it was already closed.
|
|
999
|
+
- `toggle(options?)` (`(options?: PopupChangeOptions<DrawerOpenChangeReason> | undefined) => boolean`): Opens it when it's closed, and closes it when it's open. Returns false when the change was canceled.
|
|
1000
|
+
- `getPayload()` (`() => Payload | undefined`): The payload of the last open, from a controller or the trigger that opened it.
|
|
1001
|
+
- `focus()` (`() => void`): Moves focus to the trigger that opened it last, or the first trigger.
|
|
1002
|
+
- `getSnapPoint()` (`() => SnapPoint | null`): The snap point it rests on, or null before it first opens.
|
|
1003
|
+
- `setSnapPoint(snapPoint, options?)` (`(snapPoint: SnapPoint, options?: ChangeOptions<DrawerSnapPointChangeReason> | undefined) => boolean`): Moves it to a snap point. While closed, it opens there next. Returns false when the change was canceled or it was already there.
|
|
1004
|
+
|
|
1005
|
+
### Events
|
|
1006
|
+
|
|
1007
|
+
Events get the new value first, then the details. `v-model` only updates when its change event wasn't canceled.
|
|
1008
|
+
|
|
1009
|
+
| Binding | On | Receives |
|
|
1010
|
+
| ----------------------- | -------- | ------------------------------------------------------------------------------ |
|
|
1011
|
+
| `v-model:open` | `Drawer` | Whether the drawer is open |
|
|
1012
|
+
| `v-model:snap-point` | `Drawer` | The snap point it rests on |
|
|
1013
|
+
| `@open-change` | `Drawer` | `(open, details)`: the new state, the [reason](#reasons) and any `returnValue` |
|
|
1014
|
+
| `@open-change-complete` | `Drawer` | `(open)`, once it has settled |
|
|
1015
|
+
| `@payload-change` | `Drawer` | `(payload, details)`: the content's new payload, and the [reason](#reasons) |
|
|
1016
|
+
| `@snap-point-change` | `Drawer` | `(snapPoint, details)`: the new snap point and the [reason](#reasons) |
|
|
1017
|
+
| `@dismiss-attempt` | `Drawer` | `({ reason, event })`, when a dismissal was refused |
|
|
1018
|
+
|
|
1019
|
+
## Accessibility
|
|
1020
|
+
|
|
1021
|
+
The trigger is a button that opens a dialog, and the drawer follows the [WAI-ARIA modal dialog pattern](https://www.w3.org/WAI/ARIA/apg/patterns/dialog-modal/) while it's modal: `aria-modal`, focus trapped inside, the page inert, labelled by its title and described by its description. Escape closes it. The handle is a button that controls the drawer: a press moves to the next snap point, arrow keys along the drawer's axis step, and Home and End go to the ends. Every line below is an automated test.
|
|
1022
|
+
|
|
1023
|
+
### Keyboard
|
|
1024
|
+
|
|
1025
|
+
| Key | Does |
|
|
1026
|
+
| ------------------------- | ----------------------------------------------------------------------------- |
|
|
1027
|
+
| Enter, Space | On the trigger, opens the drawer; on the handle, moves to the next snap point |
|
|
1028
|
+
| Arrow keys along the axis | On the handle, moves one snap point without wrapping |
|
|
1029
|
+
| Home, End | On the handle, moves to the smallest or largest snap point |
|
|
1030
|
+
| Tab, Shift+Tab | Moves through the sheet's controls, staying inside while it's modal |
|
|
1031
|
+
| Escape | Closes the topmost drawer when it's dismissible |
|
|
1032
|
+
|
|
1033
|
+
It shares [Dialog’s focus behavior](./dialog.md#focus): focus moves inside on open and returns when it closes. A touch open focuses the content so a field does not summon the keyboard immediately. When the on-screen keyboard opens, the viewport shrinks and the focused field can scroll into view inside the sheet.
|
|
1034
|
+
|
|
1035
|
+
### Tested Behavior
|
|
1036
|
+
|
|
1037
|
+
**Dialog**
|
|
1038
|
+
|
|
1039
|
+
- The trigger advertises a dialog.
|
|
1040
|
+
- The trigger opens a modal dialog named by its title and described by its description.
|
|
1041
|
+
- Opening moves focus into the drawer and closing returns it to the trigger.
|
|
1042
|
+
- Tab stays inside the drawer.
|
|
1043
|
+
- Escape closes it with the escape-key reason.
|
|
1044
|
+
- Pressing the backdrop closes it.
|
|
1045
|
+
- A Close part closes it.
|
|
1046
|
+
- Buttons inside it work without closing it.
|
|
1047
|
+
- The page behind is hidden from assistive technology while it's open.
|
|
1048
|
+
- Opening and closing never scroll or restyle the page.
|
|
1049
|
+
- A controller opens it from outside.
|
|
1050
|
+
|
|
1051
|
+
**Sheet**
|
|
1052
|
+
|
|
1053
|
+
- It rises from the bottom and rests against it at its own size.
|
|
1054
|
+
- It opens at the first snap point, a fraction of the screen.
|
|
1055
|
+
- A slow drag settles on the nearest snap point and reports the swipe.
|
|
1056
|
+
- A drag down past the smallest snap point closes it with the swipe reason.
|
|
1057
|
+
- A short fast flick down closes it, though it moved less than half its height.
|
|
1058
|
+
- The same distance, slowly, settles back.
|
|
1059
|
+
- A fling up from the smallest snap point can pass the middle one.
|
|
1060
|
+
- A press while it rises catches it and holds it under the finger.
|
|
1061
|
+
- A short drag back up keeps it open.
|
|
1062
|
+
- A click on a button inside it isn't a drag.
|
|
1063
|
+
- With side="…" it rests against the … edge.
|
|
1064
|
+
- With side="left" a drag toward the left closes it.
|
|
1065
|
+
|
|
1066
|
+
**Touch**
|
|
1067
|
+
|
|
1068
|
+
- A touch drag down closes it.
|
|
1069
|
+
|
|
1070
|
+
**Handle**
|
|
1071
|
+
|
|
1072
|
+
- Pressing it moves to the next snap point and wraps.
|
|
1073
|
+
- Arrow keys step without wrapping, and Home and End go to the ends.
|
|
1074
|
+
- Moving it moves the drawer to the snap point's extent.
|
|
1075
|
+
- A snap point a controller sets while it animates closed is where it opens next.
|
|
1076
|
+
- A controller moves it with the imperative reason.
|
|
1077
|
+
|
|
1078
|
+
**Not dismissible**
|
|
1079
|
+
|
|
1080
|
+
- Escape reports an attempt and keeps it open.
|
|
1081
|
+
- A press on the backdrop reports an attempt and keeps it open.
|
|
1082
|
+
- A swipe down resists, springs back and reports an attempt.
|
|
1083
|
+
|
|
1084
|
+
**Modal above a snap point**
|
|
1085
|
+
|
|
1086
|
+
- At that snap point the page stays usable and the drawer isn't modal.
|
|
1087
|
+
- Above it the drawer becomes modal, and back down the page is usable again.
|
|
1088
|
+
- The switch doesn't move focus.
|
|
1089
|
+
|
|
1090
|
+
**Nested**
|
|
1091
|
+
|
|
1092
|
+
- Escape closes only the drawer on top.
|
|
1093
|
+
|
|
1094
|
+
Runs in React, Vue and web components.
|
|
1095
|
+
|
|
1096
|
+
Screen readers and layouts the drawer is tested against:
|
|
1097
|
+
|
|
1098
|
+
- No axe violations while closed.
|
|
1099
|
+
- No axe violations while open.
|
|
1100
|
+
- No axe violations while a nested drawer is open.
|
|
1101
|
+
- No axe violations while it rests where the page stays usable.
|
|
1102
|
+
- The drawer's accessibility tree is a dialog with its handle, title and actions.
|
|
1103
|
+
- The handle is a button that controls the drawer.
|
|
1104
|
+
|
|
1105
|
+
Runs in React, Vue and web components.
|
|
1106
|
+
|
|
1107
|
+
- Side="start" comes from the right in a right-to-left layout.
|
|
1108
|
+
- Side="end" comes from the left in a right-to-left layout.
|
|
1109
|
+
- A drag toward the start edge closes it in a right-to-left layout.
|
|
1110
|
+
|
|
1111
|
+
Runs in React, Vue and web components.
|
|
1112
|
+
|
|
1113
|
+
Also tested:
|
|
1114
|
+
|
|
1115
|
+
- Without a touch screen `auto` picks the pointer driver.
|
|
1116
|
+
|
|
1117
|
+
**Dialog**
|
|
1118
|
+
|
|
1119
|
+
- An open modal drawer is marked aria-modal.
|
|
1120
|
+
- A keyboard open focuses its first control, and Tab cycles through the controls in order.
|
|
1121
|
+
- A controller's open() resolves with how it closed.
|
|
1122
|
+
|
|
1123
|
+
**Shortcuts**
|
|
1124
|
+
|
|
1125
|
+
- A trigger connected through a controller shows its shortcut in a Shortcut part, and binds it.
|
|
1126
|
+
|
|
1127
|
+
**State attributes**
|
|
1128
|
+
|
|
1129
|
+
- The content names its side, its snap point and whether it's at the largest.
|
|
1130
|
+
- A drawer resting at its own size reports the content snap point and is expanded.
|
|
1131
|
+
- Data-dragging is set while a drag moves it.
|
|
1132
|
+
- A drawer opened from inside another marks both, and the one beneath reads its depth from --drawer-stack.
|
|
1133
|
+
|
|
1134
|
+
**Physics**
|
|
1135
|
+
|
|
1136
|
+
- Past the largest snap point it stretches less than 24px and springs back.
|
|
1137
|
+
|
|
1138
|
+
**Touch**
|
|
1139
|
+
|
|
1140
|
+
- Pulling down on scrolled content scrolls it to the top, then moves the drawer in the same gesture.
|
|
1141
|
+
- Pushing up on content below the largest snap point grows the drawer before the content scrolls.
|
|
1142
|
+
|
|
1143
|
+
**Compositor**
|
|
1144
|
+
|
|
1145
|
+
- A settle runs as a spring sampled into linear(), on translate and the backdrop's opacity.
|
|
1146
|
+
- While a finger drives it, the drawer writes no attributes, only styles.
|
|
1147
|
+
- Its variables are registered and don't inherit, so moving it restyles only the drawer.
|
|
1148
|
+
- With reduced motion it fades in and out instead of sliding.
|
|
1149
|
+
|
|
1150
|
+
**Page**
|
|
1151
|
+
|
|
1152
|
+
- An outlet outside the drawer follows it, and goes back when it closes.
|
|
1153
|
+
- The theme color dims while it's open and comes back when it closes.
|
|
1154
|
+
- Content that grows moves its content snap point, and the drawer follows.
|
|
1155
|
+
- Escape on a drawer that can't be dismissed nudges it toward closing.
|
|
1156
|
+
|
|
1157
|
+
**Scroll-snap driver**
|
|
1158
|
+
|
|
1159
|
+
- On a touch screen it's the driver `auto` picks.
|
|
1160
|
+
- On a touch screen `auto` keeps the pointer driver with …=….
|
|
1161
|
+
- It opens at its first snap point with the browser's scrolling.
|
|
1162
|
+
- A swipe up snaps to the next snap point and reports the swipe.
|
|
1163
|
+
- It comes to rest when the scroll ends before the page hears the finger lift.
|
|
1164
|
+
- The handle moves it with a spring, like the pointer driver.
|
|
1165
|
+
|
|
1166
|
+
Runs in React, Vue and web components.
|