@greenharness/greenrack-ui 7.0.1 → 7.1.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-CT2te7FV.js → Table-ojMk5CaF.js} +9 -9
- package/dist/Table-ojMk5CaF.js.map +1 -0
- package/dist/components/ButtonGroup/ButtonGroup.stories.d.ts +9 -0
- package/dist/components/ButtonGroup/ButtonGroup.stories.d.ts.map +1 -1
- package/dist/components/ButtonGroup/attached.css.d.ts.map +1 -1
- package/dist/components/ConfirmDialog/ConfirmDialog.d.ts +3 -1
- package/dist/components/ConfirmDialog/ConfirmDialog.d.ts.map +1 -1
- package/dist/components/Dialog/Dialog.d.ts +10 -1
- package/dist/components/Dialog/Dialog.d.ts.map +1 -1
- package/dist/components/Dialog/Dialog.stories.d.ts +6 -0
- package/dist/components/Dialog/Dialog.stories.d.ts.map +1 -1
- package/dist/components/Drawer/touchInput.d.ts +5 -0
- package/dist/components/Drawer/touchInput.d.ts.map +1 -1
- package/dist/components/Select/Select.d.ts.map +1 -1
- package/dist/components/Select/styles.css.d.ts +9 -0
- package/dist/components/Select/styles.css.d.ts.map +1 -1
- package/dist/index.css +1 -1
- package/dist/index.js +1941 -1924
- package/dist/index.js.map +1 -1
- package/dist/table.js +1 -1
- package/package.json +2 -2
- package/src/components/ButtonGroup/ButtonGroup.stories.tsx +70 -1
- package/src/components/ButtonGroup/attached.css.ts +4 -3
- package/src/components/ConfirmDialog/ConfirmDialog.tsx +4 -1
- package/src/components/Dialog/Dialog.meta.ts +1 -1
- package/src/components/Dialog/Dialog.native.tsx +22 -2
- package/src/components/Dialog/Dialog.stories.tsx +121 -0
- package/src/components/Dialog/Dialog.tsx +15 -0
- package/src/components/Drawer/touchInput.ts +8 -0
- package/src/components/Select/Select.tsx +1 -0
- package/src/components/Select/styles.css.ts +15 -0
- package/src/components/Toggle/styles.css.ts +4 -4
- package/dist/Table-CT2te7FV.js.map +0 -1
package/dist/table.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { M as F, v as xt, R as it, H as pt, w as kt, x as bt, y as ft, z as mt, e as ht, a as yt, r as St, A as Tt } from "./Table-
|
|
1
|
+
import { M as F, v as xt, R as it, H as pt, w as kt, x as bt, y as ft, z as mt, e as ht, a as yt, r as St, A as Tt } from "./Table-ojMk5CaF.js";
|
|
2
2
|
import { jsx as g, jsxs as P } from "react/jsx-runtime";
|
|
3
3
|
import { c as H, m as k, d as b } from "./compiler-runtime-CV6vsf8h.js";
|
|
4
4
|
import { flexRender as E, useReactTable as rt, getPaginationRowModel as Ct, getFilteredRowModel as vt, getSortedRowModel as at, getCoreRowModel as st } from "@tanstack/react-table";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@greenharness/greenrack-ui",
|
|
3
|
-
"version": "7.0
|
|
3
|
+
"version": "7.1.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -92,7 +92,7 @@
|
|
|
92
92
|
"dependencies": {
|
|
93
93
|
"@tanstack/react-virtual": "^3.14.13",
|
|
94
94
|
"qrcode": "^1.5.4",
|
|
95
|
-
"@greenharness/greenrack-tokens": "^7.0
|
|
95
|
+
"@greenharness/greenrack-tokens": "^7.1.0"
|
|
96
96
|
},
|
|
97
97
|
"devDependencies": {
|
|
98
98
|
"@babel/preset-typescript": "^7.28.0",
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {useState} from 'react'
|
|
1
|
+
import {useEffect, useState} from 'react'
|
|
2
|
+
import {html} from 'react-strict-dom'
|
|
2
3
|
import type {Meta, StoryObj} from '@storybook/react'
|
|
3
4
|
import {expect, userEvent, waitFor, within} from 'storybook/test'
|
|
4
5
|
import {
|
|
@@ -13,6 +14,7 @@ import {withCoarsePointer, withFinePointer} from '../../docs/coarsePointer'
|
|
|
13
14
|
import {ButtonGroup} from './ButtonGroup'
|
|
14
15
|
import type {ControlSize} from '../../shared/types'
|
|
15
16
|
import {Button} from '../Button/Button'
|
|
17
|
+
import {centre, mouseMove} from '../Drawer/touchInput'
|
|
16
18
|
import {Icon} from '../Icon/Icon'
|
|
17
19
|
import {Inline} from '../Inline/Inline'
|
|
18
20
|
import {Menu} from '../Menu/Menu'
|
|
@@ -251,6 +253,33 @@ export const AttachedFocusMiddle: Story = {
|
|
|
251
253
|
const y = r.top + r.height / 2
|
|
252
254
|
await expect(middle.contains(document.elementFromPoint(r.left + 0.5, y))).toBe(true)
|
|
253
255
|
await expect(middle.contains(document.elementFromPoint(r.right - 0.5, y))).toBe(true)
|
|
256
|
+
// The design system's ring, not the browser's default outline.
|
|
257
|
+
await expect(getComputedStyle(middle).outlineStyle).toBe('solid')
|
|
258
|
+
await expect(getComputedStyle(middle).outlineWidth).toBe('2px')
|
|
259
|
+
},
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/** A hovered Select in an attached group hovers like the Buttons and Toggles
|
|
263
|
+
* beside it: transparent at rest, a fill on hover, the border unchanged, and
|
|
264
|
+
* it rises above its neighbours so the whole edge is its own. */
|
|
265
|
+
export const AttachedHoverMiddle: Story = {
|
|
266
|
+
render: () => <TextStyleSelects />,
|
|
267
|
+
play: async ({canvas}) => {
|
|
268
|
+
const [first, middle] = canvas.getAllByRole('combobox')
|
|
269
|
+
await expect(getComputedStyle(middle).backgroundColor).toBe('rgba(0, 0, 0, 0)')
|
|
270
|
+
const restBorder = getComputedStyle(middle).borderTopColor
|
|
271
|
+
await mouseMove(centre(middle))
|
|
272
|
+
try {
|
|
273
|
+
await waitFor(() =>
|
|
274
|
+
expect(getComputedStyle(middle).backgroundColor).not.toBe('rgba(0, 0, 0, 0)'),
|
|
275
|
+
)
|
|
276
|
+
await expect(getComputedStyle(middle).borderTopColor).toBe(restBorder)
|
|
277
|
+
await expect(getComputedStyle(middle).zIndex).toBe(String(LAYERS.raised))
|
|
278
|
+
await expect(getComputedStyle(first).zIndex).toBe('auto')
|
|
279
|
+
} finally {
|
|
280
|
+
// The pointer is shared by every story file: park it off the controls.
|
|
281
|
+
await mouseMove({x: 0, y: 0})
|
|
282
|
+
}
|
|
254
283
|
},
|
|
255
284
|
}
|
|
256
285
|
|
|
@@ -529,3 +558,43 @@ export const SmallTriggersRowCoarsePointer: Story = {
|
|
|
529
558
|
})
|
|
530
559
|
},
|
|
531
560
|
}
|
|
561
|
+
|
|
562
|
+
interface HoverBorderArgs {
|
|
563
|
+
hoverBorder: string
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
/**
|
|
567
|
+
* A playground, not the component: a stylesheet added for the story colours
|
|
568
|
+
* the border of whichever control in the groups below is hovered, so a hover
|
|
569
|
+
* border can be judged against the joined corners (round at the ends, square
|
|
570
|
+
* inside) and the raise above the neighbours. The components themselves keep
|
|
571
|
+
* the border unchanged on hover.
|
|
572
|
+
*/
|
|
573
|
+
function HoverBorderPlayground({hoverBorder}: HoverBorderArgs) {
|
|
574
|
+
useEffect(() => {
|
|
575
|
+
const sheet = document.createElement('style')
|
|
576
|
+
sheet.textContent = `[data-hover-border] [role="group"] button:hover { border-color: ${hoverBorder} !important; }`
|
|
577
|
+
document.head.appendChild(sheet)
|
|
578
|
+
return () => sheet.remove()
|
|
579
|
+
}, [hoverBorder])
|
|
580
|
+
return (
|
|
581
|
+
<html.div data-hover-border="">
|
|
582
|
+
<Stack gap="md">
|
|
583
|
+
<TextStyleSelects />
|
|
584
|
+
<FormatGroup />
|
|
585
|
+
</Stack>
|
|
586
|
+
</html.div>
|
|
587
|
+
)
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
/** Pick a hover border colour and hover across both groups. */
|
|
591
|
+
export const AttachedHoverBorderPlayground: StoryObj<HoverBorderArgs> = {
|
|
592
|
+
args: {hoverBorder: '#6aaffc'},
|
|
593
|
+
argTypes: {
|
|
594
|
+
hoverBorder: {
|
|
595
|
+
control: 'color',
|
|
596
|
+
description: 'border-color of the hovered control (story only; the components keep theirs)',
|
|
597
|
+
},
|
|
598
|
+
},
|
|
599
|
+
render: ({hoverBorder}) => <HoverBorderPlayground hoverBorder={hoverBorder} />,
|
|
600
|
+
}
|
|
@@ -8,12 +8,13 @@ import {layers} from '@greenharness/greenrack-tokens/tokens/layers.css'
|
|
|
8
8
|
const overlap = `calc(-1 * ${borders.hairline})`
|
|
9
9
|
|
|
10
10
|
export const attached = css.create({
|
|
11
|
-
// A focused control rises above its neighbours, so their borders
|
|
12
|
-
// cover its
|
|
11
|
+
// A hovered or focused control rises above its neighbours, so their borders
|
|
12
|
+
// never cover its state edge or its focus ring (Primer, Spectrum and Ant
|
|
13
|
+
// raise on hover too). Position makes the z-index apply to a trigger that
|
|
13
14
|
// is not itself the flex item (Select and Menu triggers sit in a Root).
|
|
14
15
|
item: {
|
|
15
16
|
position: 'relative',
|
|
16
|
-
zIndex: {default: null, ':focus-visible': layers.raised},
|
|
17
|
+
zIndex: {default: null, ':hover': layers.raised, ':focus-visible': layers.raised},
|
|
17
18
|
},
|
|
18
19
|
horizontalFirst: {
|
|
19
20
|
borderTopRightRadius: 0,
|
|
@@ -29,6 +29,8 @@ interface ConfirmDialogProps {
|
|
|
29
29
|
onConfirm?: () => void
|
|
30
30
|
confirmLabel?: ReactNode
|
|
31
31
|
size?: DialogSize
|
|
32
|
+
/** Called once per finished exit, after focus is back; see Dialog.Root `onExitComplete`. */
|
|
33
|
+
onExitComplete?: () => void
|
|
32
34
|
}
|
|
33
35
|
|
|
34
36
|
/**
|
|
@@ -49,6 +51,7 @@ export function ConfirmDialog({
|
|
|
49
51
|
onConfirm,
|
|
50
52
|
confirmLabel = 'Confirm',
|
|
51
53
|
size = 'sm',
|
|
54
|
+
onExitComplete,
|
|
52
55
|
}: ConfirmDialogProps) {
|
|
53
56
|
const [typed, setTyped] = useState('')
|
|
54
57
|
const satisfied = !confirmPhrase || typed.trim() === confirmPhrase
|
|
@@ -59,7 +62,7 @@ export function ConfirmDialog({
|
|
|
59
62
|
}
|
|
60
63
|
|
|
61
64
|
return (
|
|
62
|
-
<Dialog.Root open={open} onOpenChange={handleOpenChange}>
|
|
65
|
+
<Dialog.Root open={open} onOpenChange={handleOpenChange} onExitComplete={onExitComplete}>
|
|
63
66
|
<Dialog.Portal size={size}>
|
|
64
67
|
<Dialog.Header>
|
|
65
68
|
<Dialog.Title>{title}</Dialog.Title>
|
|
@@ -2,7 +2,7 @@ import type {ComponentMeta} from '../component-meta'
|
|
|
2
2
|
|
|
3
3
|
export const meta: ComponentMeta = {
|
|
4
4
|
description:
|
|
5
|
-
'Modal dialog with backdrop overlay. Centered on screen with scale+fade animation. Moves focus in on open (initialFocus, else the first focusable element, else the dialog) and back on close; dismisses on backdrop click (dismissable) or Escape (closeOnEscape, independent of dismissable). Use for confirmations, forms, or content that requires user attention before continuing.',
|
|
5
|
+
'Modal dialog with backdrop overlay. Centered on screen with scale+fade animation. Moves focus in on open (initialFocus, else the first focusable element, else the dialog) and back on close; dismisses on backdrop click (dismissable) or Escape (closeOnEscape, independent of dismissable). `onExitComplete` is called once per finished exit after focus is back, the place to unmount: for an inside close (Escape, backdrop, Dialog.Close) `onOpenChange(false)` runs first, then `onExitComplete`; an outside close (controlled open turning false) calls only `onExitComplete`; it is not called for an exit cancelled by a reopen; an owner that unmounts on `onOpenChange(false)` instead loses the focus hand-back; on native it runs after the accessibility-focus request is sent (delivery not confirmed). Use for confirmations, forms, or content that requires user attention before continuing.',
|
|
6
6
|
whenToUse: [
|
|
7
7
|
'Confirmation prompts (delete, revoke, destructive actions)',
|
|
8
8
|
'Short forms or data entry that blocks the main flow',
|
|
@@ -82,6 +82,17 @@ interface RootProps {
|
|
|
82
82
|
/** Web only: on native, screen-reader focus moves to the dialog itself. */
|
|
83
83
|
initialFocus?: RefObject<HTMLElement | null>
|
|
84
84
|
closeAnimationDuration?: DurationToken
|
|
85
|
+
/**
|
|
86
|
+
* Called once per finished exit, after focus is back on what held it before
|
|
87
|
+
* the open: the place to unmount. For an inside close (Escape, backdrop,
|
|
88
|
+
* Dialog.Close) `onOpenChange(false)` runs first, then `onExitComplete`; an
|
|
89
|
+
* outside close (a controlled `open` turning false) calls only
|
|
90
|
+
* `onExitComplete`. Not called for an exit cancelled by a reopen. An owner
|
|
91
|
+
* that unmounts on `onOpenChange(false)` instead loses the focus hand-back.
|
|
92
|
+
* On native it runs after the accessibility-focus request is sent (delivery
|
|
93
|
+
* is not confirmed).
|
|
94
|
+
*/
|
|
95
|
+
onExitComplete?: () => void
|
|
85
96
|
}
|
|
86
97
|
|
|
87
98
|
/**
|
|
@@ -98,6 +109,7 @@ function Root({
|
|
|
98
109
|
dismissable = true,
|
|
99
110
|
closeOnEscape = true,
|
|
100
111
|
closeAnimationDuration = 'fast',
|
|
112
|
+
onExitComplete,
|
|
101
113
|
}: RootProps) {
|
|
102
114
|
const {present, closing, requestOpen, requestClose} = useOverlayOpenState({
|
|
103
115
|
open: controlledOpen,
|
|
@@ -113,10 +125,18 @@ function Root({
|
|
|
113
125
|
const panelRef = useRef<View>(null)
|
|
114
126
|
const registerClose = useCallback(() => () => {}, [])
|
|
115
127
|
|
|
116
|
-
|
|
128
|
+
const onExitCompleteRef = useRef(onExitComplete)
|
|
129
|
+
useEffect(() => {
|
|
130
|
+
onExitCompleteRef.current = onExitComplete
|
|
131
|
+
})
|
|
132
|
+
|
|
133
|
+
// Back to the trigger once the dialog is gone, then tell the owner.
|
|
117
134
|
const wasPresent = useRef(present)
|
|
118
135
|
useEffect(() => {
|
|
119
|
-
if (wasPresent.current && !present)
|
|
136
|
+
if (wasPresent.current && !present) {
|
|
137
|
+
focusForAccessibility(triggerRef.current, 'Dialog')
|
|
138
|
+
onExitCompleteRef.current?.()
|
|
139
|
+
}
|
|
120
140
|
wasPresent.current = present
|
|
121
141
|
}, [present])
|
|
122
142
|
|
|
@@ -680,3 +680,124 @@ export const EscapeClosesPopoverFirst: Story = {
|
|
|
680
680
|
await waitFor(() => expect(page.queryByRole('dialog', {name: 'Host'})).not.toBeInTheDocument())
|
|
681
681
|
},
|
|
682
682
|
}
|
|
683
|
+
|
|
684
|
+
// --- onExitComplete ---
|
|
685
|
+
|
|
686
|
+
interface ExitCompleteOwnerProps {
|
|
687
|
+
outside: boolean
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
function ExitCompleteOwner({outside}: ExitCompleteOwnerProps) {
|
|
691
|
+
const [mounted, setMounted] = useState(true)
|
|
692
|
+
const [open, setOpen] = useState(false)
|
|
693
|
+
const [exits, setExits] = useState(0)
|
|
694
|
+
const [focusOnOpener, setFocusOnOpener] = useState('not yet')
|
|
695
|
+
const [order, setOrder] = useState<string[]>([])
|
|
696
|
+
const openerRef = useRef<HTMLButtonElement>(null)
|
|
697
|
+
return (
|
|
698
|
+
<Stack gap="sm">
|
|
699
|
+
<html.button ref={openerRef} onClick={() => setOpen(true)}>
|
|
700
|
+
Open notice
|
|
701
|
+
</html.button>
|
|
702
|
+
{outside && <Button onClick={() => setOpen(false)}>Close from outside</Button>}
|
|
703
|
+
<Text>{`Mounted: ${mounted ? 'yes' : 'no'}`}</Text>
|
|
704
|
+
<Text>{`Exits reported: ${exits}`}</Text>
|
|
705
|
+
<Text>{`Focus on opener at notice: ${focusOnOpener}`}</Text>
|
|
706
|
+
<Text>{`Order: ${order.join(', ')}`}</Text>
|
|
707
|
+
{mounted && (
|
|
708
|
+
<Dialog.Root
|
|
709
|
+
open={open}
|
|
710
|
+
onOpenChange={(next) => {
|
|
711
|
+
setOpen(next)
|
|
712
|
+
if (!next) setOrder((log) => [...log, 'onOpenChange(false)'])
|
|
713
|
+
}}
|
|
714
|
+
onExitComplete={() => {
|
|
715
|
+
setFocusOnOpener(document.activeElement === openerRef.current ? 'yes' : 'no')
|
|
716
|
+
setExits((count) => count + 1)
|
|
717
|
+
setOrder((log) => [...log, 'onExitComplete'])
|
|
718
|
+
setMounted(false)
|
|
719
|
+
}}
|
|
720
|
+
>
|
|
721
|
+
<Dialog.Portal size="sm" aria-label="Notice">
|
|
722
|
+
<Dialog.Body>
|
|
723
|
+
<Text>Notice body</Text>
|
|
724
|
+
</Dialog.Body>
|
|
725
|
+
</Dialog.Portal>
|
|
726
|
+
</Dialog.Root>
|
|
727
|
+
)}
|
|
728
|
+
</Stack>
|
|
729
|
+
)
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
/** An owner that unmounts on the notice after an outside close still gets focus back. */
|
|
733
|
+
export const UnmountOnExitCompleteOutside: Story = {
|
|
734
|
+
render: () => <ExitCompleteOwner outside />,
|
|
735
|
+
play: async ({canvasElement}) => {
|
|
736
|
+
const canvas = within(canvasElement)
|
|
737
|
+
const page = within(canvasElement.ownerDocument.body)
|
|
738
|
+
await userEvent.click(canvas.getByRole('button', {name: 'Open notice'}))
|
|
739
|
+
await page.findByRole('dialog')
|
|
740
|
+
await userEvent.click(page.getByRole('button', {name: 'Close from outside'}))
|
|
741
|
+
await waitFor(() => expect(canvas.getByText('Mounted: no')).toBeInTheDocument())
|
|
742
|
+
await expect(canvas.getByText('Exits reported: 1')).toBeInTheDocument()
|
|
743
|
+
await expect(canvas.getByText('Focus on opener at notice: yes')).toBeInTheDocument()
|
|
744
|
+
},
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
/** Escape reports `onOpenChange(false)` first, then the notice, and focus is on the opener. */
|
|
748
|
+
export const UnmountOnExitCompleteEscape: Story = {
|
|
749
|
+
render: () => <ExitCompleteOwner outside={false} />,
|
|
750
|
+
play: async ({canvasElement}) => {
|
|
751
|
+
const canvas = within(canvasElement)
|
|
752
|
+
const page = within(canvasElement.ownerDocument.body)
|
|
753
|
+
await userEvent.click(canvas.getByRole('button', {name: 'Open notice'}))
|
|
754
|
+
await page.findByRole('dialog')
|
|
755
|
+
await userEvent.keyboard('{Escape}')
|
|
756
|
+
await waitFor(() => expect(canvas.getByText('Mounted: no')).toBeInTheDocument())
|
|
757
|
+
await expect(canvas.getByText('Exits reported: 1')).toBeInTheDocument()
|
|
758
|
+
await expect(canvas.getByText('Focus on opener at notice: yes')).toBeInTheDocument()
|
|
759
|
+
await expect(canvas.getByText('Order: onOpenChange(false), onExitComplete')).toBeInTheDocument()
|
|
760
|
+
},
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
function ReopenMidExitDemo() {
|
|
764
|
+
const [open, setOpen] = useState(true)
|
|
765
|
+
const [exits, setExits] = useState(0)
|
|
766
|
+
return (
|
|
767
|
+
<Stack gap="sm">
|
|
768
|
+
<Button onClick={() => setOpen(false)}>Close it</Button>
|
|
769
|
+
<Button onClick={() => setOpen(true)}>Reopen it</Button>
|
|
770
|
+
<Text>{`Exits reported: ${exits}`}</Text>
|
|
771
|
+
<Dialog.Root
|
|
772
|
+
open={open}
|
|
773
|
+
onOpenChange={setOpen}
|
|
774
|
+
closeAnimationDuration="slow"
|
|
775
|
+
onExitComplete={() => setExits((count) => count + 1)}
|
|
776
|
+
>
|
|
777
|
+
<Dialog.Portal size="sm" aria-label="Reopened">
|
|
778
|
+
<Dialog.Body>
|
|
779
|
+
<Text>Body</Text>
|
|
780
|
+
</Dialog.Body>
|
|
781
|
+
</Dialog.Portal>
|
|
782
|
+
</Dialog.Root>
|
|
783
|
+
</Stack>
|
|
784
|
+
)
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
/** A reopen during the exit cancels it: no notice, then one after a full close. */
|
|
788
|
+
export const ReopenMidExitReportsNothing: Story = {
|
|
789
|
+
render: () => <ReopenMidExitDemo />,
|
|
790
|
+
play: async ({canvasElement}) => {
|
|
791
|
+
const canvas = within(canvasElement)
|
|
792
|
+
const page = within(canvasElement.ownerDocument.body)
|
|
793
|
+
await page.findByRole('dialog')
|
|
794
|
+
await userEvent.click(canvas.getByRole('button', {name: 'Close it'}))
|
|
795
|
+
await userEvent.click(canvas.getByRole('button', {name: 'Reopen it'}))
|
|
796
|
+
// Past the slow exit timer the reopen cancelled.
|
|
797
|
+
await new Promise((resolve) => setTimeout(resolve, DURATION_MS.slow * 2))
|
|
798
|
+
await expect(canvas.getByText('Exits reported: 0')).toBeInTheDocument()
|
|
799
|
+
await expect(page.getByRole('dialog')).toBeInTheDocument()
|
|
800
|
+
await userEvent.click(canvas.getByRole('button', {name: 'Close it'}))
|
|
801
|
+
await waitFor(() => expect(canvas.getByText('Exits reported: 1')).toBeInTheDocument())
|
|
802
|
+
},
|
|
803
|
+
}
|
|
@@ -60,6 +60,15 @@ interface RootProps {
|
|
|
60
60
|
initialFocus?: RefObject<HTMLElement | null>
|
|
61
61
|
/** Motion token for the close animation. Default: 'fast' (150ms) */
|
|
62
62
|
closeAnimationDuration?: DurationToken
|
|
63
|
+
/**
|
|
64
|
+
* Called once per finished exit, after focus is back on what held it before
|
|
65
|
+
* the open: the place to unmount. For an inside close (Escape, backdrop,
|
|
66
|
+
* Dialog.Close) `onOpenChange(false)` runs first, then `onExitComplete`; an
|
|
67
|
+
* outside close (a controlled `open` turning false) calls only
|
|
68
|
+
* `onExitComplete`. Not called for an exit cancelled by a reopen. An owner
|
|
69
|
+
* that unmounts on `onOpenChange(false)` instead loses the focus hand-back.
|
|
70
|
+
*/
|
|
71
|
+
onExitComplete?: () => void
|
|
63
72
|
}
|
|
64
73
|
|
|
65
74
|
function Root({
|
|
@@ -71,6 +80,7 @@ function Root({
|
|
|
71
80
|
closeOnEscape = true,
|
|
72
81
|
initialFocus,
|
|
73
82
|
closeAnimationDuration = 'fast',
|
|
83
|
+
onExitComplete,
|
|
74
84
|
}: RootProps) {
|
|
75
85
|
const {
|
|
76
86
|
open: isOpen,
|
|
@@ -116,6 +126,10 @@ function Root({
|
|
|
116
126
|
closeCountRef.current -= 1
|
|
117
127
|
}
|
|
118
128
|
}, [])
|
|
129
|
+
const onExitCompleteRef = useRef(onExitComplete)
|
|
130
|
+
useEffect(() => {
|
|
131
|
+
onExitCompleteRef.current = onExitComplete
|
|
132
|
+
})
|
|
119
133
|
const previousFocusRef = useRef<HTMLElement | null>(null)
|
|
120
134
|
const wasOpenRef = useRef(false)
|
|
121
135
|
useEffect(() => {
|
|
@@ -137,6 +151,7 @@ function Root({
|
|
|
137
151
|
const target = previousFocusRef.current
|
|
138
152
|
previousFocusRef.current = null
|
|
139
153
|
if (target?.isConnected) target.focus({preventScroll: true})
|
|
154
|
+
onExitCompleteRef.current?.()
|
|
140
155
|
}
|
|
141
156
|
wasOpenRef.current = present
|
|
142
157
|
}, [isOpen, present, initialFocus, closeOnEscape])
|
|
@@ -88,6 +88,14 @@ export async function touchTap(at: Point) {
|
|
|
88
88
|
await cdpSend('Input.dispatchTouchEvent', {type: 'touchEnd', touchPoints: []})
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
+
/**
|
|
92
|
+
* The mouse pointer moved to a point: a real `:hover`, which testing-library's
|
|
93
|
+
* synthetic `userEvent.hover` never produces.
|
|
94
|
+
*/
|
|
95
|
+
export async function mouseMove(at: Point) {
|
|
96
|
+
await cdpSend('Input.dispatchMouseEvent', {type: 'mouseMoved', ...toPage(at)})
|
|
97
|
+
}
|
|
98
|
+
|
|
91
99
|
/** The centre of an element, in its own document's coordinates. */
|
|
92
100
|
export function centre(el: Element): Point {
|
|
93
101
|
const r = el.getBoundingClientRect()
|
|
@@ -36,6 +36,21 @@ export const styles = css.create({
|
|
|
36
36
|
cursor: 'pointer',
|
|
37
37
|
transitionProperty: 'border-color',
|
|
38
38
|
transitionDuration: duration.fast,
|
|
39
|
+
// The design system's focus ring, as Button's: the browser's own outline
|
|
40
|
+
// was the only thing a focused trigger showed.
|
|
41
|
+
outlineWidth: {default: 0, ':focus-visible': borders.focusRing},
|
|
42
|
+
outlineStyle: {default: 'none', ':focus-visible': 'solid'},
|
|
43
|
+
outlineColor: {default: 'transparent', ':focus-visible': colors.accent},
|
|
44
|
+
outlineOffset: {default: 0, ':focus-visible': borders.focusOffset},
|
|
45
|
+
},
|
|
46
|
+
// In an attached ButtonGroup the trigger is one control of the group, not a
|
|
47
|
+
// form field: transparent like the Buttons and Toggles beside it, and a
|
|
48
|
+
// hover that changes the fill only, so no item of the group outlines on its
|
|
49
|
+
// own (the accent hover border stays for the standalone, Input-like trigger).
|
|
50
|
+
triggerAttached: {
|
|
51
|
+
backgroundColor: {default: 'transparent', ':hover': colors.bgCardHover},
|
|
52
|
+
borderColor: colors.border,
|
|
53
|
+
transitionProperty: 'background-color',
|
|
39
54
|
},
|
|
40
55
|
// The whole control disabled: Button's disabled look, and no hover accent.
|
|
41
56
|
triggerDisabled: {
|
|
@@ -62,10 +62,10 @@ export const styles = css.create({
|
|
|
62
62
|
default: 'transparent',
|
|
63
63
|
':hover': colors.bgCardHover,
|
|
64
64
|
},
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
65
|
+
// Hover changes the fill only, as Button's secondary and ghost variants
|
|
66
|
+
// do: in an attached ButtonGroup a Toggle sits beside them, and a border
|
|
67
|
+
// that darkened on hover made it the odd one out.
|
|
68
|
+
borderColor: colors.border,
|
|
69
69
|
color: colors.textMuted,
|
|
70
70
|
},
|
|
71
71
|
pressed: {
|