@charcuterie/ui 4.27.2 → 4.28.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Accordion/AccordionSection.d.ts.map +1 -1
- package/dist/Accordion/AccordionSection.js +43 -4
- package/dist/Accordion/AccordionSection.js.map +1 -1
- package/dist/Combobox/Combobox.d.ts.map +1 -1
- package/dist/Combobox/Combobox.js +3 -3
- package/dist/Combobox/Combobox.js.map +1 -1
- package/dist/DatePicker/DatePicker.d.ts.map +1 -1
- package/dist/DatePicker/DatePicker.js +3 -3
- package/dist/DatePicker/DatePicker.js.map +1 -1
- package/dist/Dialog/Dialog.d.ts +7 -1
- package/dist/Dialog/Dialog.d.ts.map +1 -1
- package/dist/Dialog/Dialog.js +2 -2
- package/dist/Dialog/Dialog.js.map +1 -1
- package/dist/GroupedList/GroupedList.d.ts +9 -2
- package/dist/GroupedList/GroupedList.d.ts.map +1 -1
- package/dist/GroupedList/GroupedList.js +39 -5
- package/dist/GroupedList/GroupedList.js.map +1 -1
- package/dist/GroupedList/GroupedListRow.d.ts +4 -1
- package/dist/GroupedList/GroupedListRow.d.ts.map +1 -1
- package/dist/GroupedList/GroupedListRow.js +3 -3
- package/dist/GroupedList/GroupedListRow.js.map +1 -1
- package/dist/GroupedList/GroupedListRows.d.ts +16 -0
- package/dist/GroupedList/GroupedListRows.d.ts.map +1 -0
- package/dist/GroupedList/GroupedListRows.js +17 -0
- package/dist/GroupedList/GroupedListRows.js.map +1 -0
- package/dist/Listbox/Listbox.d.ts.map +1 -1
- package/dist/Listbox/Listbox.js +6 -4
- package/dist/Listbox/Listbox.js.map +1 -1
- package/dist/Menu/Menu.d.ts.map +1 -1
- package/dist/Menu/Menu.js +6 -4
- package/dist/Menu/Menu.js.map +1 -1
- package/dist/Modal/Modal.d.ts +7 -1
- package/dist/Modal/Modal.d.ts.map +1 -1
- package/dist/Modal/Modal.js +1 -1
- package/dist/Modal/Modal.js.map +1 -1
- package/dist/Motion/useLastPresentValue.d.ts +21 -0
- package/dist/Motion/useLastPresentValue.d.ts.map +1 -0
- package/dist/Motion/useLastPresentValue.js +30 -0
- package/dist/Motion/useLastPresentValue.js.map +1 -0
- package/dist/Motion/useListMotion.d.ts +111 -0
- package/dist/Motion/useListMotion.d.ts.map +1 -0
- package/dist/Motion/useListMotion.js +358 -0
- package/dist/Motion/useListMotion.js.map +1 -0
- package/dist/Motion/usePresence.d.ts +81 -0
- package/dist/Motion/usePresence.d.ts.map +1 -0
- package/dist/Motion/usePresence.js +131 -0
- package/dist/Motion/usePresence.js.map +1 -0
- package/dist/Motion/useValueChangeMotion.d.ts +52 -0
- package/dist/Motion/useValueChangeMotion.d.ts.map +1 -0
- package/dist/Motion/useValueChangeMotion.js +87 -0
- package/dist/Motion/useValueChangeMotion.js.map +1 -0
- package/dist/Overlay/OverlayPanel.d.ts +18 -1
- package/dist/Overlay/OverlayPanel.d.ts.map +1 -1
- package/dist/Overlay/OverlayPanel.js +40 -10
- package/dist/Overlay/OverlayPanel.js.map +1 -1
- package/dist/Overlay/SharedBackdrop.d.ts +3 -0
- package/dist/Overlay/SharedBackdrop.d.ts.map +1 -1
- package/dist/Overlay/SharedBackdrop.js +8 -2
- package/dist/Overlay/SharedBackdrop.js.map +1 -1
- package/dist/Overlay/useAnchoredOverlay.d.ts +17 -3
- package/dist/Overlay/useAnchoredOverlay.d.ts.map +1 -1
- package/dist/Overlay/useAnchoredOverlay.js +23 -5
- package/dist/Overlay/useAnchoredOverlay.js.map +1 -1
- package/dist/Popover/Popover.d.ts.map +1 -1
- package/dist/Popover/Popover.js +4 -2
- package/dist/Popover/Popover.js.map +1 -1
- package/dist/ReorderList/ReorderList.d.ts +6 -0
- package/dist/ReorderList/ReorderList.d.ts.map +1 -1
- package/dist/ReorderList/ReorderList.js +23 -6
- package/dist/ReorderList/ReorderList.js.map +1 -1
- package/dist/TableViewport/TableViewport.d.ts.map +1 -1
- package/dist/TableViewport/TableViewport.js +9 -1
- package/dist/TableViewport/TableViewport.js.map +1 -1
- package/dist/Tooltip/Tooltip.d.ts.map +1 -1
- package/dist/Tooltip/Tooltip.js +16 -13
- package/dist/Tooltip/Tooltip.js.map +1 -1
- package/dist/index.d.ts +22 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -1
- package/dist/styles.css +191 -1
- package/package.json +2 -2
- package/src/Accordion/AccordionSection.tsx +63 -4
- package/src/Combobox/Combobox.tsx +8 -2
- package/src/DatePicker/DatePicker.tsx +7 -1
- package/src/Dialog/Dialog.tsx +8 -0
- package/src/GroupedList/GroupedList.mdx +3 -2
- package/src/GroupedList/GroupedList.test.tsx +283 -0
- package/src/GroupedList/GroupedList.tsx +88 -44
- package/src/GroupedList/GroupedListRow.tsx +8 -0
- package/src/GroupedList/GroupedListRows.tsx +51 -0
- package/src/Listbox/Listbox.tsx +9 -1
- package/src/Menu/Menu.tsx +9 -1
- package/src/Modal/Modal.tsx +8 -0
- package/src/Motion/useLastPresentValue.test.tsx +66 -0
- package/src/Motion/useLastPresentValue.ts +38 -0
- package/src/Motion/useListMotion.test.tsx +527 -0
- package/src/Motion/useListMotion.ts +674 -0
- package/src/Motion/usePresence.test.tsx +223 -0
- package/src/Motion/usePresence.ts +252 -0
- package/src/Motion/useValueChangeMotion.test.tsx +131 -0
- package/src/Motion/useValueChangeMotion.ts +110 -0
- package/src/Overlay/OverlayPanel.tsx +78 -14
- package/src/Overlay/SharedBackdrop.tsx +17 -2
- package/src/Overlay/useAnchoredOverlay.ts +56 -4
- package/src/Popover/Popover.tsx +9 -1
- package/src/ReorderList/ReorderList.test.tsx +76 -0
- package/src/ReorderList/ReorderList.tsx +86 -48
- package/src/TableViewport/TableViewport.tsx +4 -0
- package/src/Tooltip/Tooltip.tsx +32 -4
- package/src/index.ts +30 -0
- package/src/styles.css +191 -1
|
@@ -8,11 +8,16 @@ import {
|
|
|
8
8
|
useDismiss,
|
|
9
9
|
useFloating,
|
|
10
10
|
useInteractions,
|
|
11
|
+
useMergeRefs,
|
|
11
12
|
useRole,
|
|
12
13
|
} from "@floating-ui/react"
|
|
13
14
|
import type { ReactNode, RefObject } from "react"
|
|
14
|
-
import { useCallback, useEffect } from "react"
|
|
15
|
-
|
|
15
|
+
import { useCallback, useEffect, useState } from "react"
|
|
16
|
+
import {
|
|
17
|
+
toOverlayMotionClass,
|
|
18
|
+
usePresence,
|
|
19
|
+
} from "../Motion/usePresence.ts"
|
|
20
|
+
import { toClassName } from "../toClassName.ts"
|
|
16
21
|
import {
|
|
17
22
|
AnchoredOverlayScopeContext,
|
|
18
23
|
useAnchoredOverlayScope,
|
|
@@ -56,6 +61,17 @@ import { SharedBackdrop } from "./SharedBackdrop.tsx"
|
|
|
56
61
|
* `aria-label` / `aria-labelledby` must be present. Missing both is a
|
|
57
62
|
* dev-time warning, not a throw — the lesson `Spinner`, `Popover`, and
|
|
58
63
|
* `Modal` each learned, applied without breaking a render.
|
|
64
|
+
*
|
|
65
|
+
* ### It opens and closes with motion
|
|
66
|
+
*
|
|
67
|
+
* The panel scales and fades in, and on close it stays in the page
|
|
68
|
+
* until its exit animation ends (`usePresence`). While it leaves it is
|
|
69
|
+
* already closed to everything but the eye: it leaves the stack at
|
|
70
|
+
* once, so the panel under it is live again; its focus manager is
|
|
71
|
+
* disabled, which returns focus to the trigger immediately; and it is
|
|
72
|
+
* `inert`, `aria-hidden`, and click-through. Under reduced motion and
|
|
73
|
+
* in the automated suites the exit has no length, so it is removed in
|
|
74
|
+
* the same commit exactly as before.
|
|
59
75
|
*/
|
|
60
76
|
export type OverlayPanelProps = {
|
|
61
77
|
"aria-label"?: string
|
|
@@ -73,6 +89,12 @@ export type OverlayPanelProps = {
|
|
|
73
89
|
* manager wins, which reads as the app ignoring you.
|
|
74
90
|
*/
|
|
75
91
|
initialFocus?: RefObject<HTMLElement | null>
|
|
92
|
+
/**
|
|
93
|
+
* `false` only for a caller that animates the panel itself, as
|
|
94
|
+
* `TableViewport` does when it grows a table out of the page. Every
|
|
95
|
+
* other panel keeps the library's enter and exit motion.
|
|
96
|
+
*/
|
|
97
|
+
hasMotion?: boolean
|
|
76
98
|
/** Escape and an outside press both close. */
|
|
77
99
|
isDismissable?: boolean
|
|
78
100
|
isVisible: boolean
|
|
@@ -85,6 +107,7 @@ export const OverlayPanel = ({
|
|
|
85
107
|
"aria-labelledby": ariaLabelledBy,
|
|
86
108
|
children,
|
|
87
109
|
className,
|
|
110
|
+
hasMotion = true,
|
|
88
111
|
initialFocus,
|
|
89
112
|
isDismissable = true,
|
|
90
113
|
isVisible,
|
|
@@ -103,7 +126,11 @@ export const OverlayPanel = ({
|
|
|
103
126
|
onCloseRef.current()
|
|
104
127
|
}, [onCloseRef])
|
|
105
128
|
|
|
106
|
-
const
|
|
129
|
+
const { isExiting, isMounted, presenceRef } =
|
|
130
|
+
usePresence(isVisible)
|
|
131
|
+
|
|
132
|
+
const isTop =
|
|
133
|
+
!isExiting && (!stack.isProvided || stack.topId === id)
|
|
107
134
|
const anchors = useAnchoredOverlayScope()
|
|
108
135
|
const hasOpenAnchor = anchors.topId !== null
|
|
109
136
|
|
|
@@ -168,10 +195,33 @@ export const OverlayPanel = ({
|
|
|
168
195
|
* `--layer-modal` it paints. `0` when unprovided — a lone `Modal`
|
|
169
196
|
* is the only thing open.
|
|
170
197
|
*/
|
|
171
|
-
const
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
198
|
+
const registeredIndex = stack.orderedIds.indexOf(id)
|
|
199
|
+
|
|
200
|
+
// A closing panel has already left the stack, so its own index is
|
|
201
|
+
// gone. It keeps the layer it had, or the panel it is leaving would
|
|
202
|
+
// be drawn under the one it was covering for the length of its exit.
|
|
203
|
+
// State with a render-phase update, not a ref written during render,
|
|
204
|
+
// so a render React throws away cannot leave a layer behind.
|
|
205
|
+
const [lastStackIndex, setLastStackIndex] = useState(0)
|
|
206
|
+
|
|
207
|
+
if (
|
|
208
|
+
registeredIndex >= 0 &&
|
|
209
|
+
registeredIndex !== lastStackIndex
|
|
210
|
+
) {
|
|
211
|
+
setLastStackIndex(registeredIndex)
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
const stackIndex =
|
|
215
|
+
registeredIndex >= 0
|
|
216
|
+
? registeredIndex
|
|
217
|
+
: isExiting
|
|
218
|
+
? lastStackIndex
|
|
219
|
+
: 0
|
|
220
|
+
|
|
221
|
+
const setPanelRef = useMergeRefs([
|
|
222
|
+
refs.setFloating,
|
|
223
|
+
presenceRef,
|
|
224
|
+
])
|
|
175
225
|
|
|
176
226
|
useEffect(() => {
|
|
177
227
|
if (!isVisible) {
|
|
@@ -188,9 +238,13 @@ export const OverlayPanel = ({
|
|
|
188
238
|
// Ref-counted through `lockScrollBehind`'s module scope, so N
|
|
189
239
|
// stacked panels lock the page once and free it only when the last
|
|
190
240
|
// closes — with or without a provider.
|
|
241
|
+
//
|
|
242
|
+
// Held while the panel is mounted, not only while it is visible, so
|
|
243
|
+
// the page's scrollbar does not come back, and shift the page
|
|
244
|
+
// sideways, while the panel is still fading out over it.
|
|
191
245
|
useEffect(
|
|
192
|
-
() => (
|
|
193
|
-
[
|
|
246
|
+
() => (isMounted ? lockScrollBehind() : undefined),
|
|
247
|
+
[isMounted],
|
|
194
248
|
)
|
|
195
249
|
|
|
196
250
|
useEffect(() => {
|
|
@@ -205,7 +259,7 @@ export const OverlayPanel = ({
|
|
|
205
259
|
}
|
|
206
260
|
}, [ariaLabel, ariaLabelledBy, isVisible])
|
|
207
261
|
|
|
208
|
-
if (!
|
|
262
|
+
if (!isMounted) {
|
|
209
263
|
return null
|
|
210
264
|
}
|
|
211
265
|
|
|
@@ -214,12 +268,17 @@ export const OverlayPanel = ({
|
|
|
214
268
|
{/* A self-hosting `Modal` renders its own scrim; under a
|
|
215
269
|
provider the shared one already stands behind every panel. */}
|
|
216
270
|
{stack.isProvided ? null : (
|
|
217
|
-
<SharedBackdrop isVisible />
|
|
271
|
+
<SharedBackdrop isVisible={isVisible} />
|
|
218
272
|
)}
|
|
219
273
|
|
|
220
274
|
<FloatingPortal>
|
|
221
275
|
<div
|
|
222
|
-
className=
|
|
276
|
+
className={toClassName(
|
|
277
|
+
"fixed inset-0 flex items-center justify-center",
|
|
278
|
+
// The centring layer covers the viewport. While the panel
|
|
279
|
+
// leaves, a press must reach the page under it.
|
|
280
|
+
isExiting && "pointer-events-none",
|
|
281
|
+
)}
|
|
223
282
|
/*
|
|
224
283
|
* ⚠️ Cascading, not one shared layer.
|
|
225
284
|
*
|
|
@@ -260,13 +319,18 @@ export const OverlayPanel = ({
|
|
|
260
319
|
"aria-label": ariaLabel,
|
|
261
320
|
"aria-labelledby": ariaLabelledBy,
|
|
262
321
|
}}
|
|
263
|
-
|
|
322
|
+
aria-hidden={isExiting ? true : undefined}
|
|
323
|
+
className={toClassName(
|
|
324
|
+
className,
|
|
325
|
+
hasMotion &&
|
|
326
|
+
toOverlayMotionClass(isExiting),
|
|
327
|
+
)}
|
|
264
328
|
// The fallback the plan calls for: `inert` on every panel
|
|
265
329
|
// but the top, so a lower modal is unreachable across the
|
|
266
330
|
// portal boundary even where `FloatingFocusManager`'s
|
|
267
331
|
// outside-hiding does not reach a sibling portal.
|
|
268
332
|
inert={isTop ? undefined : true}
|
|
269
|
-
ref={
|
|
333
|
+
ref={setPanelRef}
|
|
270
334
|
role={role}
|
|
271
335
|
>
|
|
272
336
|
<AnchoredOverlayScopeContext.Provider
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { FloatingPortal } from "@floating-ui/react"
|
|
2
2
|
import type { ReactNode } from "react"
|
|
3
|
+
import {
|
|
4
|
+
toFadeMotionClass,
|
|
5
|
+
usePresence,
|
|
6
|
+
} from "../Motion/usePresence.ts"
|
|
7
|
+
import { toClassName } from "../toClassName.ts"
|
|
3
8
|
|
|
4
9
|
/**
|
|
5
10
|
* The scrim, and there is exactly one of it however many backdrop
|
|
@@ -19,13 +24,19 @@ import type { ReactNode } from "react"
|
|
|
19
24
|
* — a real bug a same-z-plus-DOM-order scheme has, because a
|
|
20
25
|
* later-mounted scrim then covers the panel. Stacking *between* panels
|
|
21
26
|
* still falls out of append order at the one `--layer-modal`.
|
|
27
|
+
*
|
|
28
|
+
* It fades in with the first panel and out with the last, and during
|
|
29
|
+
* the fade out it is click-through like the panel leaving with it.
|
|
22
30
|
*/
|
|
23
31
|
export const SharedBackdrop = ({
|
|
24
32
|
isVisible,
|
|
25
33
|
}: {
|
|
26
34
|
isVisible: boolean
|
|
27
35
|
}): ReactNode => {
|
|
28
|
-
|
|
36
|
+
const { isExiting, isMounted, presenceRef } =
|
|
37
|
+
usePresence<HTMLDivElement>(isVisible)
|
|
38
|
+
|
|
39
|
+
if (!isMounted) {
|
|
29
40
|
return null
|
|
30
41
|
}
|
|
31
42
|
|
|
@@ -33,7 +44,11 @@ export const SharedBackdrop = ({
|
|
|
33
44
|
<FloatingPortal>
|
|
34
45
|
<div
|
|
35
46
|
aria-hidden="true"
|
|
36
|
-
className=
|
|
47
|
+
className={toClassName(
|
|
48
|
+
"fixed inset-0 z-[var(--layer-overlay)] bg-scrim",
|
|
49
|
+
toFadeMotionClass(isExiting),
|
|
50
|
+
)}
|
|
51
|
+
ref={presenceRef}
|
|
37
52
|
/>
|
|
38
53
|
</FloatingPortal>
|
|
39
54
|
)
|
|
@@ -15,14 +15,25 @@ import {
|
|
|
15
15
|
useDismiss,
|
|
16
16
|
useFloating,
|
|
17
17
|
useInteractions,
|
|
18
|
+
useMergeRefs,
|
|
18
19
|
useRole,
|
|
19
20
|
} from "@floating-ui/react"
|
|
20
|
-
import type {
|
|
21
|
+
import type {
|
|
22
|
+
CSSProperties,
|
|
23
|
+
ReactElement,
|
|
24
|
+
RefObject,
|
|
25
|
+
} from "react"
|
|
21
26
|
import {
|
|
22
27
|
createElement,
|
|
28
|
+
useCallback,
|
|
23
29
|
useContext,
|
|
24
30
|
useLayoutEffect,
|
|
25
31
|
} from "react"
|
|
32
|
+
import {
|
|
33
|
+
toOverlayMotionClass,
|
|
34
|
+
toTransformOrigin,
|
|
35
|
+
usePresence,
|
|
36
|
+
} from "../Motion/usePresence.ts"
|
|
26
37
|
import { AnchoredOverlayScopeContext } from "./AnchoredOverlayScope.ts"
|
|
27
38
|
|
|
28
39
|
/**
|
|
@@ -69,6 +80,17 @@ import { AnchoredOverlayScopeContext } from "./AnchoredOverlayScope.ts"
|
|
|
69
80
|
* Whether the panel goes in a `FloatingPortal`, the top layer, or in
|
|
70
81
|
* place is the component's call, which is what lets the same hook back
|
|
71
82
|
* a portalled `Listbox` and (for now) a top-layer `Popover`.
|
|
83
|
+
*
|
|
84
|
+
* ### Presence, so the panel can leave with motion
|
|
85
|
+
*
|
|
86
|
+
* A component renders its panel while `isMounted`, not while
|
|
87
|
+
* `isVisible`: the two differ only while `isExiting`, the length of
|
|
88
|
+
* the exit animation. During that time the component makes the panel
|
|
89
|
+
* `inert` and `aria-hidden` and disables any focus manager on it, so
|
|
90
|
+
* it is closed to everything but the eye. `motionClassName` is the
|
|
91
|
+
* enter or exit class, and `floatingStyles` already carries the
|
|
92
|
+
* `transform-origin` that makes the panel grow out of its trigger,
|
|
93
|
+
* flipped with the placement.
|
|
72
94
|
*/
|
|
73
95
|
export type AnchoredOverlayRole =
|
|
74
96
|
| "dialog"
|
|
@@ -243,7 +265,12 @@ export const useAnchoredOverlay = ({
|
|
|
243
265
|
|
|
244
266
|
const isAnchored = anchorRef !== undefined
|
|
245
267
|
|
|
246
|
-
const {
|
|
268
|
+
const {
|
|
269
|
+
context,
|
|
270
|
+
floatingStyles,
|
|
271
|
+
placement: resolvedPlacement,
|
|
272
|
+
refs,
|
|
273
|
+
} = useFloating({
|
|
247
274
|
// Read-only. Charcuterie remains the sole owner; floating-ui is
|
|
248
275
|
// told what is true and never decides it.
|
|
249
276
|
open: isVisible,
|
|
@@ -375,12 +402,37 @@ export const useAnchoredOverlay = ({
|
|
|
375
402
|
|
|
376
403
|
const clonedTrigger = isAnchored ? null : clonedChild
|
|
377
404
|
|
|
405
|
+
const { isExiting, isMounted, presenceRef } =
|
|
406
|
+
usePresence(isVisible)
|
|
407
|
+
|
|
408
|
+
const mergedFloatingRef = useMergeRefs([
|
|
409
|
+
refs.setFloating,
|
|
410
|
+
presenceRef,
|
|
411
|
+
])
|
|
412
|
+
|
|
413
|
+
// Re-typed as the plain callback `refs.setFloating` was, so the
|
|
414
|
+
// hook's inferred return type names nothing from React's internals.
|
|
415
|
+
const setFloating = useCallback(
|
|
416
|
+
(node: HTMLElement | null) => {
|
|
417
|
+
mergedFloatingRef?.(node)
|
|
418
|
+
},
|
|
419
|
+
[mergedFloatingRef],
|
|
420
|
+
)
|
|
421
|
+
|
|
422
|
+
const panelStyles: CSSProperties = {
|
|
423
|
+
...floatingStyles,
|
|
424
|
+
transformOrigin: toTransformOrigin(resolvedPlacement),
|
|
425
|
+
}
|
|
426
|
+
|
|
378
427
|
return {
|
|
379
428
|
clonedTrigger,
|
|
380
429
|
context,
|
|
381
|
-
floatingStyles,
|
|
430
|
+
floatingStyles: panelStyles,
|
|
382
431
|
getFloatingProps,
|
|
383
|
-
|
|
432
|
+
isExiting,
|
|
433
|
+
isMounted,
|
|
434
|
+
motionClassName: toOverlayMotionClass(isExiting),
|
|
435
|
+
setFloating,
|
|
384
436
|
triggerId,
|
|
385
437
|
}
|
|
386
438
|
}
|
package/src/Popover/Popover.tsx
CHANGED
|
@@ -78,6 +78,9 @@ export const Popover = ({
|
|
|
78
78
|
context,
|
|
79
79
|
floatingStyles,
|
|
80
80
|
getFloatingProps,
|
|
81
|
+
isExiting,
|
|
82
|
+
isMounted,
|
|
83
|
+
motionClassName,
|
|
81
84
|
setFloating,
|
|
82
85
|
} = useAnchoredOverlay({
|
|
83
86
|
isVisible,
|
|
@@ -92,10 +95,12 @@ export const Popover = ({
|
|
|
92
95
|
<>
|
|
93
96
|
{clonedTrigger}
|
|
94
97
|
|
|
95
|
-
{
|
|
98
|
+
{isMounted ? (
|
|
96
99
|
<FloatingPortal>
|
|
97
100
|
<FloatingFocusManager
|
|
98
101
|
context={context}
|
|
102
|
+
// A leaving panel hands focus back at once.
|
|
103
|
+
disabled={isExiting}
|
|
99
104
|
modal={false}
|
|
100
105
|
>
|
|
101
106
|
<div
|
|
@@ -104,8 +109,11 @@ export const Popover = ({
|
|
|
104
109
|
className={toClassName(
|
|
105
110
|
PANEL_SURFACE_CLASS,
|
|
106
111
|
"z-[var(--layer-modal)] max-w-xs p-3 text-content-primary text-sm",
|
|
112
|
+
motionClassName,
|
|
107
113
|
className,
|
|
108
114
|
)}
|
|
115
|
+
aria-hidden={isExiting ? true : undefined}
|
|
116
|
+
inert={isExiting ? true : undefined}
|
|
109
117
|
ref={setFloating}
|
|
110
118
|
// Duplicated from `getFloatingProps()` on purpose, and
|
|
111
119
|
// the two cannot differ — `useRole(context, { role:
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { composeStories } from "@storybook/react"
|
|
2
|
+
import { flushSync } from "react-dom"
|
|
3
|
+
import { createRoot } from "react-dom/client"
|
|
2
4
|
import {
|
|
3
5
|
expect,
|
|
4
6
|
userEvent,
|
|
@@ -9,6 +11,8 @@ import { test } from "vitest"
|
|
|
9
11
|
import { expectNoAxeViolations } from "../expectNoAxeViolations.testHelpers.ts"
|
|
10
12
|
import { mountStory } from "../mountStory.testHelpers.ts"
|
|
11
13
|
import * as stories from "./ReorderList.stories.tsx"
|
|
14
|
+
import type { ReorderListItem } from "./ReorderList.tsx"
|
|
15
|
+
import { ReorderList } from "./ReorderList.tsx"
|
|
12
16
|
|
|
13
17
|
const { Playground, SingleItem } = composeStories(stories)
|
|
14
18
|
|
|
@@ -188,3 +192,75 @@ test("has no axe violations", async () => {
|
|
|
188
192
|
|
|
189
193
|
await expectNoAxeViolations(canvasElement)
|
|
190
194
|
})
|
|
195
|
+
|
|
196
|
+
test("a leaving row keeps its position and reports both ends, so its move buttons stay disabled", () => {
|
|
197
|
+
// About the motion, so the suite's freeze is lifted for this test.
|
|
198
|
+
const frozenStyle = document.getElementById(
|
|
199
|
+
"charcuterie-freeze-motion",
|
|
200
|
+
)
|
|
201
|
+
|
|
202
|
+
frozenStyle?.remove()
|
|
203
|
+
|
|
204
|
+
const host = document.createElement("div")
|
|
205
|
+
|
|
206
|
+
host.style.setProperty("--duration-fast", "600ms")
|
|
207
|
+
host.style.setProperty("--duration-normal", "600ms")
|
|
208
|
+
|
|
209
|
+
document.body.append(host)
|
|
210
|
+
|
|
211
|
+
const root = createRoot(host)
|
|
212
|
+
|
|
213
|
+
const toList = (items: ReorderListItem[]) => (
|
|
214
|
+
<ReorderList
|
|
215
|
+
elementType="ul"
|
|
216
|
+
items={items}
|
|
217
|
+
label="Rows"
|
|
218
|
+
onReorder={() => {}}
|
|
219
|
+
renderItem={({
|
|
220
|
+
isExiting,
|
|
221
|
+
isFirst,
|
|
222
|
+
isLast,
|
|
223
|
+
item,
|
|
224
|
+
position,
|
|
225
|
+
}) =>
|
|
226
|
+
`${item.label}:${String(position)}:${String(isExiting)}:${String(isFirst)}:${String(isLast)}`
|
|
227
|
+
}
|
|
228
|
+
/>
|
|
229
|
+
)
|
|
230
|
+
|
|
231
|
+
const rows = [
|
|
232
|
+
{ key: "a", label: "A" },
|
|
233
|
+
{ key: "b", label: "B" },
|
|
234
|
+
{ key: "c", label: "C" },
|
|
235
|
+
]
|
|
236
|
+
|
|
237
|
+
try {
|
|
238
|
+
flushSync(() => {
|
|
239
|
+
root.render(toList(rows))
|
|
240
|
+
})
|
|
241
|
+
|
|
242
|
+
flushSync(() => {
|
|
243
|
+
root.render(
|
|
244
|
+
toList(rows.filter((row) => row.key !== "b")),
|
|
245
|
+
)
|
|
246
|
+
})
|
|
247
|
+
|
|
248
|
+
expect(
|
|
249
|
+
[...host.querySelectorAll("li")].map(
|
|
250
|
+
(row) => row.textContent,
|
|
251
|
+
),
|
|
252
|
+
).toEqual([
|
|
253
|
+
"A:1:false:true:false",
|
|
254
|
+
"B:2:true:true:true",
|
|
255
|
+
"C:2:false:false:true",
|
|
256
|
+
])
|
|
257
|
+
} finally {
|
|
258
|
+
root.unmount()
|
|
259
|
+
|
|
260
|
+
host.remove()
|
|
261
|
+
|
|
262
|
+
if (frozenStyle !== null) {
|
|
263
|
+
document.head.append(frozenStyle)
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
})
|
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
toSettledIndex,
|
|
7
7
|
} from "../Board/boardMove.ts"
|
|
8
8
|
import { useBoardDrag } from "../Board/useBoardDrag.ts"
|
|
9
|
+
import { useListMotion } from "../Motion/useListMotion.ts"
|
|
9
10
|
import { toClassName } from "../toClassName.ts"
|
|
10
11
|
import { VisuallyHidden } from "../VisuallyHidden/VisuallyHidden.tsx"
|
|
11
12
|
|
|
@@ -58,6 +59,12 @@ export type ReorderListRenderArguments<
|
|
|
58
59
|
}
|
|
59
60
|
index: number
|
|
60
61
|
isDragged: boolean
|
|
62
|
+
/**
|
|
63
|
+
* Removed, and leaving with motion. It is `inert`, keeps the
|
|
64
|
+
* position it had, and reports itself as both first and last, so a
|
|
65
|
+
* host that disables its move buttons at the ends disables both.
|
|
66
|
+
*/
|
|
67
|
+
isExiting: boolean
|
|
61
68
|
isFirst: boolean
|
|
62
69
|
isLast: boolean
|
|
63
70
|
item: TItem
|
|
@@ -216,6 +223,13 @@ export const ReorderList = <TItem extends ReorderListItem>({
|
|
|
216
223
|
},
|
|
217
224
|
})
|
|
218
225
|
|
|
226
|
+
// A row moved by a button, a key, or a drop slides to its new place
|
|
227
|
+
// instead of jumping, so the user sees where it went.
|
|
228
|
+
const { entries } = useListMotion({
|
|
229
|
+
getKey: (item: TItem) => item.key,
|
|
230
|
+
items,
|
|
231
|
+
})
|
|
232
|
+
|
|
219
233
|
const ListElement = elementType
|
|
220
234
|
|
|
221
235
|
const ItemElement =
|
|
@@ -240,56 +254,80 @@ export const ReorderList = <TItem extends ReorderListItem>({
|
|
|
240
254
|
}
|
|
241
255
|
}}
|
|
242
256
|
>
|
|
243
|
-
{
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
257
|
+
{entries.map(
|
|
258
|
+
({
|
|
259
|
+
index,
|
|
260
|
+
isExiting,
|
|
261
|
+
item,
|
|
262
|
+
key,
|
|
263
|
+
motionProps,
|
|
264
|
+
}) => {
|
|
265
|
+
// A leaving row keeps the index it had, for printing, but
|
|
266
|
+
// has no grip and no attribute, so a drag never measures it
|
|
267
|
+
// as a drop slot, and `moveBy` does nothing on it.
|
|
268
|
+
|
|
269
|
+
return (
|
|
270
|
+
<ItemElement
|
|
271
|
+
{...motionProps}
|
|
272
|
+
className={toClassName(
|
|
273
|
+
itemClassName,
|
|
274
|
+
motionProps.className,
|
|
275
|
+
)}
|
|
276
|
+
key={key}
|
|
277
|
+
{...(isExiting
|
|
278
|
+
? {}
|
|
279
|
+
: { [ITEM_ATTRIBUTE]: item.key })}
|
|
280
|
+
>
|
|
281
|
+
{renderItem({
|
|
282
|
+
gripProps:
|
|
283
|
+
isReorderable && !isExiting
|
|
284
|
+
? {
|
|
285
|
+
onPointerDown: (pointerEvent) => {
|
|
286
|
+
startDrag(pointerEvent, {
|
|
287
|
+
fromIndex: index,
|
|
288
|
+
fromLaneKey: LANE_KEY,
|
|
289
|
+
itemKey: item.key,
|
|
290
|
+
})
|
|
291
|
+
},
|
|
292
|
+
/*
|
|
293
|
+
* Without it the browser claims the gesture
|
|
294
|
+
* for a scroll and the `pointermove` stream
|
|
295
|
+
* stops one frame in — which reads as "drag
|
|
296
|
+
* works on the desktop and not on the
|
|
297
|
+
* tablet", the exact bug this component
|
|
298
|
+
* exists to end.
|
|
299
|
+
*/
|
|
300
|
+
style: { touchAction: "none" },
|
|
301
|
+
title: "Drag to reorder",
|
|
302
|
+
}
|
|
303
|
+
: {},
|
|
304
|
+
index,
|
|
305
|
+
isDragged: drag?.itemKey === item.key,
|
|
306
|
+
isExiting,
|
|
307
|
+
isFirst: isExiting || index === 0,
|
|
308
|
+
isLast:
|
|
309
|
+
isExiting || index === items.length - 1,
|
|
310
|
+
item,
|
|
311
|
+
moveBy: (offset) => {
|
|
312
|
+
const toIndex = index + offset
|
|
278
313
|
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
314
|
+
if (
|
|
315
|
+
isExiting ||
|
|
316
|
+
!isReorderable ||
|
|
317
|
+
toIndex < 0 ||
|
|
318
|
+
toIndex > items.length - 1
|
|
319
|
+
) {
|
|
320
|
+
return
|
|
321
|
+
}
|
|
286
322
|
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
323
|
+
commit(index, toIndex)
|
|
324
|
+
},
|
|
325
|
+
position: index + 1,
|
|
326
|
+
})}
|
|
327
|
+
</ItemElement>
|
|
328
|
+
)
|
|
329
|
+
},
|
|
330
|
+
)}
|
|
293
331
|
|
|
294
332
|
{/*
|
|
295
333
|
* A real element rather than a border on a row, and
|
|
@@ -155,6 +155,10 @@ export const TableViewport = ({
|
|
|
155
155
|
{isExpanded ? null : content}
|
|
156
156
|
</section>
|
|
157
157
|
<Dialog
|
|
158
|
+
// This component grows the dialog out of the page and reverses
|
|
159
|
+
// it before closing (`animateExpansion`), so the library's own
|
|
160
|
+
// enter and exit would run on top of it.
|
|
161
|
+
hasMotion={false}
|
|
158
162
|
heading={label}
|
|
159
163
|
isVisible={isExpanded}
|
|
160
164
|
size="full"
|