sb-floating-panel-vue 5.2.0 → 5.2.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/README.md +82 -197
- package/dist/components/SbContainer.vue.d.ts +1 -1
- package/dist/components/SbFloating.vue.d.ts +0 -3
- package/dist/components/SbReference.vue.d.ts +0 -2
- package/dist/composables/useSbFloatingPanel.d.ts +6 -16
- package/dist/sb-floating-panel.es.js +259 -265
- package/dist/sb-floating-panel.umd.js +1 -1
- package/dist/types.d.ts +30 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
# sb-floating-panel-vue
|
|
2
2
|
|
|
3
|
-
[](https://www.npmjs.com/package/sb-floating-panel-vue)
|
|
4
|
-
[](https://github.com/stefanBid/sb-floating-panel-vue/blob/main/LICENSE)
|
|
5
|
-
[](https://vuejs.org)
|
|
6
|
-
[](https://github.com/stefanBid/sb-floating-panel-vue/actions/workflows/ci.yml)
|
|
7
|
-
[](https://github.com/stefanBid/sb-floating-panel-vue/actions/workflows/ci.yml)
|
|
8
|
-
[](https://github.com/stefanBid/sb-floating-panel-vue/actions/workflows/ci.yml)
|
|
3
|
+
[](https://www.npmjs.com/package/sb-floating-panel-vue) [](https://github.com/stefanBid/sb-floating-panel-vue/blob/main/LICENSE) [](https://vuejs.org) [](https://github.com/stefanBid/sb-floating-panel-vue/actions/workflows/ci.yml) [](https://github.com/stefanBid/sb-floating-panel-vue/actions/workflows/ci.yml) [](https://github.com/stefanBid/sb-floating-panel-vue/actions/workflows/ci.yml)
|
|
9
4
|
|
|
10
5
|
Headless Vue 3 components for floating panels (dropdowns, menus, listboxes, popovers, tooltips) built on [`@floating-ui/vue`](https://floating-ui.com/). You write three components; the library handles placement, flipping, viewport collisions, open state, keyboard and accessibility. It never decides how your panel looks: no stylesheet, only data attributes and CSS variables your styles can read.
|
|
11
6
|
|
|
@@ -22,14 +17,7 @@ Headless Vue 3 components for floating panels (dropdowns, menus, listboxes, popo
|
|
|
22
17
|
## 📦 Installation
|
|
23
18
|
|
|
24
19
|
```bash
|
|
25
|
-
# npm
|
|
26
20
|
npm install sb-floating-panel-vue vue @floating-ui/vue
|
|
27
|
-
|
|
28
|
-
# yarn
|
|
29
|
-
yarn add sb-floating-panel-vue vue @floating-ui/vue
|
|
30
|
-
|
|
31
|
-
# pnpm
|
|
32
|
-
pnpm add sb-floating-panel-vue vue @floating-ui/vue
|
|
33
21
|
```
|
|
34
22
|
|
|
35
23
|
`vue` (`^3.5.13`) and `@floating-ui/vue` (`^2.0.1`) are peer dependencies: your app provides them, so only one copy of each ends up in the bundle. Vue is usually already installed in your app.
|
|
@@ -101,39 +89,39 @@ Holds the state and the positioning. Renders no element of its own, only its slo
|
|
|
101
89
|
|
|
102
90
|
**Positioning**
|
|
103
91
|
|
|
104
|
-
| Prop
|
|
105
|
-
|
|
|
106
|
-
| `placement`
|
|
107
|
-
| `strategy`
|
|
108
|
-
| `offset`
|
|
109
|
-
| `padding`
|
|
110
|
-
| `matchWidth`
|
|
111
|
-
| `hideWhenDetached` | `boolean \| 'close'`
|
|
92
|
+
| Prop | Type | Default | Description |
|
|
93
|
+
| --- | --- | --- | --- |
|
|
94
|
+
| `placement` | `SbPlacement` | `'bottom-start'` | Preferred placement; the panel flips when there is not enough space |
|
|
95
|
+
| `strategy` | `'absolute' \| 'fixed'` | `'absolute'` | CSS position strategy. Use `fixed` inside scroll containers or fixed layouts |
|
|
96
|
+
| `offset` | `number` | `8` | Distance in px between reference and panel |
|
|
97
|
+
| `padding` | `number` | `8` | Minimum distance in px between the panel and the viewport edges |
|
|
98
|
+
| `matchWidth` | `boolean \| 'min'` | `false` | `true` sets `width`, `'min'` sets `min-width` to the reference width |
|
|
99
|
+
| `hideWhenDetached` | `boolean \| 'close'` | `false` | When the reference is scrolled out of view: `true` hides the panel (`visibility: hidden`) until it is back, `'close'` closes it |
|
|
112
100
|
|
|
113
101
|
**Open state**
|
|
114
102
|
|
|
115
|
-
| Prop
|
|
116
|
-
|
|
|
117
|
-
| `v-model:open` | `boolean`
|
|
118
|
-
| `defaultOpen`
|
|
119
|
-
| `disabled`
|
|
120
|
-
| `trigger`
|
|
121
|
-
| `delay`
|
|
122
|
-
|
|
123
|
-
| `trigger`
|
|
124
|
-
|
|
|
125
|
-
| `'click'`
|
|
126
|
-
| `'hover'`
|
|
127
|
-
| `'focus'`
|
|
128
|
-
| `'manual'` | Only `v-model:open`, the slot props or the exposed methods
|
|
103
|
+
| Prop | Type | Default | Description |
|
|
104
|
+
| --- | --- | --- | --- |
|
|
105
|
+
| `v-model:open` | `boolean` | — | Open state. Leave it unset to let the container manage it |
|
|
106
|
+
| `defaultOpen` | `boolean` | `false` | Initial open state when `v-model:open` is not used |
|
|
107
|
+
| `disabled` | `boolean` | `false` | Prevents opening; closes the panel if it is open |
|
|
108
|
+
| `trigger` | `SbTrigger` | `'click'` | How the reference opens the panel, see below |
|
|
109
|
+
| `delay` | `number \| { open?: number; close?: number }` | `{ open: 300, close: 150 }` | Milliseconds before the `hover` trigger opens and closes; a number sets both |
|
|
110
|
+
|
|
111
|
+
| `trigger` | Opens | Closes |
|
|
112
|
+
| --- | --- | --- |
|
|
113
|
+
| `'click'` | Click (Enter/Space) on the reference toggles the panel | Same, or any dismissal below |
|
|
114
|
+
| `'hover'` | Pointer over the reference after `delay.open`; keyboard focus at once (touch has no hover) | `delay.close` after the pointer leaves the reference and the panel, or when focus moves elsewhere |
|
|
115
|
+
| `'focus'` | Focus on the reference | Focus moving elsewhere |
|
|
116
|
+
| `'manual'` | Only `v-model:open`, the slot props or the exposed methods | Same, or any dismissal below |
|
|
129
117
|
|
|
130
118
|
**Dismissal**
|
|
131
119
|
|
|
132
|
-
| Prop
|
|
133
|
-
|
|
|
134
|
-
| `closeOnEscape`
|
|
135
|
-
| `closeOnClickOutside` | `boolean` | `true`
|
|
136
|
-
| `closeOnFocusOut`
|
|
120
|
+
| Prop | Type | Default | Description |
|
|
121
|
+
| --- | --- | --- | --- |
|
|
122
|
+
| `closeOnEscape` | `boolean` | `true` | Closes on Escape |
|
|
123
|
+
| `closeOnClickOutside` | `boolean` | `true` | Closes on a pointer press outside the reference and the panel (on touch, on the tap's click) |
|
|
124
|
+
| `closeOnFocusOut` | `boolean` | `true` | Closes when keyboard focus moves outside the reference and the panel |
|
|
137
125
|
|
|
138
126
|
| Event | Payload | Description |
|
|
139
127
|
| ------------- | --------------- | ----------------------------- |
|
|
@@ -143,18 +131,18 @@ Holds the state and the positioning. Renders no element of its own, only its slo
|
|
|
143
131
|
|
|
144
132
|
The reason tells what opened or closed the panel, e.g. for analytics or to react only to a dismissal:
|
|
145
133
|
|
|
146
|
-
| Reason
|
|
147
|
-
|
|
|
148
|
-
| `trigger`
|
|
149
|
-
| `hover`
|
|
150
|
-
| `focus`
|
|
151
|
-
| `focus-out` | —
|
|
152
|
-
| `escape`
|
|
153
|
-
| `outside`
|
|
154
|
-
| `select`
|
|
155
|
-
| `detached`
|
|
156
|
-
| `disabled`
|
|
157
|
-
| `api`
|
|
134
|
+
| Reason | `open` | `close` |
|
|
135
|
+
| --- | --- | --- |
|
|
136
|
+
| `trigger` | Click on the reference, Enter, Space or an arrow key on it | Click on the reference, Enter or Space on it |
|
|
137
|
+
| `hover` | Pointer over the reference (`hover` trigger) | Pointer left the reference and the panel (`hover` trigger) |
|
|
138
|
+
| `focus` | Focus on the reference (`hover` and `focus` triggers) | — |
|
|
139
|
+
| `focus-out` | — | Focus moved outside, e.g. Tab out of a menu |
|
|
140
|
+
| `escape` | — | Escape, or the arrow key that closes a submenu |
|
|
141
|
+
| `outside` | — | Press outside the reference and the panel |
|
|
142
|
+
| `select` | — | Item activated with `closeOnSelect` |
|
|
143
|
+
| `detached` | — | Reference scrolled out of view, with `hideWhenDetached: 'close'` |
|
|
144
|
+
| `disabled` | — | The container was disabled |
|
|
145
|
+
| `api` | `v-model:open`, slot props, exposed methods, `useSbFloating()` | Same, or the reference unmounting |
|
|
158
146
|
|
|
159
147
|
```vue
|
|
160
148
|
<SbContainer @close="(reason) => reason === 'select' && track('menu-pick')">
|
|
@@ -168,11 +156,11 @@ The reason tells what opened or closed the panel, e.g. for analytics or to react
|
|
|
168
156
|
|
|
169
157
|
The trigger the panel is anchored to.
|
|
170
158
|
|
|
171
|
-
| Prop
|
|
172
|
-
|
|
|
173
|
-
| `as`
|
|
174
|
-
| `id`
|
|
175
|
-
| `ariaHaspopup` | `'dialog' \| 'menu' \| 'listbox' \| 'tree' \| 'grid' \| 'true' \| 'false'` | follows `role` | Value of `aria-haspopup`. When unset it follows the `role` of the panel (`alertdialog` gives `dialog`) and is left out for other roles
|
|
159
|
+
| Prop | Type | Default | Description |
|
|
160
|
+
| --- | --- | --- | --- |
|
|
161
|
+
| `as` | `string \| Component` | `'button'` | Tag or component to render. `button` gets `type="button"`; form controls (`input`, `textarea`, `select`), `a` with `href` and components keep their own semantics; any other tag (also `a` without `href`) gets `role="button"`, `tabindex="0"` and Enter/Space. A text field opens the panel on click without closing it, and keeps focus (see [Text field references](#text-field-references)) |
|
|
162
|
+
| `id` | `string` | generated | `id` of the element, used to name the panel |
|
|
163
|
+
| `ariaHaspopup` | `'dialog' \| 'menu' \| 'listbox' \| 'tree' \| 'grid' \| 'true' \| 'false'` | follows `role` | Value of `aria-haspopup`. When unset it follows the `role` of the panel (`alertdialog` gives `dialog`) and is left out for other roles |
|
|
176
164
|
|
|
177
165
|
Sets `aria-expanded`, `aria-controls` (while open) and `data-sbf-state`; a tooltip reference gets `aria-describedby` instead (see [Tooltip](#tooltip-1)). When the container is `disabled`, a `button` gets `disabled`, anything else gets `aria-disabled="true"` (and non-interactive tags `tabindex="-1"`). Your own `class`, attributes and listeners (`@click`, `@mouseenter`, …) are applied to the element; the click is not stopped.
|
|
178
166
|
|
|
@@ -182,16 +170,16 @@ With a component (e.g. the `Button` of your design system), its root element bec
|
|
|
182
170
|
|
|
183
171
|
The panel, teleported to `body`. It is rendered while open and stays mounted until its leave transition has finished.
|
|
184
172
|
|
|
185
|
-
| Prop
|
|
186
|
-
|
|
|
187
|
-
| `as`
|
|
188
|
-
| `role`
|
|
189
|
-
| `transition`
|
|
190
|
-
| `teleport`
|
|
191
|
-
| `zIndex`
|
|
192
|
-
| `autoFocus`
|
|
193
|
-
| `keyboardNavigation` | `boolean`
|
|
194
|
-
| `closeOnSelect`
|
|
173
|
+
| Prop | Type | Default | Description |
|
|
174
|
+
| --- | --- | --- | --- |
|
|
175
|
+
| `as` | `string \| Component` | `'div'` | Tag or component of the panel element; a component must render a single root element |
|
|
176
|
+
| `role` | `SbFloatingRole \| null` | `'dialog'` | ARIA role of the panel; `null` renders no role (disclosure pattern). Known roles are suggested by your editor, any string is accepted |
|
|
177
|
+
| `transition` | `string \| TransitionProps` | — | Name of a Vue `<Transition>` defined in your CSS, or an object of `<Transition>` props (e.g. Tailwind classes). No animation when unset |
|
|
178
|
+
| `teleport` | `string \| HTMLElement \| false` | `'body'` | Teleport target (selector or element); `false` renders the panel in place |
|
|
179
|
+
| `zIndex` | `number \| string` | — | `z-index` of the positioned wrapper. Use this, not a `z-*` class on the panel (see [Stacking](#stacking)) |
|
|
180
|
+
| `autoFocus` | `boolean` | `true`, `false` with `role="tooltip"`, the `hover` / `focus` trigger or a text field reference | Once positioned, focuses the first `[autofocus]` or focusable element inside, else the panel itself (a menu: its first item; a listbox: its selected option) |
|
|
181
|
+
| `keyboardNavigation` | `boolean` | `true` | Handles the keyboard model of `role="menu"` and `role="listbox"` panels (see [Keyboard](#keyboard)). No effect with other roles |
|
|
182
|
+
| `closeOnSelect` | `boolean` | `false` | With `role="menu"` / `"listbox"`, activating a `menuitem` / `option` closes the panel (a submenu: with its parent menus) and gives focus back to the reference, after the item's `click` handler. Not for `menuitemcheckbox` / `menuitemradio`, submenu triggers, disabled items or a listbox with `aria-multiselectable="true"`; `event.preventDefault()` in the handler keeps it open |
|
|
195
183
|
|
|
196
184
|
| Event | Description |
|
|
197
185
|
| ------------- | ---------------------------------------------------------- |
|
|
@@ -221,24 +209,7 @@ Call it in `setup` of a component rendered inside an `SbContainer` (in the refer
|
|
|
221
209
|
|
|
222
210
|
### Types
|
|
223
211
|
|
|
224
|
-
|
|
225
|
-
import type {
|
|
226
|
-
SbContainerProps,
|
|
227
|
-
SbContainerSlotProps,
|
|
228
|
-
SbContainerExposed,
|
|
229
|
-
SbReferenceProps,
|
|
230
|
-
SbFloatingProps,
|
|
231
|
-
SbTrigger,
|
|
232
|
-
SbPlacement,
|
|
233
|
-
SbSide,
|
|
234
|
-
SbAlignment,
|
|
235
|
-
SbStrategy,
|
|
236
|
-
SbFloatingRole,
|
|
237
|
-
SbOpenReason,
|
|
238
|
-
SbCloseReason,
|
|
239
|
-
UseSbFloatingReturn,
|
|
240
|
-
} from 'sb-floating-panel-vue';
|
|
241
|
-
```
|
|
212
|
+
Every prop, slot prop, event and option type is exported (`SbContainerProps`, `SbPlacement`, `SbFloatingRole`, …): import them with `import type { … } from 'sb-floating-panel-vue'`.
|
|
242
213
|
|
|
243
214
|
---
|
|
244
215
|
|
|
@@ -250,14 +221,14 @@ import type {
|
|
|
250
221
|
- **Focus.** By default (`autoFocus`) focus moves inside the panel once it is positioned. When the panel closes with focus inside it, focus returns to the reference without scrolling the page. When it unmounts open with focus inside, focus is not left on the body: it goes back to the reference when only `SbFloating` is removed, and to what follows the reference in the page when the reference is removed too.
|
|
251
222
|
- <a id="keyboard"></a>**Keyboard.** With `role="menu"` or `role="listbox"` the components follow the WAI-ARIA [menu button](https://www.w3.org/WAI/ARIA/apg/patterns/menu-button/) and [listbox](https://www.w3.org/WAI/ARIA/apg/patterns/listbox/) patterns. Items are the elements with role `menuitem`, `menuitemcheckbox`, `menuitemradio` (menu) or `option` (listbox); they must be focusable (a `button`, or `tabindex="-1"`). Turn it off with `:keyboard-navigation="false"`.
|
|
252
223
|
|
|
253
|
-
| Key
|
|
254
|
-
|
|
|
255
|
-
| ArrowDown / ArrowUp
|
|
256
|
-
| Home / End
|
|
257
|
-
| Letters
|
|
258
|
-
| Enter / Space
|
|
259
|
-
| Tab / Shift+Tab
|
|
260
|
-
| ArrowRight / ArrowLeft | A submenu trigger: ArrowRight opens the submenu on its first item
|
|
224
|
+
| Key | On the reference | In the panel |
|
|
225
|
+
| --- | --- | --- |
|
|
226
|
+
| ArrowDown / ArrowUp | Opens on the first / last item (or the selected option), except with the `manual` trigger | Next / previous item; a menu wraps around, a listbox stops at its ends |
|
|
227
|
+
| Home / End | — | First / last item |
|
|
228
|
+
| Letters | — | Next item whose text starts with the typed letters |
|
|
229
|
+
| Enter / Space | Toggles | Clicks items that are not buttons or links |
|
|
230
|
+
| Tab / Shift+Tab | — | Menu: closes it (and the menus it opened from) and moves focus on, as from the reference |
|
|
231
|
+
| ArrowRight / ArrowLeft | A submenu trigger: ArrowRight opens the submenu on its first item | A submenu: ArrowLeft closes it and focuses its trigger |
|
|
261
232
|
|
|
262
233
|
A submenu is a menu `SbContainer` inside a menu panel; its arrows are mirrored in right-to-left text. Keys whose `keydown` you already handled with `event.preventDefault()`, and keys typed in text fields, are left alone.
|
|
263
234
|
|
|
@@ -296,22 +267,22 @@ Your styles, transitions and transforms go on the panel, so they never fight wit
|
|
|
296
267
|
|
|
297
268
|
### Data attributes
|
|
298
269
|
|
|
299
|
-
| Attribute
|
|
300
|
-
|
|
|
301
|
-
| `data-sbf-state` | `open` / `closed`
|
|
302
|
-
| `data-sbf-state` | `open` / `closed`
|
|
303
|
-
| `data-sbf-side`
|
|
304
|
-
| `data-sbf-align` | `start` / `end` / absent
|
|
270
|
+
| Attribute | Values | On | Use |
|
|
271
|
+
| --- | --- | --- | --- |
|
|
272
|
+
| `data-sbf-state` | `open` / `closed` | reference | Open/closed styles (e.g. rotate an icon) |
|
|
273
|
+
| `data-sbf-state` | `open` / `closed` | panel | `closed` from the start of the leave transition: style or animate the exit |
|
|
274
|
+
| `data-sbf-side` | `top` / `bottom` / `left` / `right` | panel | Real side after flip: directional animation |
|
|
275
|
+
| `data-sbf-align` | `start` / `end` / absent | panel | Alignment part of the placement |
|
|
305
276
|
|
|
306
277
|
### CSS variables
|
|
307
278
|
|
|
308
279
|
Set on the wrapper and inherited by the panel:
|
|
309
280
|
|
|
310
|
-
| Variable
|
|
311
|
-
|
|
|
312
|
-
| `--sbf-reference-width`
|
|
313
|
-
| `--sbf-available-width`
|
|
314
|
-
| `--sbf-available-height` | Vertical space left before overflowing the viewport
|
|
281
|
+
| Variable | Meaning |
|
|
282
|
+
| --- | --- |
|
|
283
|
+
| `--sbf-reference-width` | Width of the reference |
|
|
284
|
+
| `--sbf-available-width` | Horizontal space left before overflowing the viewport |
|
|
285
|
+
| `--sbf-available-height` | Vertical space left before overflowing the viewport |
|
|
315
286
|
| `--sbf-transform-origin` | Corner or edge of the panel facing the reference, for `transform-origin` |
|
|
316
287
|
|
|
317
288
|
All attributes and variables use the `sbf` prefix, so they do not clash with other libraries in the same app (e.g. Radix / Reka UI `data-state`).
|
|
@@ -397,20 +368,7 @@ Panels are teleported to `body`, so their styles cannot be `scoped` to the compo
|
|
|
397
368
|
|
|
398
369
|
## 🧭 How It Works
|
|
399
370
|
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
`SbContainer` owns the state (open state, positioning, ARIA ids) and shares it with its descendants through Vue `provide`/`inject`:
|
|
403
|
-
|
|
404
|
-
```
|
|
405
|
-
SbContainer ── provides the state ──┬─▶ SbReference
|
|
406
|
-
└─▶ SbFloating
|
|
407
|
-
```
|
|
408
|
-
|
|
409
|
-
- `SbReference` and `SbFloating` find their container on their own: you pass no refs, styles or handlers, and never write `.value`.
|
|
410
|
-
- The lookup follows the component tree, not the DOM, so it keeps working although `SbFloating` is teleported to `body`.
|
|
411
|
-
- They can sit at any depth inside the container slot, also inside your own components, which can read the same state with [`useSbFloating()`](#usesbfloating).
|
|
412
|
-
- Used outside an `SbContainer`, they throw: `[sb-floating-panel-vue] <SbFloating> must be used inside <SbContainer>.`
|
|
413
|
-
- In development, the console warns about a second `SbReference` or `SbFloating` in the same container, about an `as` component that renders no single root element, about a text field reference of a `menu` or `listbox` panel, about a `tooltip` opened by click, and, the first time the arrow keys look for them, about a `menu` or `listbox` with no items or with items that cannot take focus. The warnings depend on `process.env.NODE_ENV`, which your bundler replaces: they are left out of production builds.
|
|
371
|
+
`SbContainer` owns the state (open state, positioning, ARIA ids) and shares it with `SbReference` and `SbFloating` through `provide`/`inject`. The lookup follows the component tree, not the DOM, so it keeps working although `SbFloating` is teleported to `body`; used outside an `SbContainer`, they throw.
|
|
414
372
|
|
|
415
373
|
### Nested containers
|
|
416
374
|
|
|
@@ -420,92 +378,19 @@ An `SbContainer` placed inside another one (e.g. a submenu in a menu panel) regi
|
|
|
420
378
|
- Escape closes the innermost open panel first, then the next one;
|
|
421
379
|
- a press outside all of them closes them all.
|
|
422
380
|
|
|
423
|
-
###
|
|
424
|
-
|
|
425
|
-
1. **Click** on `SbReference` (or Enter/Space on a non-interactive tag). With `trigger="click"` and the container not `disabled`, the container toggles: it emits `update:open` and, without `v-model:open`, updates its own state.
|
|
426
|
-
2. **Open state changes.** `SbReference` gets `aria-expanded="true"`, `aria-controls` and `data-sbf-state="open"`; the container starts listening for Escape, outside presses and focus moving outside (only while open) and emits `open`.
|
|
427
|
-
3. **The panel mounts.** `SbFloating` renders the wrapper in the teleport target, with the panel and two hidden focus guards inside it; the enter classes of your `transition`, if any, are applied to the panel.
|
|
428
|
-
4. **Positioning.** Floating UI starts tracking the reference (scroll, resize, layout changes) and computes the position with `offset`, `flip`, `shift`, `size` and, with `hideWhenDetached`, `hide`. `size` writes the `--sbf-*` variables and applies `matchWidth`; the position is written on the wrapper.
|
|
429
|
-
5. **Positioned.** With `autoFocus` (the default), focus moves inside the panel now, not earlier, so the page does not jump to the panel's initial (0, 0) position.
|
|
430
|
-
|
|
431
|
-
Closing (click on the reference, `close()`, Escape, press outside, focus moving outside, the pointer leaving with `trigger="hover"`, `v-model:open` set to `false`, `disabled`, or the reference unmounting):
|
|
432
|
-
|
|
433
|
-
1. If focus is inside the panel, it goes back to the reference without scrolling the page; it stays where it is when a press outside lands on another focusable element. The container emits `close`.
|
|
434
|
-
2. The panel gets `data-sbf-state="closed"` and the leave classes of your `transition`; the wrapper stays mounted and positioned until the animation ends (immediately without `transition`).
|
|
435
|
-
3. The wrapper is removed, Floating UI stops tracking, `SbFloating` emits `after-leave`.
|
|
436
|
-
|
|
437
|
-
---
|
|
438
|
-
|
|
439
|
-
## 🔀 Migrating from v4
|
|
440
|
-
|
|
441
|
-
v5 is a breaking release.
|
|
381
|
+
### Development warnings
|
|
442
382
|
|
|
443
|
-
|
|
444
|
-
- **Menus and listboxes handle the keyboard.** Remove your own arrow-key, Home/End and typeahead handlers on `role="menu"` and `role="listbox"` panels, or keep them and call `event.preventDefault()` on the keys they handle (the library then leaves those keys alone), or set `:keyboard-navigation="false"`. Tab now closes a menu.
|
|
445
|
-
- **Tooltips.** With `role="tooltip"` the reference no longer gets `aria-expanded` nor `aria-controls`, and gets `aria-describedby` pointing to the panel while open; `autoFocus` defaults to `false`. Replace a `trigger="manual"` tooltip opened with your own `@mouseenter` / `@focus` handlers by `trigger="hover"`.
|
|
446
|
-
- **`SbTrigger` also takes `'hover'` and `'focus'`**: a `switch` over it in your code may need the new cases.
|
|
447
|
-
- **The panel closes when its reference unmounts** while open.
|
|
448
|
-
- **Escape closes the open panel that has focus**, else the most recently opened one (it was always the most recently opened one).
|
|
383
|
+
In development, the console warns about a second `SbReference` or `SbFloating` in the same container, about an `as` component that renders no single root element, about a text field reference of a `menu` or `listbox` panel, about a `tooltip` opened by click, and, the first time the arrow keys look for them, about a `menu` or `listbox` with no items or with items that cannot take focus. The warnings depend on `process.env.NODE_ENV`, which your bundler replaces: they are left out of production builds.
|
|
449
384
|
|
|
450
|
-
|
|
385
|
+
### Directives on `SbFloating`
|
|
451
386
|
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
- **`autoFocus` is `true`.** Focus moves inside the panel when it opens. Set `:auto-focus="false"` on panels that must not take focus, such as tooltips.
|
|
455
|
-
- **`ariaHaspopup` follows the panel `role`** instead of defaulting to `dialog`: drop the matching `aria-haspopup` you set by hand, keep it only where it differs from the role.
|
|
456
|
-
- **Focus moving outside closes the panel.** Set `:close-on-focus-out="false"` to keep the previous behaviour.
|
|
457
|
-
- **The panel is named after the reference** with `aria-labelledby`; pass `aria-label` or `aria-labelledby` to name it differently.
|
|
458
|
-
- **Escape** no longer closes the panel when a widget inside called `preventDefault()` on it, and it now calls `preventDefault()` itself.
|
|
459
|
-
- **`data-sbf-state` on the panel** becomes `closed` during the leave transition.
|
|
460
|
-
|
|
461
|
-
---
|
|
462
|
-
|
|
463
|
-
## 🔀 Migrating from v2
|
|
464
|
-
|
|
465
|
-
v3 is a breaking release.
|
|
466
|
-
|
|
467
|
-
- **The composable is no longer exported.** Use the components; for full control use `@floating-ui/vue` directly.
|
|
468
|
-
- **No refs or styles in the slot.** Remove `reference-ref`, `floating-ref`, `is-open`, `floating-placement`, `floating-style` and `:on-click`: the components share their state.
|
|
469
|
-
- **No arrow.** `hasArrow`, `floating-arrow-ref`, `floating-arrow-style` and `arrow-dimensions` are gone.
|
|
470
|
-
- **No CSS.** Remove `import 'sb-floating-panel-vue/style.css'`. `animation` and `duration` are replaced by `transition`, the name of your own `<Transition>` classes.
|
|
471
|
-
- **Renamed props:** `offsetValue` → `offset` (default `15` → `8`), `hasResize` → `matchWidth`.
|
|
472
|
-
- **New defaults:** `padding: 8` from the viewport edges; Escape and click outside close the panel.
|
|
473
|
-
- `SbContainer` no longer renders a `<div>`; `SbReference` no longer stops click propagation and sets `type="button"`.
|
|
474
|
-
|
|
475
|
-
```vue
|
|
476
|
-
<!-- v2 -->
|
|
477
|
-
<SbContainer :has-resize="true">
|
|
478
|
-
<template #default="{ reference, floating, floatingPlacement, floatingStyle, isOpen, toggle }">
|
|
479
|
-
<SbReference :reference-ref="reference" :on-click="toggle">Toggle</SbReference>
|
|
480
|
-
<SbFloating
|
|
481
|
-
:is-open="isOpen.value"
|
|
482
|
-
:floating-ref="floating"
|
|
483
|
-
:floating-placement="floatingPlacement.value"
|
|
484
|
-
:floating-style="floatingStyle.value"
|
|
485
|
-
>
|
|
486
|
-
Hello Panel!
|
|
487
|
-
</SbFloating>
|
|
488
|
-
</template>
|
|
489
|
-
</SbContainer>
|
|
490
|
-
|
|
491
|
-
<!-- v3 -->
|
|
492
|
-
<SbContainer match-width>
|
|
493
|
-
<SbReference>Toggle</SbReference>
|
|
494
|
-
<SbFloating>Hello Panel!</SbFloating>
|
|
495
|
-
</SbContainer>
|
|
496
|
-
```
|
|
387
|
+
`<SbFloating>` renders a `<teleport>` root, so a custom directive applied to the component is not inherited and Vue warns about it: put the directive on an element inside the slot.
|
|
497
388
|
|
|
498
389
|
---
|
|
499
390
|
|
|
500
|
-
##
|
|
391
|
+
## 🔀 Migrating
|
|
501
392
|
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
```vue
|
|
505
|
-
<SbFloating>
|
|
506
|
-
<div v-my-directive>...</div>
|
|
507
|
-
</SbFloating>
|
|
508
|
-
```
|
|
393
|
+
Breaking changes between major versions and how to update: [MIGRATING.md](MIGRATING.md).
|
|
509
394
|
|
|
510
395
|
---
|
|
511
396
|
|
|
@@ -18,8 +18,8 @@ declare const __VLS_export: __VLS_WithSlots<import('vue').DefineComponent<Omit<S
|
|
|
18
18
|
disabled: boolean;
|
|
19
19
|
placement: import('..').SbPlacement;
|
|
20
20
|
strategy: import('..').SbStrategy;
|
|
21
|
-
padding: number;
|
|
22
21
|
offset: number;
|
|
22
|
+
padding: number;
|
|
23
23
|
matchWidth: boolean | "min";
|
|
24
24
|
hideWhenDetached: boolean | "close";
|
|
25
25
|
defaultOpen: boolean;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { TransitionProps } from 'vue';
|
|
2
1
|
import { SbFloatingProps } from '../types';
|
|
3
2
|
declare var __VLS_26: {};
|
|
4
3
|
type __VLS_Slots = {} & {
|
|
@@ -13,9 +12,7 @@ declare const __VLS_base: import('vue').DefineComponent<SbFloatingProps, {}, {},
|
|
|
13
12
|
}>, {
|
|
14
13
|
as: string | import('vue').Component;
|
|
15
14
|
role: import('..').SbFloatingRole | null;
|
|
16
|
-
transition: string | TransitionProps;
|
|
17
15
|
teleport: string | false | HTMLElement;
|
|
18
|
-
zIndex: string | number;
|
|
19
16
|
autoFocus: boolean;
|
|
20
17
|
keyboardNavigation: boolean;
|
|
21
18
|
closeOnSelect: boolean;
|
|
@@ -5,8 +5,6 @@ type __VLS_Slots = {} & {
|
|
|
5
5
|
};
|
|
6
6
|
declare const __VLS_base: import('vue').DefineComponent<SbReferenceProps, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<SbReferenceProps> & Readonly<{}>, {
|
|
7
7
|
as: string | import('vue').Component;
|
|
8
|
-
id: string;
|
|
9
|
-
ariaHaspopup: "dialog" | "menu" | "listbox" | "tree" | "grid" | "true" | "false";
|
|
10
8
|
}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, any>;
|
|
11
9
|
declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
|
|
12
10
|
declare const _default: typeof __VLS_export;
|
|
@@ -1,18 +1,7 @@
|
|
|
1
|
-
import { ComputedRef, CSSProperties,
|
|
2
|
-
import { SbAlignment, SbPlacement, SbSide
|
|
3
|
-
/**
|
|
4
|
-
|
|
5
|
-
* a ref or a getter, so `SbContainer` props stay reactive.
|
|
6
|
-
*/
|
|
7
|
-
export interface FloatingPanelOptions {
|
|
8
|
-
isOpen: MaybeRefOrGetter<boolean>;
|
|
9
|
-
placement: MaybeRefOrGetter<SbPlacement>;
|
|
10
|
-
strategy: MaybeRefOrGetter<SbStrategy>;
|
|
11
|
-
offset: MaybeRefOrGetter<number>;
|
|
12
|
-
padding: MaybeRefOrGetter<number>;
|
|
13
|
-
matchWidth: MaybeRefOrGetter<boolean | 'min'>;
|
|
14
|
-
hideWhenDetached: MaybeRefOrGetter<boolean | 'close'>;
|
|
15
|
-
}
|
|
1
|
+
import { ComputedRef, CSSProperties, Ref } from 'vue';
|
|
2
|
+
import { SbAlignment, SbContainerProps, SbPlacement, SbSide } from '../types';
|
|
3
|
+
/** Positioning props of `SbContainer`, with their defaults: read reactively. */
|
|
4
|
+
type PositioningProps = Readonly<Required<Pick<SbContainerProps, 'placement' | 'strategy' | 'offset' | 'padding' | 'matchWidth' | 'hideWhenDetached'>>>;
|
|
16
5
|
export interface FloatingPanel {
|
|
17
6
|
reference: Ref<HTMLElement | null>;
|
|
18
7
|
floating: Ref<HTMLElement | null>;
|
|
@@ -30,4 +19,5 @@ export interface FloatingPanel {
|
|
|
30
19
|
/**
|
|
31
20
|
* Wraps Floating UI for the components. Not part of the public API.
|
|
32
21
|
*/
|
|
33
|
-
export declare function useSbFloatingPanel(
|
|
22
|
+
export declare function useSbFloatingPanel(props: PositioningProps, isOpen: Readonly<Ref<boolean>>): FloatingPanel;
|
|
23
|
+
export {};
|