@duro-app/ui 4.4.0 → 4.5.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/{Table-JTgcR_Fh.js → Table-CUp12BKZ.js} +78 -75
- package/dist/Table-CUp12BKZ.js.map +1 -0
- package/dist/components/Combobox/Combobox.d.ts.map +1 -1
- package/dist/components/Combobox/Combobox.meta.d.ts.map +1 -1
- package/dist/components/Drawer/Drawer.d.ts.map +1 -1
- package/dist/components/Drawer/DrawerScroll.stories.d.ts +13 -0
- package/dist/components/Drawer/DrawerScroll.stories.d.ts.map +1 -0
- package/dist/components/Drawer/useSwipeDismiss.d.ts +7 -2
- package/dist/components/Drawer/useSwipeDismiss.d.ts.map +1 -1
- package/dist/components/Menu/useMenuRoot.d.ts.map +1 -1
- package/dist/components/Popover/Popover.d.ts.map +1 -1
- package/dist/components/Popover/Popover.meta.d.ts.map +1 -1
- package/dist/components/Popover/PopoverLayerContext.d.ts +10 -0
- package/dist/components/Popover/PopoverLayerContext.d.ts.map +1 -0
- package/dist/components/Popover/PopoverLayers.stories.d.ts +13 -0
- package/dist/components/Popover/PopoverLayers.stories.d.ts.map +1 -0
- package/dist/components/ScrollArea/ScrollArea.d.ts +8 -2
- package/dist/components/ScrollArea/ScrollArea.d.ts.map +1 -1
- package/dist/components/Select/Select.d.ts.map +1 -1
- package/dist/components/Select/Select.meta.d.ts.map +1 -1
- package/dist/components/Select/useSelectRoot.d.ts.map +1 -1
- package/dist/components/Toggle/Toggle.d.ts.map +1 -1
- package/dist/components/Toggle/rowHeight.d.ts +17 -0
- package/dist/components/Toggle/rowHeight.d.ts.map +1 -0
- package/dist/components/Toggle/styles.css.d.ts +10 -0
- package/dist/components/Toggle/styles.css.d.ts.map +1 -1
- package/dist/components/ToggleGroup/ToggleGroup.d.ts +7 -1
- package/dist/components/ToggleGroup/ToggleGroup.d.ts.map +1 -1
- package/dist/components/ToggleGroup/ToggleGroup.meta.d.ts.map +1 -1
- package/dist/components/ToggleGroup/ToggleGroup.stories.d.ts +4 -0
- package/dist/components/ToggleGroup/ToggleGroup.stories.d.ts.map +1 -1
- package/dist/components/ToggleGroup/ToggleGroupContext.d.ts +6 -0
- package/dist/components/ToggleGroup/ToggleGroupContext.d.ts.map +1 -1
- package/dist/components/ToggleGroup/styles.css.d.ts +19 -0
- package/dist/components/ToggleGroup/styles.css.d.ts.map +1 -1
- package/dist/components/ToggleGroup/useRovingFocus.d.ts +17 -0
- package/dist/components/ToggleGroup/useRovingFocus.d.ts.map +1 -0
- package/dist/index.css +1 -1
- package/dist/index.js +2737 -2469
- package/dist/index.js.map +1 -1
- package/dist/table.js +1 -1
- package/package.json +2 -2
- package/src/components/Combobox/Combobox.meta.ts +6 -0
- package/src/components/Combobox/Combobox.tsx +5 -0
- package/src/components/Drawer/Drawer.meta.ts +1 -1
- package/src/components/Drawer/Drawer.tsx +12 -2
- package/src/components/Drawer/DrawerScroll.stories.tsx +292 -0
- package/src/components/Drawer/useSwipeDismiss.ts +53 -8
- package/src/components/Menu/useMenuRoot.ts +5 -1
- package/src/components/Popover/Popover.meta.ts +7 -0
- package/src/components/Popover/Popover.tsx +30 -24
- package/src/components/Popover/PopoverLayerContext.ts +20 -0
- package/src/components/Popover/PopoverLayers.stories.tsx +234 -0
- package/src/components/ScrollArea/ScrollArea.meta.ts +1 -1
- package/src/components/ScrollArea/ScrollArea.tsx +12 -6
- package/src/components/Select/Select.meta.ts +6 -0
- package/src/components/Select/Select.tsx +8 -1
- package/src/components/Select/useSelectRoot.ts +6 -2
- package/src/components/Toggle/Toggle.meta.ts +1 -1
- package/src/components/Toggle/Toggle.tsx +19 -2
- package/src/components/Toggle/rowHeight.ts +12 -0
- package/src/components/Toggle/styles.css.ts +12 -0
- package/src/components/ToggleGroup/ToggleGroup.meta.ts +11 -1
- package/src/components/ToggleGroup/ToggleGroup.stories.tsx +156 -0
- package/src/components/ToggleGroup/ToggleGroup.tsx +87 -10
- package/src/components/ToggleGroup/ToggleGroupContext.ts +6 -0
- package/src/components/ToggleGroup/styles.css.ts +30 -1
- package/src/components/ToggleGroup/useRovingFocus.ts +121 -0
- package/dist/Table-JTgcR_Fh.js.map +0 -1
package/dist/table.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { M as F, s as xt, R as rt, H as kt, a as pt, B as bt, c as mt, C as ft, b as ht, d as yt } from "./Table-
|
|
1
|
+
import { M as F, s as xt, R as rt, H as kt, a as pt, B as bt, c as mt, C as ft, b as ht, d as yt } from "./Table-CUp12BKZ.js";
|
|
2
2
|
import { jsx as u, jsxs as B } from "react/jsx-runtime";
|
|
3
3
|
import { c as H, m as p, d as b } from "./compiler-runtime-B2IcI8_O.js";
|
|
4
4
|
import { flexRender as E, useReactTable as it, getPaginationRowModel as St, getFilteredRowModel as Tt, getSortedRowModel as at, getCoreRowModel as st } from "@tanstack/react-table";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@duro-app/ui",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.5.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
},
|
|
67
67
|
"dependencies": {
|
|
68
68
|
"@tanstack/react-virtual": "^3.14.6",
|
|
69
|
-
"@duro-app/tokens": "^4.
|
|
69
|
+
"@duro-app/tokens": "^4.5.0"
|
|
70
70
|
},
|
|
71
71
|
"devDependencies": {
|
|
72
72
|
"@babel/preset-typescript": "^7.28.0",
|
|
@@ -18,6 +18,12 @@ export const meta: ComponentMeta = {
|
|
|
18
18
|
optional: ['Empty'],
|
|
19
19
|
},
|
|
20
20
|
relatedTo: [
|
|
21
|
+
{
|
|
22
|
+
component: 'Popover',
|
|
23
|
+
kind: 'composition',
|
|
24
|
+
relationship:
|
|
25
|
+
'Inside Popover.Popup a Combobox keeps the popover open while you choose; Escape closes only the list',
|
|
26
|
+
},
|
|
21
27
|
{
|
|
22
28
|
component: 'Select',
|
|
23
29
|
kind: 'contrast',
|
|
@@ -5,6 +5,7 @@ import {styles} from './styles.css'
|
|
|
5
5
|
import {ComboboxContext, useCombobox} from './ComboboxContext'
|
|
6
6
|
import {useComboboxRoot} from './useComboboxRoot'
|
|
7
7
|
import {usePortalMount} from '../ThemeProvider/ThemeProvider'
|
|
8
|
+
import {usePopoverLayer} from '../Popover/PopoverLayerContext'
|
|
8
9
|
|
|
9
10
|
// --- Root ---
|
|
10
11
|
interface RootProps {
|
|
@@ -137,6 +138,7 @@ function Trigger({children}: {children?: ReactNode}) {
|
|
|
137
138
|
function Popup({children}: {children: ReactNode}) {
|
|
138
139
|
const {open, listboxId, rootRef} = useCombobox()
|
|
139
140
|
const mount = usePortalMount()
|
|
141
|
+
const listboxRef = useRef<HTMLDivElement>(null)
|
|
140
142
|
const [coords, setCoords] = useState<{top: number; left: number; width: number} | null>(null)
|
|
141
143
|
|
|
142
144
|
// Measure the root each time the popup opens, and re-measure on scroll/resize
|
|
@@ -163,10 +165,13 @@ function Popup({children}: {children: ReactNode}) {
|
|
|
163
165
|
}
|
|
164
166
|
}, [open, rootRef])
|
|
165
167
|
|
|
168
|
+
usePopoverLayer(listboxRef, {active: open && coords !== null})
|
|
169
|
+
|
|
166
170
|
if (!open || !coords) return null
|
|
167
171
|
|
|
168
172
|
const node = (
|
|
169
173
|
<html.div
|
|
174
|
+
ref={listboxRef}
|
|
170
175
|
id={listboxId}
|
|
171
176
|
role="listbox"
|
|
172
177
|
style={[styles.popup, styles.popupPosition(coords.top, coords.left, coords.width)]}
|
|
@@ -2,7 +2,7 @@ import type {ComponentMeta} from '../component-meta'
|
|
|
2
2
|
|
|
3
3
|
export const meta: ComponentMeta = {
|
|
4
4
|
description:
|
|
5
|
-
'Modal sliding panel from a screen edge (right, left, or bottom). Slides in with backdrop overlay. Supports swipe-to-dismiss gestures on mobile, backdrop click dismiss, and Escape key. Use for secondary workflows, settings panels, or mobile-friendly detail views.',
|
|
5
|
+
'Modal sliding panel from a screen edge (right, left, or bottom). Slides in with backdrop overlay. Supports swipe-to-dismiss gestures on mobile, backdrop click dismiss, and Escape key. Swipe yields to an inner Duro ScrollArea: a drag there scrolls it, and dismisses only toward the edge from the scroll start (a native overflow:auto child is not covered — use ScrollArea). Use for secondary workflows, settings panels, or mobile-friendly detail views.',
|
|
6
6
|
whenToUse: [
|
|
7
7
|
'Settings or configuration panels that slide in from the side',
|
|
8
8
|
'Mobile-friendly detail views (bottom sheet pattern)',
|
|
@@ -233,6 +233,16 @@ function Portal({children, size = 'md'}: PortalProps) {
|
|
|
233
233
|
panelRef,
|
|
234
234
|
} = useDrawer()
|
|
235
235
|
const mount = usePortalMount()
|
|
236
|
+
// The shown panel element, tracked as state so swipe listeners follow it
|
|
237
|
+
// when the portal mount arrives and the panel is remounted into it.
|
|
238
|
+
const [panel, setPanel] = useState<HTMLDivElement | null>(null)
|
|
239
|
+
const attachPanel = useCallback(
|
|
240
|
+
(el: HTMLDivElement | null) => {
|
|
241
|
+
panelRef.current = el
|
|
242
|
+
setPanel(el)
|
|
243
|
+
},
|
|
244
|
+
[panelRef],
|
|
245
|
+
)
|
|
236
246
|
|
|
237
247
|
const handleBackdropClick = useCallback(() => {
|
|
238
248
|
if (dismissable) {
|
|
@@ -245,7 +255,7 @@ function Portal({children, size = 'md'}: PortalProps) {
|
|
|
245
255
|
anchor,
|
|
246
256
|
enabled: swipeEnabled && open && !closing,
|
|
247
257
|
onDismiss: requestCloseImmediate,
|
|
248
|
-
|
|
258
|
+
panel,
|
|
249
259
|
})
|
|
250
260
|
|
|
251
261
|
if (!open) return null
|
|
@@ -269,7 +279,7 @@ function Portal({children, size = 'md'}: PortalProps) {
|
|
|
269
279
|
{/* Viewport */}
|
|
270
280
|
<html.div style={[styles.viewport, viewportAnchorMap[anchor]]} data-drawer-viewport="">
|
|
271
281
|
<html.div
|
|
272
|
-
ref={
|
|
282
|
+
ref={attachPanel}
|
|
273
283
|
role="dialog"
|
|
274
284
|
aria-modal={true}
|
|
275
285
|
aria-labelledby={titleId}
|
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
import type {Meta, StoryObj} from '@storybook/react'
|
|
2
|
+
import {expect, waitFor} from 'storybook/test'
|
|
3
|
+
import {cdp, page} from 'vitest/browser'
|
|
4
|
+
import {Drawer} from './Drawer'
|
|
5
|
+
import {ToggleGroup} from '../ToggleGroup/ToggleGroup'
|
|
6
|
+
import {Toggle} from '../Toggle/Toggle'
|
|
7
|
+
import {Icon, type IconName} from '../Icon'
|
|
8
|
+
import {ROW_HEIGHT} from '../Toggle/rowHeight'
|
|
9
|
+
|
|
10
|
+
const meta: Meta = {
|
|
11
|
+
title: 'Components/Drawer/Scroll',
|
|
12
|
+
parameters: {layout: 'fullscreen'},
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export default meta
|
|
16
|
+
type Story = StoryObj
|
|
17
|
+
|
|
18
|
+
const ICON_NAMES: IconName[] = [
|
|
19
|
+
'x-circle',
|
|
20
|
+
'check-circle',
|
|
21
|
+
'check-done',
|
|
22
|
+
'clock',
|
|
23
|
+
'forbidden',
|
|
24
|
+
'info-circle',
|
|
25
|
+
'alert-triangle',
|
|
26
|
+
'shield',
|
|
27
|
+
'lock',
|
|
28
|
+
'key',
|
|
29
|
+
'map',
|
|
30
|
+
'layers',
|
|
31
|
+
'repeat',
|
|
32
|
+
'database',
|
|
33
|
+
'shield-check',
|
|
34
|
+
'route',
|
|
35
|
+
'git-branch',
|
|
36
|
+
'menu',
|
|
37
|
+
'pin',
|
|
38
|
+
'server',
|
|
39
|
+
'hard-drive',
|
|
40
|
+
'box',
|
|
41
|
+
'image',
|
|
42
|
+
'tag',
|
|
43
|
+
'pie-chart',
|
|
44
|
+
'users',
|
|
45
|
+
'user-plus',
|
|
46
|
+
'mail',
|
|
47
|
+
'file-text',
|
|
48
|
+
'plug',
|
|
49
|
+
'search',
|
|
50
|
+
'mic',
|
|
51
|
+
'sun',
|
|
52
|
+
'moon',
|
|
53
|
+
'monitor',
|
|
54
|
+
'contrast',
|
|
55
|
+
'info-circle-filled',
|
|
56
|
+
'alert-triangle-filled',
|
|
57
|
+
'check-circle-filled',
|
|
58
|
+
'x-circle-filled',
|
|
59
|
+
'shield-filled',
|
|
60
|
+
'lock-filled',
|
|
61
|
+
]
|
|
62
|
+
|
|
63
|
+
function Scene({pressed}: {pressed?: string} = {}) {
|
|
64
|
+
return (
|
|
65
|
+
<Drawer.Root anchor="bottom" defaultOpen>
|
|
66
|
+
<Drawer.Portal>
|
|
67
|
+
<Drawer.Header>
|
|
68
|
+
<Drawer.Title>Pick an icon</Drawer.Title>
|
|
69
|
+
</Drawer.Header>
|
|
70
|
+
<Drawer.Body>
|
|
71
|
+
<ToggleGroup
|
|
72
|
+
wrap
|
|
73
|
+
maxRows={3}
|
|
74
|
+
size="small"
|
|
75
|
+
aria-label="Icon"
|
|
76
|
+
defaultValue={pressed ? [pressed] : []}
|
|
77
|
+
>
|
|
78
|
+
{ICON_NAMES.map((name) => (
|
|
79
|
+
<Toggle key={name} value={name} aria-label={name}>
|
|
80
|
+
<Icon name={name} size="sm" />
|
|
81
|
+
</Toggle>
|
|
82
|
+
))}
|
|
83
|
+
</ToggleGroup>
|
|
84
|
+
</Drawer.Body>
|
|
85
|
+
</Drawer.Portal>
|
|
86
|
+
</Drawer.Root>
|
|
87
|
+
)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
type Point = {x: number; y: number}
|
|
91
|
+
|
|
92
|
+
/** `CDPSession` is empty until the provider's typings load; `send` exists at runtime. */
|
|
93
|
+
const cdpSend = (method: string, params: object) =>
|
|
94
|
+
(cdp() as unknown as {send: (method: string, params: object) => Promise<unknown>}).send(
|
|
95
|
+
method,
|
|
96
|
+
params,
|
|
97
|
+
)
|
|
98
|
+
|
|
99
|
+
const pause = (ms: number) => new Promise((r) => setTimeout(r, ms))
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* CDP input lands in top-level page coordinates; the story runs in an iframe
|
|
103
|
+
* the test runner offsets and may scale to fit. Map a point up every frame.
|
|
104
|
+
*/
|
|
105
|
+
function toPage(p: Point): Point {
|
|
106
|
+
let {x, y} = p
|
|
107
|
+
let win: Window = window
|
|
108
|
+
while (win.frameElement && win.parent !== win) {
|
|
109
|
+
const rect = win.frameElement.getBoundingClientRect()
|
|
110
|
+
const scale = rect.width / win.innerWidth
|
|
111
|
+
x = rect.left + x * scale
|
|
112
|
+
y = rect.top + y * scale
|
|
113
|
+
win = win.parent
|
|
114
|
+
}
|
|
115
|
+
return {x, y}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* A page-coordinate touch point with a 1px radius: Chrome's touch adjustment
|
|
120
|
+
* snaps a fat default touch onto the nearest control, which would turn every
|
|
121
|
+
* drag in the list into a drag on a toggle.
|
|
122
|
+
*/
|
|
123
|
+
const touchAt = (p: Point) => ({...toPage(p), radiusX: 1, radiusY: 1})
|
|
124
|
+
|
|
125
|
+
/** Real touch drag through CDP; synthetic pointer events don't scroll. */
|
|
126
|
+
async function touchDrag(from: Point, to: Point) {
|
|
127
|
+
const steps = 12
|
|
128
|
+
const send = (type: string, touchPoints: Point[]) =>
|
|
129
|
+
cdpSend('Input.dispatchTouchEvent', {type, touchPoints: touchPoints.map(touchAt)})
|
|
130
|
+
await send('touchStart', [from])
|
|
131
|
+
for (let i = 1; i <= steps; i++) {
|
|
132
|
+
await send('touchMove', [
|
|
133
|
+
{x: from.x + ((to.x - from.x) * i) / steps, y: from.y + ((to.y - from.y) * i) / steps},
|
|
134
|
+
])
|
|
135
|
+
await pause(16)
|
|
136
|
+
}
|
|
137
|
+
await send('touchEnd', [])
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const getViewport = () => document.querySelector<HTMLElement>('[data-duro-scroll]')!
|
|
141
|
+
const getDialog = () => document.querySelector('[role="dialog"]')
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* A point inside the list that is not on a toggle, so a drag starting there
|
|
145
|
+
* is the case the deferral decides (a drag starting on a toggle is decided
|
|
146
|
+
* the same way, but on origin/main it was left to the native scroll).
|
|
147
|
+
*/
|
|
148
|
+
function freePoint(el: HTMLElement, fy: number): Point {
|
|
149
|
+
const r = el.getBoundingClientRect()
|
|
150
|
+
const y = r.top + r.height * fy
|
|
151
|
+
for (let dy = 0; dy < 12; dy++) {
|
|
152
|
+
for (let x = r.left + 2; x < r.right; x += 2) {
|
|
153
|
+
const hit = document.elementFromPoint(x, y + dy)
|
|
154
|
+
if (hit && el.contains(hit) && !hit.closest('button')) return {x, y: y + dy}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
throw new Error('no free point in the list')
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
async function setup() {
|
|
161
|
+
await page.viewport(390, 844)
|
|
162
|
+
await cdpSend('Emulation.setTouchEmulationEnabled', {enabled: true, maxTouchPoints: 1})
|
|
163
|
+
await waitFor(() => expect(getViewport()).toBeTruthy())
|
|
164
|
+
const viewport = getViewport()
|
|
165
|
+
await expect(viewport.scrollHeight).toBeGreaterThan(viewport.clientHeight)
|
|
166
|
+
// let the slide-in animation finish
|
|
167
|
+
await pause(500)
|
|
168
|
+
return viewport
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export const DragUpAtTopScrolls: Story = {
|
|
172
|
+
render: () => <Scene />,
|
|
173
|
+
play: async () => {
|
|
174
|
+
const viewport = await setup()
|
|
175
|
+
await expect(viewport.scrollTop).toBe(0)
|
|
176
|
+
const from = freePoint(viewport, 0.7)
|
|
177
|
+
await touchDrag(from, {x: from.x, y: from.y - 60})
|
|
178
|
+
await pause(300)
|
|
179
|
+
await expect(viewport.scrollTop).toBeGreaterThan(0)
|
|
180
|
+
await expect(getDialog()).not.toBeNull()
|
|
181
|
+
},
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export const DragDownMidListScrolls: Story = {
|
|
185
|
+
render: () => <Scene />,
|
|
186
|
+
play: async () => {
|
|
187
|
+
const viewport = await setup()
|
|
188
|
+
viewport.scrollTop = 40
|
|
189
|
+
await pause(100)
|
|
190
|
+
const before = viewport.scrollTop
|
|
191
|
+
await expect(before).toBeGreaterThan(0)
|
|
192
|
+
const from = freePoint(viewport, 0.5)
|
|
193
|
+
await touchDrag(from, {x: from.x, y: from.y + 20})
|
|
194
|
+
await pause(300)
|
|
195
|
+
await expect(viewport.scrollTop).toBeLessThan(before)
|
|
196
|
+
await expect(getDialog()).not.toBeNull()
|
|
197
|
+
},
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
export const DragDownAtTopDismisses: Story = {
|
|
201
|
+
render: () => <Scene />,
|
|
202
|
+
play: async () => {
|
|
203
|
+
const viewport = await setup()
|
|
204
|
+
await expect(viewport.scrollTop).toBe(0)
|
|
205
|
+
const from = freePoint(viewport, 0.5)
|
|
206
|
+
await touchDrag(from, {x: from.x, y: from.y + 300})
|
|
207
|
+
await waitFor(() => expect(getDialog()).toBeNull())
|
|
208
|
+
},
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
export const DragDownOnHeaderDismisses: Story = {
|
|
212
|
+
render: () => <Scene />,
|
|
213
|
+
play: async () => {
|
|
214
|
+
await setup()
|
|
215
|
+
const title = [...document.querySelectorAll('[role="dialog"] *')].find(
|
|
216
|
+
(el) => el.textContent === 'Pick an icon',
|
|
217
|
+
) as HTMLElement
|
|
218
|
+
const r = title.getBoundingClientRect()
|
|
219
|
+
const from = {x: r.left + r.width / 2, y: r.top + r.height / 2}
|
|
220
|
+
await touchDrag(from, {x: from.x, y: from.y + 300})
|
|
221
|
+
await waitFor(() => expect(getDialog()).toBeNull())
|
|
222
|
+
},
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
export const TapOnToggleStillPresses: Story = {
|
|
226
|
+
render: () => <Scene />,
|
|
227
|
+
play: async () => {
|
|
228
|
+
await setup()
|
|
229
|
+
const key = document.querySelector<HTMLElement>('[role="dialog"] button[aria-label="key"]')!
|
|
230
|
+
const r = key.getBoundingClientRect()
|
|
231
|
+
const at = toPage({x: r.left + r.width / 2, y: r.top + r.height / 2})
|
|
232
|
+
await cdpSend('Input.dispatchTouchEvent', {
|
|
233
|
+
type: 'touchStart',
|
|
234
|
+
touchPoints: [{...at, radiusX: 1, radiusY: 1}],
|
|
235
|
+
})
|
|
236
|
+
await cdpSend('Input.dispatchTouchEvent', {type: 'touchEnd', touchPoints: []})
|
|
237
|
+
await waitFor(() => expect(key).toHaveAttribute('aria-pressed', 'true'))
|
|
238
|
+
await expect(getDialog()).not.toBeNull()
|
|
239
|
+
},
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
export const MountKeepsTheDrawerStill: Story = {
|
|
243
|
+
// size the page before the render: a drawer mounts at its final width
|
|
244
|
+
beforeEach: async () => {
|
|
245
|
+
await page.viewport(390, 844)
|
|
246
|
+
},
|
|
247
|
+
render: () => <Scene pressed={ICON_NAMES[39]} />,
|
|
248
|
+
play: async () => {
|
|
249
|
+
const pageScroll = document.scrollingElement?.scrollTop
|
|
250
|
+
await waitFor(() => expect(getViewport()).toBeTruthy())
|
|
251
|
+
await pause(500)
|
|
252
|
+
const viewport = getViewport()
|
|
253
|
+
const body = viewport.closest('[role="dialog"]')!
|
|
254
|
+
// the list scrolled itself to the pressed icon …
|
|
255
|
+
await expect(viewport.scrollTop).toBeGreaterThan(0)
|
|
256
|
+
const pressed = viewport.querySelector('[aria-pressed="true"]')!.getBoundingClientRect()
|
|
257
|
+
const v = viewport.getBoundingClientRect()
|
|
258
|
+
await expect(pressed.top).toBeGreaterThanOrEqual(v.top - 1)
|
|
259
|
+
await expect(pressed.bottom).toBeLessThanOrEqual(v.bottom + 1)
|
|
260
|
+
// … and nothing outside it moved
|
|
261
|
+
for (const el of body.querySelectorAll<HTMLElement>('*')) {
|
|
262
|
+
if (el !== viewport && !viewport.contains(el)) await expect(el.scrollTop).toBe(0)
|
|
263
|
+
}
|
|
264
|
+
await expect(document.scrollingElement?.scrollTop).toBe(pageScroll)
|
|
265
|
+
},
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/** The coarse-pointer rows of a wrapping group, measured, not inferred. */
|
|
269
|
+
export const CoarsePointerRows: Story = {
|
|
270
|
+
render: () => (
|
|
271
|
+
<ToggleGroup wrap maxRows={3} size="small" aria-label="Icon">
|
|
272
|
+
{ICON_NAMES.map((name) => (
|
|
273
|
+
<Toggle key={name} value={name} aria-label={name}>
|
|
274
|
+
<Icon name={name} size="sm" />
|
|
275
|
+
</Toggle>
|
|
276
|
+
))}
|
|
277
|
+
</ToggleGroup>
|
|
278
|
+
),
|
|
279
|
+
play: async () => {
|
|
280
|
+
// phone width, so 42 icons overflow three rows
|
|
281
|
+
await page.viewport(390, 844)
|
|
282
|
+
await cdpSend('Emulation.setTouchEmulationEnabled', {enabled: true, maxTouchPoints: 1})
|
|
283
|
+
await waitFor(() => expect(matchMedia('(pointer: coarse)').matches).toBe(true))
|
|
284
|
+
const viewport = getViewport()
|
|
285
|
+
const expected = 3.5 * ROW_HEIGHT.coarse + 3 * 4 + 2 * 4
|
|
286
|
+
await waitFor(() => expect(Math.abs(viewport.clientHeight - expected)).toBeLessThanOrEqual(2))
|
|
287
|
+
const toggle = viewport.querySelector('button')!.getBoundingClientRect()
|
|
288
|
+
// exact: Toggle's styles repeat ROW_HEIGHT, and a drift must fail here
|
|
289
|
+
await expect(Math.abs(toggle.height - ROW_HEIGHT.coarse)).toBeLessThanOrEqual(0.5)
|
|
290
|
+
await expect(toggle.width).toBeGreaterThanOrEqual(ROW_HEIGHT.coarse)
|
|
291
|
+
},
|
|
292
|
+
}
|
|
@@ -21,7 +21,12 @@ interface UseSwipeDismissOptions {
|
|
|
21
21
|
anchor: DrawerAnchor
|
|
22
22
|
enabled: boolean
|
|
23
23
|
onDismiss: () => void
|
|
24
|
-
|
|
24
|
+
/**
|
|
25
|
+
* The panel element itself, not a ref: a Drawer open from its first render
|
|
26
|
+
* draws the panel inline, then remounts it into the portal once the mount
|
|
27
|
+
* exists, and listeners must follow the element that is actually shown.
|
|
28
|
+
*/
|
|
29
|
+
panel: HTMLDivElement | null
|
|
25
30
|
}
|
|
26
31
|
|
|
27
32
|
interface SwipeState {
|
|
@@ -32,6 +37,9 @@ interface SwipeState {
|
|
|
32
37
|
startTime: number
|
|
33
38
|
swiping: boolean
|
|
34
39
|
panelSize: number
|
|
40
|
+
/** Inner Duro scroll viewport the gesture started in; capture is deferred until the axis is decided */
|
|
41
|
+
deferredScroll: HTMLElement | null
|
|
42
|
+
pointerId: number
|
|
35
43
|
}
|
|
36
44
|
|
|
37
45
|
/**
|
|
@@ -41,7 +49,7 @@ interface SwipeState {
|
|
|
41
49
|
* Opposite direction: iOS-style — panel stays anchored, shows subtle
|
|
42
50
|
* overscroll feedback (box-shadow intensifies), then snaps back.
|
|
43
51
|
*/
|
|
44
|
-
export function useSwipeDismiss({anchor, enabled, onDismiss,
|
|
52
|
+
export function useSwipeDismiss({anchor, enabled, onDismiss, panel}: UseSwipeDismissOptions) {
|
|
45
53
|
const stateRef = useRef<SwipeState>({
|
|
46
54
|
startX: 0,
|
|
47
55
|
startY: 0,
|
|
@@ -50,6 +58,8 @@ export function useSwipeDismiss({anchor, enabled, onDismiss, panelRef}: UseSwipe
|
|
|
50
58
|
startTime: 0,
|
|
51
59
|
swiping: false,
|
|
52
60
|
panelSize: 0,
|
|
61
|
+
deferredScroll: null,
|
|
62
|
+
pointerId: 0,
|
|
53
63
|
})
|
|
54
64
|
|
|
55
65
|
const isHorizontal = anchor === 'left' || anchor === 'right'
|
|
@@ -169,14 +179,18 @@ export function useSwipeDismiss({anchor, enabled, onDismiss, panelRef}: UseSwipe
|
|
|
169
179
|
}, [])
|
|
170
180
|
|
|
171
181
|
useEffect(() => {
|
|
172
|
-
if (!enabled) return
|
|
173
|
-
const panel = panelRef.current
|
|
174
|
-
if (!panel) return
|
|
182
|
+
if (!enabled || !panel) return
|
|
175
183
|
|
|
176
184
|
function handlePointerDown(e: PointerEvent) {
|
|
177
185
|
if (e.button !== 0) return
|
|
178
186
|
const target = e.target as HTMLElement
|
|
179
|
-
|
|
187
|
+
const scrollEl = target.closest<HTMLElement>('[data-duro-scroll]')
|
|
188
|
+
// Outside a ScrollArea a control keeps its press. Inside one the gesture
|
|
189
|
+
// is decided on the first move even from a control: a list of toggles is
|
|
190
|
+
// all buttons, and touch adjustment snaps a finger onto one. A tap
|
|
191
|
+
// (under the 8px slop) still presses it; a drag never captures before
|
|
192
|
+
// the decision, so the release lands on the panel, not the control.
|
|
193
|
+
if (!scrollEl && target.closest('button, a, input, textarea, select, [role="button"]')) {
|
|
180
194
|
return
|
|
181
195
|
}
|
|
182
196
|
|
|
@@ -190,14 +204,30 @@ export function useSwipeDismiss({anchor, enabled, onDismiss, panelRef}: UseSwipe
|
|
|
190
204
|
state.swiping = false
|
|
191
205
|
state.panelSize = isHorizontal ? rect.width : rect.height
|
|
192
206
|
|
|
207
|
+
state.pointerId = e.pointerId
|
|
208
|
+
state.deferredScroll = scrollEl
|
|
209
|
+
|
|
193
210
|
panel!.dataset.panelSize = String(state.panelSize)
|
|
194
|
-
|
|
211
|
+
|
|
212
|
+
// Inside a Duro ScrollArea the scroll may own the gesture: wait for the first move.
|
|
213
|
+
if (!state.deferredScroll) beginCapture(e.pointerId)
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
function beginCapture(pointerId: number) {
|
|
217
|
+
panel!.setPointerCapture(pointerId)
|
|
195
218
|
|
|
196
219
|
// Freeze CSS animation — we take over positioning.
|
|
197
220
|
// Never restore it; the panel is already at its final resting position.
|
|
198
221
|
panel!.style.animation = 'none'
|
|
199
222
|
}
|
|
200
223
|
|
|
224
|
+
/** True when the viewport can't scroll further against the dismiss direction */
|
|
225
|
+
function isAtDismissEdge(el: HTMLElement) {
|
|
226
|
+
if (!isHorizontal) return el.scrollTop <= 0
|
|
227
|
+
if (anchor === 'right') return el.scrollLeft <= 0
|
|
228
|
+
return el.scrollLeft + el.clientWidth >= el.scrollWidth - 1
|
|
229
|
+
}
|
|
230
|
+
|
|
201
231
|
function handlePointerMove(e: PointerEvent) {
|
|
202
232
|
const state = stateRef.current
|
|
203
233
|
if (state.startTime === 0) return
|
|
@@ -219,8 +249,21 @@ export function useSwipeDismiss({anchor, enabled, onDismiss, panelRef}: UseSwipe
|
|
|
219
249
|
} else {
|
|
220
250
|
// Wrong axis — abort gesture
|
|
221
251
|
state.startTime = 0
|
|
252
|
+
state.deferredScroll = null
|
|
222
253
|
return
|
|
223
254
|
}
|
|
255
|
+
|
|
256
|
+
const scrollEl = state.deferredScroll
|
|
257
|
+
if (scrollEl) {
|
|
258
|
+
state.deferredScroll = null
|
|
259
|
+
if (getMovement(state) <= 0 || !isAtDismissEdge(scrollEl)) {
|
|
260
|
+
// The scroll owns this gesture: no swiping, no capture, no preventDefault
|
|
261
|
+
state.swiping = false
|
|
262
|
+
state.startTime = 0
|
|
263
|
+
return
|
|
264
|
+
}
|
|
265
|
+
beginCapture(state.pointerId)
|
|
266
|
+
}
|
|
224
267
|
}
|
|
225
268
|
|
|
226
269
|
if (state.swiping) {
|
|
@@ -239,6 +282,7 @@ export function useSwipeDismiss({anchor, enabled, onDismiss, panelRef}: UseSwipe
|
|
|
239
282
|
const velocity = movement / elapsed
|
|
240
283
|
|
|
241
284
|
state.startTime = 0
|
|
285
|
+
state.deferredScroll = null
|
|
242
286
|
|
|
243
287
|
if (!state.swiping) {
|
|
244
288
|
return
|
|
@@ -266,6 +310,7 @@ export function useSwipeDismiss({anchor, enabled, onDismiss, panelRef}: UseSwipe
|
|
|
266
310
|
const state = stateRef.current
|
|
267
311
|
state.startTime = 0
|
|
268
312
|
state.swiping = false
|
|
313
|
+
state.deferredScroll = null
|
|
269
314
|
resetStyles(panel!)
|
|
270
315
|
}
|
|
271
316
|
|
|
@@ -290,7 +335,7 @@ export function useSwipeDismiss({anchor, enabled, onDismiss, panelRef}: UseSwipe
|
|
|
290
335
|
}
|
|
291
336
|
}, [
|
|
292
337
|
enabled,
|
|
293
|
-
|
|
338
|
+
panel,
|
|
294
339
|
anchor,
|
|
295
340
|
isHorizontal,
|
|
296
341
|
getMovement,
|
|
@@ -6,6 +6,7 @@ export const meta: ComponentMeta = {
|
|
|
6
6
|
whenToUse: [
|
|
7
7
|
'A small form or controls tied to one element that stay open while you work in them',
|
|
8
8
|
'Anchoring to a spot that is not a button (a canvas point, a text selection) with a virtual anchor',
|
|
9
|
+
'Holding a Select or Combobox: their portalled list counts as inside the popover, so choosing an item keeps it open; Escape closes an open Select, Combobox or Menu before the popover',
|
|
9
10
|
],
|
|
10
11
|
whenNotToUse: [
|
|
11
12
|
'A list of actions — use Menu',
|
|
@@ -47,6 +48,12 @@ export const meta: ComponentMeta = {
|
|
|
47
48
|
relationship:
|
|
48
49
|
'Drawer is the modal edge panel for phone width; Popover is anchored and non-modal',
|
|
49
50
|
},
|
|
51
|
+
{
|
|
52
|
+
component: 'Select',
|
|
53
|
+
kind: 'composition',
|
|
54
|
+
relationship:
|
|
55
|
+
'A Select or Combobox inside Popover.Popup keeps the popover open while you choose; a Select backdrop press closes only its list',
|
|
56
|
+
},
|
|
50
57
|
{
|
|
51
58
|
component: 'Field',
|
|
52
59
|
kind: 'composition',
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
useId,
|
|
9
9
|
useImperativeHandle,
|
|
10
10
|
useLayoutEffect,
|
|
11
|
+
useMemo,
|
|
11
12
|
useRef,
|
|
12
13
|
useState,
|
|
13
14
|
} from 'react'
|
|
@@ -17,6 +18,7 @@ import {usePortalMount} from '../ThemeProvider/ThemeProvider'
|
|
|
17
18
|
import {styles} from './styles.css'
|
|
18
19
|
import {computePopoverPosition, type PopoverAlign, type PopoverSide} from './position'
|
|
19
20
|
import {isOutsidePress} from './outside'
|
|
21
|
+
import {PopoverLayerContext, type PopoverLayerContextValue} from './PopoverLayerContext'
|
|
20
22
|
|
|
21
23
|
// --- Context ---
|
|
22
24
|
|
|
@@ -47,27 +49,6 @@ const FOCUSABLE =
|
|
|
47
49
|
|
|
48
50
|
const OFFSET = 4 // `xs` token
|
|
49
51
|
|
|
50
|
-
/**
|
|
51
|
-
* Whether a nested popup control owns this Escape: a Select, Menu or
|
|
52
|
-
* Combobox inside the popup closes on Esc without preventing default, and
|
|
53
|
-
* that Esc must close only it. Only controls that open a popup count — an
|
|
54
|
-
* expanded trigger that declares one (`aria-haspopup`), an expanded combobox,
|
|
55
|
-
* or focus inside a listbox or menu — never a plain disclosure, and never
|
|
56
|
-
* this popover's own Trigger.
|
|
57
|
-
*
|
|
58
|
-
* holds-until: Duro's Select, Menu and Combobox call preventDefault on the
|
|
59
|
-
* Escape they consume; the defaultPrevented check alone then suffices and
|
|
60
|
-
* this selector goes.
|
|
61
|
-
*/
|
|
62
|
-
const NESTED_POPUP_OWNER =
|
|
63
|
-
'[aria-expanded="true"][aria-haspopup], [role="combobox"][aria-expanded="true"], [role="listbox"], [role="menu"]'
|
|
64
|
-
|
|
65
|
-
function nestedOwnsEscape(target: EventTarget | null, ownTrigger: Element | null): boolean {
|
|
66
|
-
if (!(target instanceof Element)) return false
|
|
67
|
-
const owner = target.closest(NESTED_POPUP_OWNER)
|
|
68
|
-
return owner !== null && owner !== ownTrigger
|
|
69
|
-
}
|
|
70
|
-
|
|
71
52
|
// --- Root ---
|
|
72
53
|
|
|
73
54
|
export interface PopoverHandle {
|
|
@@ -148,7 +129,6 @@ function Root({
|
|
|
148
129
|
|
|
149
130
|
function onKeyDown(e: KeyboardEvent) {
|
|
150
131
|
if (e.key !== 'Escape' || e.defaultPrevented) return
|
|
151
|
-
if (nestedOwnsEscape(e.target, triggerRef.current)) return
|
|
152
132
|
e.preventDefault()
|
|
153
133
|
setOpen(false)
|
|
154
134
|
}
|
|
@@ -157,7 +137,7 @@ function Root({
|
|
|
157
137
|
const ignored = (ignoreRef.current ?? []).map((entry) =>
|
|
158
138
|
typeof entry === 'function' ? entry() : entry,
|
|
159
139
|
)
|
|
160
|
-
const inside = [popupRef.current, triggerRef.current, ...ignored]
|
|
140
|
+
const inside = [popupRef.current, triggerRef.current, ...ignored, ...layersRef.current]
|
|
161
141
|
if (isOutsidePress(e.target as Node | null, inside)) setOpen(false)
|
|
162
142
|
}
|
|
163
143
|
|
|
@@ -169,6 +149,28 @@ function Root({
|
|
|
169
149
|
}
|
|
170
150
|
}, [open, setOpen])
|
|
171
151
|
|
|
152
|
+
const layersRef = useRef(new Set<Element>())
|
|
153
|
+
// A nested Popover's layers are inside its parent too.
|
|
154
|
+
const parentLayer = useContext(PopoverLayerContext)
|
|
155
|
+
const layerCtx = useMemo<PopoverLayerContextValue>(
|
|
156
|
+
() => ({
|
|
157
|
+
register: (el) => {
|
|
158
|
+
layersRef.current.add(el)
|
|
159
|
+
const unregisterParent = parentLayer?.register(el)
|
|
160
|
+
return () => {
|
|
161
|
+
layersRef.current.delete(el)
|
|
162
|
+
unregisterParent?.()
|
|
163
|
+
}
|
|
164
|
+
},
|
|
165
|
+
}),
|
|
166
|
+
[parentLayer],
|
|
167
|
+
)
|
|
168
|
+
useLayoutEffect(() => {
|
|
169
|
+
const popup = popupRef.current
|
|
170
|
+
if (!open || !popup) return
|
|
171
|
+
return parentLayer?.register(popup)
|
|
172
|
+
}, [open, parentLayer])
|
|
173
|
+
|
|
172
174
|
const ctx: PopoverContextValue = {
|
|
173
175
|
open,
|
|
174
176
|
setOpen,
|
|
@@ -181,7 +183,11 @@ function Root({
|
|
|
181
183
|
repositionRef,
|
|
182
184
|
}
|
|
183
185
|
|
|
184
|
-
return
|
|
186
|
+
return (
|
|
187
|
+
<PopoverContext.Provider value={ctx}>
|
|
188
|
+
<PopoverLayerContext.Provider value={layerCtx}>{children}</PopoverLayerContext.Provider>
|
|
189
|
+
</PopoverContext.Provider>
|
|
190
|
+
)
|
|
185
191
|
}
|
|
186
192
|
|
|
187
193
|
// --- Trigger ---
|