@atlaskit/top-layer 4.0.0 → 4.2.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/CHANGELOG.md +17 -0
- package/dist/cjs/dialog/dialog-content.compiled.css +1 -0
- package/dist/cjs/dialog/dialog-content.js +53 -26
- package/dist/cjs/internal/use-animated-visibility.js +36 -39
- package/dist/cjs/popover/popover.compiled.css +1 -0
- package/dist/cjs/popover/popover.js +19 -20
- package/dist/es2019/dialog/dialog-content.compiled.css +1 -0
- package/dist/es2019/dialog/dialog-content.js +54 -28
- package/dist/es2019/internal/use-animated-visibility.js +38 -39
- package/dist/es2019/popover/popover.compiled.css +1 -0
- package/dist/es2019/popover/popover.js +17 -18
- package/dist/esm/dialog/dialog-content.compiled.css +1 -0
- package/dist/esm/dialog/dialog-content.js +55 -28
- package/dist/esm/internal/use-animated-visibility.js +38 -41
- package/dist/esm/popover/popover.compiled.css +1 -0
- package/dist/esm/popover/popover.js +19 -20
- package/dist/types/dialog/dialog-content.d.ts +2 -2
- package/dist/types/dialog/index.d.ts +1 -1
- package/dist/types/dialog/types.d.ts +17 -3
- package/dist/types/entry-points/dialog.d.ts +1 -1
- package/dist/types/internal/use-animated-visibility.d.ts +7 -1
- package/dist/types/popover/popover.d.ts +1 -5
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { useEffect, useLayoutEffect, useRef, useState } from 'react';
|
|
2
|
-
import { bind
|
|
1
|
+
import { useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react';
|
|
2
|
+
import { bind } from 'bind-event-listener';
|
|
3
3
|
import { prefersReducedMotion } from './reduced-motion';
|
|
4
4
|
/**
|
|
5
5
|
* Using the recommended motion timings for safety net.
|
|
@@ -110,7 +110,7 @@ function runOnTransitionEndOrTimeout({
|
|
|
110
110
|
* `entering`, `open`, `exiting`). The host element is rendered while
|
|
111
111
|
* `phase !== 'closed'`, so the `exiting` phase keeps the host mounted
|
|
112
112
|
* while the CSS exit transition plays (or, with animation disabled,
|
|
113
|
-
* while we wait for the browser `toggle`
|
|
113
|
+
* while we wait for the browser's closing `toggle` event to fire on the
|
|
114
114
|
* still-attached element):
|
|
115
115
|
*
|
|
116
116
|
* ```
|
|
@@ -130,6 +130,7 @@ export function useAnimatedVisibility({
|
|
|
130
130
|
onExitFinish
|
|
131
131
|
}) {
|
|
132
132
|
const willAnimate = shouldAnimate && !prefersReducedMotion();
|
|
133
|
+
const isNativeClosedRef = useRef(false);
|
|
133
134
|
|
|
134
135
|
// Promote `closed → entering`/`closed → open` synchronously during
|
|
135
136
|
// render so the host element mounts in the same commit as the open
|
|
@@ -140,16 +141,23 @@ export function useAnimatedVisibility({
|
|
|
140
141
|
}
|
|
141
142
|
return willAnimate ? 'entering' : 'open';
|
|
142
143
|
});
|
|
143
|
-
|
|
144
|
+
|
|
145
|
+
// Rearm only after controlled state and the native lifecycle have both
|
|
146
|
+
// reached closed. Resetting as soon as `isOpen` becomes false can erase a
|
|
147
|
+
// closing toggle that was handled in the same React batch.
|
|
148
|
+
if (!isOpen && phase === 'closed') {
|
|
149
|
+
isNativeClosedRef.current = false;
|
|
150
|
+
}
|
|
151
|
+
if (isOpen && phase === 'closed' && !isNativeClosedRef.current) {
|
|
144
152
|
setPhase(willAnimate ? 'entering' : 'open');
|
|
145
153
|
}
|
|
146
154
|
if (!isOpen && (phase === 'open' || phase === 'entering')) {
|
|
147
155
|
// Close intent. Move to `exiting` to gate the unmount on either
|
|
148
|
-
// the exit transition (animated) or the toggle
|
|
156
|
+
// the exit transition (animated) or the closing toggle event
|
|
149
157
|
// (non-animated). Includes interrupted entry (`entering → exiting`).
|
|
150
158
|
setPhase('exiting');
|
|
151
159
|
}
|
|
152
|
-
if (isOpen && phase === 'exiting') {
|
|
160
|
+
if (isOpen && phase === 'exiting' && !isNativeClosedRef.current) {
|
|
153
161
|
// Reopen mid-exit. With animation, jump back to `entering` and let
|
|
154
162
|
// the entry transition restart from current visual state. Without
|
|
155
163
|
// animation, jump straight to `open` (the handshake we were waiting
|
|
@@ -234,47 +242,37 @@ export function useAnimatedVisibility({
|
|
|
234
242
|
});
|
|
235
243
|
}, [phase, willAnimate, animationKind, elementRef]);
|
|
236
244
|
|
|
237
|
-
//
|
|
238
|
-
//
|
|
239
|
-
//
|
|
240
|
-
// native focus restoration both run against the still-attached
|
|
241
|
-
// element. A naive `setTimeout(0)` occasionally beats the `toggle`
|
|
242
|
-
// task in Chromium and drops focus restoration.
|
|
243
|
-
//
|
|
244
|
-
// `useLayoutEffect` so the listener binds in the same commit as the
|
|
245
|
-
// show/hide layout effect that calls `hidePopover()` / `dialog.close()`.
|
|
246
|
-
// The toggle/close event is queued as a task and cannot run until the
|
|
247
|
-
// frame completes. SSR-safe: `phase` starts at `'closed'`.
|
|
248
|
-
//
|
|
249
|
-
// `onExitFinish` is fired separately (see effect below) so consumers
|
|
250
|
-
// observe it the moment `isOpen` flips to `false`.
|
|
245
|
+
// Native dismissal is authoritative. Its toggle can arrive while controlled
|
|
246
|
+
// state still says open, so remember that native state and do not
|
|
247
|
+
// reopen until `isOpen` has first moved to false.
|
|
251
248
|
useLayoutEffect(() => {
|
|
252
|
-
if (phase
|
|
253
|
-
|
|
249
|
+
if (phase === 'exiting' && !willAnimate && isNativeClosedRef.current) {
|
|
250
|
+
setPhase('closed');
|
|
254
251
|
}
|
|
255
|
-
|
|
256
|
-
|
|
252
|
+
}, [phase, willAnimate]);
|
|
253
|
+
const onToggle = useCallback(event => {
|
|
254
|
+
if (event.newState === 'open') {
|
|
255
|
+
isNativeClosedRef.current = false;
|
|
257
256
|
return;
|
|
258
257
|
}
|
|
259
|
-
|
|
260
|
-
|
|
258
|
+
if (event.newState !== 'closed') {
|
|
259
|
+
return;
|
|
261
260
|
}
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
unmount();
|
|
267
|
-
}
|
|
261
|
+
isNativeClosedRef.current = true;
|
|
262
|
+
setPhase(current => {
|
|
263
|
+
if (current === 'open' || current === 'entering') {
|
|
264
|
+
return 'exiting';
|
|
268
265
|
}
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
266
|
+
if (current === 'exiting' && !willAnimate) {
|
|
267
|
+
return 'closed';
|
|
268
|
+
}
|
|
269
|
+
return current;
|
|
270
|
+
});
|
|
271
|
+
}, [willAnimate]);
|
|
274
272
|
|
|
275
273
|
// Non-animated exit callback. No `transitionend` to wait for, so fire
|
|
276
274
|
// `onExitFinish` on the transition into `exiting` (the unmount itself
|
|
277
|
-
// is gated by the toggle
|
|
275
|
+
// is gated by the closing toggle handshake above).
|
|
278
276
|
const prevPhaseForExitRef = useRef('closed');
|
|
279
277
|
useEffect(() => {
|
|
280
278
|
const prevPhase = prevPhaseForExitRef.current;
|
|
@@ -289,6 +287,7 @@ export function useAnimatedVisibility({
|
|
|
289
287
|
}
|
|
290
288
|
}, [phase, willAnimate]);
|
|
291
289
|
return {
|
|
292
|
-
phase
|
|
290
|
+
phase,
|
|
291
|
+
onToggle
|
|
293
292
|
};
|
|
294
293
|
}
|
|
@@ -25,7 +25,8 @@ const supportsPopoverHint = once(() => {
|
|
|
25
25
|
return element.popover === 'hint';
|
|
26
26
|
});
|
|
27
27
|
|
|
28
|
-
// Surface reset — neutralises inherited text-layout properties
|
|
28
|
+
// Surface reset — neutralises inherited interaction and text-layout properties
|
|
29
|
+
// (e.g. `pointer-events: none` from an overlaid controls container and
|
|
29
30
|
// `white-space: nowrap` from an `@atlaskit/select` option) that leak into a
|
|
30
31
|
// top-layer element because, for CSS inheritance, it is still a DOM child of its
|
|
31
32
|
// trigger (top-layer promotion is paint/stacking only; the legacy portal path
|
|
@@ -37,7 +38,7 @@ const supportsPopoverHint = once(() => {
|
|
|
37
38
|
// `no-imported-style-values` — Compiled styles are null at runtime), so the reset is
|
|
38
39
|
// co-located and duplicated deliberately.
|
|
39
40
|
const surfaceResetStyles = {
|
|
40
|
-
root: "_o5724jg8 _1nmz4jg8 _1i4q4jg8 _y3gnv2br _azhwidpf _1p1dglyw"
|
|
41
|
+
root: "_lcxv1wug _o5724jg8 _1nmz4jg8 _1i4q4jg8 _y3gnv2br _azhwidpf _1p1dglyw"
|
|
41
42
|
};
|
|
42
43
|
const styles = {
|
|
43
44
|
root: "_19itglyw _ca0qidpf _u5f3idpf _n3tdidpf _19bvidpf _19pkidpf _2hwxidpf _otyridpf _18u0idpf _1r041wug _1reoewfl _18m9ewfl _bfhk1j28 _4t3i1wug",
|
|
@@ -88,11 +89,7 @@ const POPUP_ROLES = new Set(['menu', 'listbox', 'dialog', 'alertdialog', 'tree',
|
|
|
88
89
|
* ### 📜 Browser dismiss is non-cancellable
|
|
89
90
|
*
|
|
90
91
|
* Per the popover spec, `beforetoggle` is cancellable on open transitions
|
|
91
|
-
* only, not on close.
|
|
92
|
-
* (e.g. a click on a logically-associated external trigger) must reconcile
|
|
93
|
-
* inside their own `onClose` handler by calling `showPopover()` again.
|
|
94
|
-
* `Popover` does not self-heal so consumers do not pay a reconcile cost
|
|
95
|
-
* by default.
|
|
92
|
+
* only, not on close.
|
|
96
93
|
*
|
|
97
94
|
* - Spec: <https://html.spec.whatwg.org/multipage/popover.html#the-popover-attribute>
|
|
98
95
|
* - <https://github.com/whatwg/html/issues/8973>
|
|
@@ -132,7 +129,8 @@ export const Popover = /*#__PURE__*/forwardRef(function Popover({
|
|
|
132
129
|
// `useId()` colons are invalid in CSS selectors and popover target attributes.
|
|
133
130
|
const popoverId = idProp !== null && idProp !== void 0 ? idProp : `popover-${autoId.replace(/:/g, '')}`;
|
|
134
131
|
const {
|
|
135
|
-
phase
|
|
132
|
+
phase,
|
|
133
|
+
onToggle
|
|
136
134
|
} = useAnimatedVisibility({
|
|
137
135
|
isOpen,
|
|
138
136
|
animationKind: 'popover',
|
|
@@ -214,6 +212,7 @@ export const Popover = /*#__PURE__*/forwardRef(function Popover({
|
|
|
214
212
|
const handleToggle = useCallback(event => {
|
|
215
213
|
const element = ownRef.current;
|
|
216
214
|
if (event.newState === 'open') {
|
|
215
|
+
onToggle(event);
|
|
217
216
|
return;
|
|
218
217
|
}
|
|
219
218
|
if (event.newState === 'closed') {
|
|
@@ -243,18 +242,18 @@ export const Popover = /*#__PURE__*/forwardRef(function Popover({
|
|
|
243
242
|
// Reset reason so a stale 'escape' from a race with Escape keydown
|
|
244
243
|
// does not corrupt the next browser-dismiss cycle.
|
|
245
244
|
closeReasonRef.current = 'light-dismiss';
|
|
246
|
-
|
|
245
|
+
} else {
|
|
246
|
+
// Browser dismiss (Escape/click-outside).
|
|
247
|
+
const reason = closeReasonRef.current;
|
|
248
|
+
closeReasonRef.current = 'light-dismiss';
|
|
249
|
+
// Optional: `manual` mode has no `onClose` in the forwarded type.
|
|
250
|
+
onClose === null || onClose === void 0 ? void 0 : onClose({
|
|
251
|
+
reason
|
|
252
|
+
});
|
|
247
253
|
}
|
|
248
|
-
|
|
249
|
-
// Browser dismiss (Escape/click-outside).
|
|
250
|
-
const reason = closeReasonRef.current;
|
|
251
|
-
closeReasonRef.current = 'light-dismiss';
|
|
252
|
-
// Optional: `manual` mode has no `onClose` in the forwarded type.
|
|
253
|
-
onClose === null || onClose === void 0 ? void 0 : onClose({
|
|
254
|
-
reason
|
|
255
|
-
});
|
|
256
254
|
}
|
|
257
|
-
|
|
255
|
+
onToggle(event);
|
|
256
|
+
}, [onClose, onToggle, role]);
|
|
258
257
|
|
|
259
258
|
// Bind via `useLayoutEffect`, and BEFORE the show/hide layout effect
|
|
260
259
|
// below, so listeners are attached when `showPopover()` synchronously
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
._bozgze3t{padding-inline-start:var(--ds-space-0,0)}
|
|
25
25
|
._c71lglyw{max-height:none}
|
|
26
26
|
._k8m011k7{transition-property:overlay,display}
|
|
27
|
+
._lcxv1wug{pointer-events:auto}
|
|
27
28
|
._o5724jg8{white-space:normal}
|
|
28
29
|
._otyr1wug{margin-bottom:auto}
|
|
29
30
|
._p12fglyw{max-width:none}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/* dialog-content.tsx generated by @compiled/babel-plugin v2.0.0 */
|
|
2
2
|
import "./dialog-content.compiled.css";
|
|
3
3
|
import { ax, ix } from "@compiled/react/runtime";
|
|
4
|
-
import React, { forwardRef, useCallback,
|
|
4
|
+
import React, { forwardRef, useCallback, useId, useLayoutEffect, useRef } from 'react';
|
|
5
5
|
import { cx } from '@compiled/react';
|
|
6
|
-
import {
|
|
6
|
+
import { bindAll } from 'bind-event-listener';
|
|
7
7
|
import mergeRefs from '@atlaskit/ds-lib/merge-refs';
|
|
8
8
|
import noop from '@atlaskit/ds-lib/noop';
|
|
9
9
|
import { useNotifyOpenLayerObserver } from '@atlaskit/layering/use-notify-open-layer-observer';
|
|
@@ -11,16 +11,16 @@ import { useAnimatedVisibility } from '../internal/use-animated-visibility';
|
|
|
11
11
|
import { useFocusWrap } from '../internal/use-focus-wrap';
|
|
12
12
|
import { useSafariEscapeFix } from '../internal/use-safari-escape-fix';
|
|
13
13
|
// Surface reset — see the rationale on `surfaceResetStyles` in `popover/popover.tsx`.
|
|
14
|
-
// Neutralises inherited text-layout properties (e.g.
|
|
15
|
-
//
|
|
16
|
-
// `direction`/`unicode-bidi` (RTL
|
|
17
|
-
// side-effects, so it does not reintroduce
|
|
18
|
-
// kept `height: auto` off `Dialog`.
|
|
14
|
+
// Neutralises inherited interaction and text-layout properties (e.g.
|
|
15
|
+
// `pointer-events: none` and `white-space: nowrap`) that leak into the top-layer
|
|
16
|
+
// surface. Excludes `color`/`font` (theming) and `direction`/`unicode-bidi` (RTL
|
|
17
|
+
// must inherit). The reset has no box side-effects, so it does not reintroduce
|
|
18
|
+
// the `margin: auto` centering problem that kept `height: auto` off `Dialog`.
|
|
19
19
|
//
|
|
20
20
|
// KEEP IN SYNC with the identical `surfaceResetStyles` in `popover/popover.tsx`
|
|
21
21
|
// (ADS forbids sharing styles across files, so it is co-located and duplicated).
|
|
22
22
|
var surfaceResetStyles = {
|
|
23
|
-
root: "_o5724jg8 _1nmz4jg8 _1i4q4jg8 _y3gnv2br _azhwidpf _1p1dglyw"
|
|
23
|
+
root: "_lcxv1wug _o5724jg8 _1nmz4jg8 _1i4q4jg8 _y3gnv2br _azhwidpf _1p1dglyw"
|
|
24
24
|
};
|
|
25
25
|
var dialogStyles = {
|
|
26
26
|
root: "_19itglyw _19pk1wug _2hwx1wug _otyr1wug _18u01wug _1q51ze3t _y4tize3t _85i5ze3t _bozgze3t _p12fglyw _c71lglyw _bfhk1j28",
|
|
@@ -45,8 +45,8 @@ var backdropStyles = {
|
|
|
45
45
|
*
|
|
46
46
|
* Handles native `cancel` event (Escape) and backdrop click detection.
|
|
47
47
|
*
|
|
48
|
-
* Close flow:
|
|
49
|
-
*
|
|
48
|
+
* Close flow: allowed user dismissal closes the native dialog before `onClose`
|
|
49
|
+
* notifies the consumer. The consumer must synchronize `isOpen` in response.
|
|
50
50
|
*
|
|
51
51
|
* Accessibility: render at least one focusable element (typically a close
|
|
52
52
|
* button) when `isOpen` becomes `true`. Tab is always trapped inside the
|
|
@@ -56,6 +56,8 @@ export var Dialog = /*#__PURE__*/forwardRef(function Dialog(_ref, ref) {
|
|
|
56
56
|
var children = _ref.children,
|
|
57
57
|
isOpen = _ref.isOpen,
|
|
58
58
|
onClose = _ref.onClose,
|
|
59
|
+
_ref$dismissedBy = _ref.dismissedBy,
|
|
60
|
+
dismissedBy = _ref$dismissedBy === void 0 ? 'escape-and-outside-click' : _ref$dismissedBy,
|
|
59
61
|
onEnterFinish = _ref.onEnterFinish,
|
|
60
62
|
onExitFinish = _ref.onExitFinish,
|
|
61
63
|
_ref$shouldAnimate = _ref.shouldAnimate,
|
|
@@ -73,6 +75,7 @@ export var Dialog = /*#__PURE__*/forwardRef(function Dialog(_ref, ref) {
|
|
|
73
75
|
var dialogId = providedId !== null && providedId !== void 0 ? providedId : generatedId;
|
|
74
76
|
var ownRef = useRef(null);
|
|
75
77
|
var combinedRef = mergeRefs([ownRef, ref]);
|
|
78
|
+
var closeReasonRef = useRef(null);
|
|
76
79
|
var _useAnimatedVisibilit = useAnimatedVisibility({
|
|
77
80
|
isOpen: isOpen,
|
|
78
81
|
animationKind: 'dialog',
|
|
@@ -81,7 +84,8 @@ export var Dialog = /*#__PURE__*/forwardRef(function Dialog(_ref, ref) {
|
|
|
81
84
|
onEnterFinish: onEnterFinish,
|
|
82
85
|
onExitFinish: onExitFinish
|
|
83
86
|
}),
|
|
84
|
-
phase = _useAnimatedVisibilit.phase
|
|
87
|
+
phase = _useAnimatedVisibilit.phase,
|
|
88
|
+
onToggle = _useAnimatedVisibilit.onToggle;
|
|
85
89
|
|
|
86
90
|
// True while the host element is mounted (any phase except `closed`).
|
|
87
91
|
// Used as a dep so listener-rebind effects re-attach after a remount.
|
|
@@ -112,6 +116,7 @@ export var Dialog = /*#__PURE__*/forwardRef(function Dialog(_ref, ref) {
|
|
|
112
116
|
return;
|
|
113
117
|
}
|
|
114
118
|
if (isOpen) {
|
|
119
|
+
closeReasonRef.current = null;
|
|
115
120
|
if (!dialog.open) {
|
|
116
121
|
dialog.showModal();
|
|
117
122
|
}
|
|
@@ -144,45 +149,67 @@ export var Dialog = /*#__PURE__*/forwardRef(function Dialog(_ref, ref) {
|
|
|
144
149
|
if (event.target !== event.currentTarget) {
|
|
145
150
|
return;
|
|
146
151
|
}
|
|
147
|
-
|
|
152
|
+
|
|
148
153
|
// Spurious Safari `cancel`: the keydown snapshot saw an open child
|
|
149
154
|
// popover, so this Escape belongs to that popover (light-dismissed
|
|
150
155
|
// natively). Keep the dialog open instead of forwarding to `onClose`.
|
|
151
156
|
if (shouldIgnoreEscape()) {
|
|
157
|
+
event.preventDefault();
|
|
152
158
|
return;
|
|
153
159
|
}
|
|
154
|
-
onClose({
|
|
155
|
-
reason: 'escape'
|
|
156
|
-
});
|
|
157
|
-
}, [onClose, shouldIgnoreEscape]);
|
|
158
160
|
|
|
159
|
-
|
|
161
|
+
// Without native `closedby`, cancel Escape only when dismissal is disabled.
|
|
162
|
+
// Allowed dismissal follows Popover behavior: the browser closes the element
|
|
163
|
+
// and `onClose` notifies the controlled owner of the reason.
|
|
164
|
+
if (dismissedBy === 'none') {
|
|
165
|
+
event.preventDefault();
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
closeReasonRef.current = 'escape';
|
|
169
|
+
}, [dismissedBy, shouldIgnoreEscape]);
|
|
170
|
+
|
|
171
|
+
// Handle backdrop interaction
|
|
160
172
|
// Attached via bind-event-listener rather than a React prop so we avoid
|
|
161
173
|
// a11y lint suppressions on the <dialog> element.
|
|
162
|
-
//
|
|
174
|
+
// The click listener provides light dismiss consistently across browsers.
|
|
163
175
|
// `isVisible` is in deps so the listener re-binds to the new <dialog>
|
|
164
176
|
// element after a host unmount / remount cycle.
|
|
165
|
-
|
|
177
|
+
useLayoutEffect(function () {
|
|
166
178
|
var dialog = ownRef.current;
|
|
167
179
|
if (!dialog) {
|
|
168
180
|
return;
|
|
169
181
|
}
|
|
170
|
-
return
|
|
182
|
+
return bindAll(dialog, [{
|
|
171
183
|
type: 'click',
|
|
172
184
|
listener: function listener(event) {
|
|
173
|
-
if (event.target === event.currentTarget) {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
185
|
+
if (event.target === event.currentTarget && dismissedBy === 'escape-and-outside-click') {
|
|
186
|
+
closeReasonRef.current = 'overlay-click';
|
|
187
|
+
// Calls native close because this is emulating the native light-dismiss behavior
|
|
188
|
+
dialog.close();
|
|
177
189
|
}
|
|
178
190
|
}
|
|
179
|
-
}
|
|
180
|
-
|
|
191
|
+
}, {
|
|
192
|
+
type: 'toggle',
|
|
193
|
+
listener: function listener(event) {
|
|
194
|
+
if (event.newState === 'closed') {
|
|
195
|
+
var reason = closeReasonRef.current;
|
|
196
|
+
closeReasonRef.current = null;
|
|
197
|
+
if (reason) {
|
|
198
|
+
onClose({
|
|
199
|
+
reason: reason
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// Visibility cleanup runs after close-reason handling.
|
|
205
|
+
onToggle(event);
|
|
206
|
+
}
|
|
207
|
+
}]);
|
|
208
|
+
}, [dismissedBy, onClose, onToggle, isVisible]);
|
|
181
209
|
|
|
182
210
|
// Unmount the `<dialog>` once exit completes so it does not leave an
|
|
183
211
|
// empty `role="dialog"` element in the accessibility tree. On the next
|
|
184
|
-
// open the element remounts and
|
|
185
|
-
// effects re-run against the fresh element.
|
|
212
|
+
// open the element remounts and its effects run against the fresh element.
|
|
186
213
|
if (!isVisible) {
|
|
187
214
|
return null;
|
|
188
215
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
|
-
import { useEffect, useLayoutEffect, useRef, useState } from 'react';
|
|
3
|
-
import { bind
|
|
2
|
+
import { useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react';
|
|
3
|
+
import { bind } from 'bind-event-listener';
|
|
4
4
|
import { prefersReducedMotion } from './reduced-motion';
|
|
5
5
|
/**
|
|
6
6
|
* Using the recommended motion timings for safety net.
|
|
@@ -110,7 +110,7 @@ function runOnTransitionEndOrTimeout(_ref) {
|
|
|
110
110
|
* `entering`, `open`, `exiting`). The host element is rendered while
|
|
111
111
|
* `phase !== 'closed'`, so the `exiting` phase keeps the host mounted
|
|
112
112
|
* while the CSS exit transition plays (or, with animation disabled,
|
|
113
|
-
* while we wait for the browser `toggle`
|
|
113
|
+
* while we wait for the browser's closing `toggle` event to fire on the
|
|
114
114
|
* still-attached element):
|
|
115
115
|
*
|
|
116
116
|
* ```
|
|
@@ -129,6 +129,7 @@ export function useAnimatedVisibility(_ref2) {
|
|
|
129
129
|
onEnterFinish = _ref2.onEnterFinish,
|
|
130
130
|
onExitFinish = _ref2.onExitFinish;
|
|
131
131
|
var willAnimate = shouldAnimate && !prefersReducedMotion();
|
|
132
|
+
var isNativeClosedRef = useRef(false);
|
|
132
133
|
|
|
133
134
|
// Promote `closed → entering`/`closed → open` synchronously during
|
|
134
135
|
// render so the host element mounts in the same commit as the open
|
|
@@ -142,16 +143,23 @@ export function useAnimatedVisibility(_ref2) {
|
|
|
142
143
|
_useState2 = _slicedToArray(_useState, 2),
|
|
143
144
|
phase = _useState2[0],
|
|
144
145
|
setPhase = _useState2[1];
|
|
145
|
-
|
|
146
|
+
|
|
147
|
+
// Rearm only after controlled state and the native lifecycle have both
|
|
148
|
+
// reached closed. Resetting as soon as `isOpen` becomes false can erase a
|
|
149
|
+
// closing toggle that was handled in the same React batch.
|
|
150
|
+
if (!isOpen && phase === 'closed') {
|
|
151
|
+
isNativeClosedRef.current = false;
|
|
152
|
+
}
|
|
153
|
+
if (isOpen && phase === 'closed' && !isNativeClosedRef.current) {
|
|
146
154
|
setPhase(willAnimate ? 'entering' : 'open');
|
|
147
155
|
}
|
|
148
156
|
if (!isOpen && (phase === 'open' || phase === 'entering')) {
|
|
149
157
|
// Close intent. Move to `exiting` to gate the unmount on either
|
|
150
|
-
// the exit transition (animated) or the toggle
|
|
158
|
+
// the exit transition (animated) or the closing toggle event
|
|
151
159
|
// (non-animated). Includes interrupted entry (`entering → exiting`).
|
|
152
160
|
setPhase('exiting');
|
|
153
161
|
}
|
|
154
|
-
if (isOpen && phase === 'exiting') {
|
|
162
|
+
if (isOpen && phase === 'exiting' && !isNativeClosedRef.current) {
|
|
155
163
|
// Reopen mid-exit. With animation, jump back to `entering` and let
|
|
156
164
|
// the entry transition restart from current visual state. Without
|
|
157
165
|
// animation, jump straight to `open` (the handshake we were waiting
|
|
@@ -240,49 +248,37 @@ export function useAnimatedVisibility(_ref2) {
|
|
|
240
248
|
});
|
|
241
249
|
}, [phase, willAnimate, animationKind, elementRef]);
|
|
242
250
|
|
|
243
|
-
//
|
|
244
|
-
//
|
|
245
|
-
//
|
|
246
|
-
// native focus restoration both run against the still-attached
|
|
247
|
-
// element. A naive `setTimeout(0)` occasionally beats the `toggle`
|
|
248
|
-
// task in Chromium and drops focus restoration.
|
|
249
|
-
//
|
|
250
|
-
// `useLayoutEffect` so the listener binds in the same commit as the
|
|
251
|
-
// show/hide layout effect that calls `hidePopover()` / `dialog.close()`.
|
|
252
|
-
// The toggle/close event is queued as a task and cannot run until the
|
|
253
|
-
// frame completes. SSR-safe: `phase` starts at `'closed'`.
|
|
254
|
-
//
|
|
255
|
-
// `onExitFinish` is fired separately (see effect below) so consumers
|
|
256
|
-
// observe it the moment `isOpen` flips to `false`.
|
|
251
|
+
// Native dismissal is authoritative. Its toggle can arrive while controlled
|
|
252
|
+
// state still says open, so remember that native state and do not
|
|
253
|
+
// reopen until `isOpen` has first moved to false.
|
|
257
254
|
useLayoutEffect(function () {
|
|
258
|
-
if (phase
|
|
259
|
-
|
|
255
|
+
if (phase === 'exiting' && !willAnimate && isNativeClosedRef.current) {
|
|
256
|
+
setPhase('closed');
|
|
260
257
|
}
|
|
261
|
-
|
|
262
|
-
|
|
258
|
+
}, [phase, willAnimate]);
|
|
259
|
+
var onToggle = useCallback(function (event) {
|
|
260
|
+
if (event.newState === 'open') {
|
|
261
|
+
isNativeClosedRef.current = false;
|
|
263
262
|
return;
|
|
264
263
|
}
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
return current === 'exiting' ? 'closed' : current;
|
|
268
|
-
});
|
|
264
|
+
if (event.newState !== 'closed') {
|
|
265
|
+
return;
|
|
269
266
|
}
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
unmount();
|
|
275
|
-
}
|
|
267
|
+
isNativeClosedRef.current = true;
|
|
268
|
+
setPhase(function (current) {
|
|
269
|
+
if (current === 'open' || current === 'entering') {
|
|
270
|
+
return 'exiting';
|
|
276
271
|
}
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
272
|
+
if (current === 'exiting' && !willAnimate) {
|
|
273
|
+
return 'closed';
|
|
274
|
+
}
|
|
275
|
+
return current;
|
|
276
|
+
});
|
|
277
|
+
}, [willAnimate]);
|
|
282
278
|
|
|
283
279
|
// Non-animated exit callback. No `transitionend` to wait for, so fire
|
|
284
280
|
// `onExitFinish` on the transition into `exiting` (the unmount itself
|
|
285
|
-
// is gated by the toggle
|
|
281
|
+
// is gated by the closing toggle handshake above).
|
|
286
282
|
var prevPhaseForExitRef = useRef('closed');
|
|
287
283
|
useEffect(function () {
|
|
288
284
|
var prevPhase = prevPhaseForExitRef.current;
|
|
@@ -297,6 +293,7 @@ export function useAnimatedVisibility(_ref2) {
|
|
|
297
293
|
}
|
|
298
294
|
}, [phase, willAnimate]);
|
|
299
295
|
return {
|
|
300
|
-
phase: phase
|
|
296
|
+
phase: phase,
|
|
297
|
+
onToggle: onToggle
|
|
301
298
|
};
|
|
302
299
|
}
|
|
@@ -25,7 +25,8 @@ var supportsPopoverHint = once(function () {
|
|
|
25
25
|
return element.popover === 'hint';
|
|
26
26
|
});
|
|
27
27
|
|
|
28
|
-
// Surface reset — neutralises inherited text-layout properties
|
|
28
|
+
// Surface reset — neutralises inherited interaction and text-layout properties
|
|
29
|
+
// (e.g. `pointer-events: none` from an overlaid controls container and
|
|
29
30
|
// `white-space: nowrap` from an `@atlaskit/select` option) that leak into a
|
|
30
31
|
// top-layer element because, for CSS inheritance, it is still a DOM child of its
|
|
31
32
|
// trigger (top-layer promotion is paint/stacking only; the legacy portal path
|
|
@@ -37,7 +38,7 @@ var supportsPopoverHint = once(function () {
|
|
|
37
38
|
// `no-imported-style-values` — Compiled styles are null at runtime), so the reset is
|
|
38
39
|
// co-located and duplicated deliberately.
|
|
39
40
|
var surfaceResetStyles = {
|
|
40
|
-
root: "_o5724jg8 _1nmz4jg8 _1i4q4jg8 _y3gnv2br _azhwidpf _1p1dglyw"
|
|
41
|
+
root: "_lcxv1wug _o5724jg8 _1nmz4jg8 _1i4q4jg8 _y3gnv2br _azhwidpf _1p1dglyw"
|
|
41
42
|
};
|
|
42
43
|
var styles = {
|
|
43
44
|
root: "_19itglyw _ca0qidpf _u5f3idpf _n3tdidpf _19bvidpf _19pkidpf _2hwxidpf _otyridpf _18u0idpf _1r041wug _1reoewfl _18m9ewfl _bfhk1j28 _4t3i1wug",
|
|
@@ -88,11 +89,7 @@ var POPUP_ROLES = new Set(['menu', 'listbox', 'dialog', 'alertdialog', 'tree', '
|
|
|
88
89
|
* ### 📜 Browser dismiss is non-cancellable
|
|
89
90
|
*
|
|
90
91
|
* Per the popover spec, `beforetoggle` is cancellable on open transitions
|
|
91
|
-
* only, not on close.
|
|
92
|
-
* (e.g. a click on a logically-associated external trigger) must reconcile
|
|
93
|
-
* inside their own `onClose` handler by calling `showPopover()` again.
|
|
94
|
-
* `Popover` does not self-heal so consumers do not pay a reconcile cost
|
|
95
|
-
* by default.
|
|
92
|
+
* only, not on close.
|
|
96
93
|
*
|
|
97
94
|
* - Spec: <https://html.spec.whatwg.org/multipage/popover.html#the-popover-attribute>
|
|
98
95
|
* - <https://github.com/whatwg/html/issues/8973>
|
|
@@ -139,7 +136,8 @@ export var Popover = /*#__PURE__*/forwardRef(function Popover(_ref, ref) {
|
|
|
139
136
|
onEnterFinish: onEnterFinish,
|
|
140
137
|
onExitFinish: onExitFinish
|
|
141
138
|
}),
|
|
142
|
-
phase = _useAnimatedVisibilit.phase
|
|
139
|
+
phase = _useAnimatedVisibilit.phase,
|
|
140
|
+
onToggle = _useAnimatedVisibilit.onToggle;
|
|
143
141
|
|
|
144
142
|
// True while the host element is mounted (any phase except `closed`).
|
|
145
143
|
// Used as a dep so listener-rebind effects re-attach after a remount.
|
|
@@ -212,6 +210,7 @@ export var Popover = /*#__PURE__*/forwardRef(function Popover(_ref, ref) {
|
|
|
212
210
|
var handleToggle = useCallback(function (event) {
|
|
213
211
|
var element = ownRef.current;
|
|
214
212
|
if (event.newState === 'open') {
|
|
213
|
+
onToggle(event);
|
|
215
214
|
return;
|
|
216
215
|
}
|
|
217
216
|
if (event.newState === 'closed') {
|
|
@@ -223,11 +222,11 @@ export var Popover = /*#__PURE__*/forwardRef(function Popover(_ref, ref) {
|
|
|
223
222
|
// click target keeps focus per HTML spec
|
|
224
223
|
// (`focusPreviousElement=false`).
|
|
225
224
|
var previouslyFocused = previouslyFocusedElementRef.current;
|
|
226
|
-
var
|
|
225
|
+
var reason = closeReasonRef.current;
|
|
227
226
|
var isProgrammatic = programmaticCloseRef.current;
|
|
228
227
|
var shouldRestore = previouslyFocused !== null && previouslyFocused.isConnected && shouldFocusIntoPopover({
|
|
229
228
|
role: role
|
|
230
|
-
}) && (
|
|
229
|
+
}) && (reason === 'escape' || isProgrammatic);
|
|
231
230
|
if (shouldRestore && previouslyFocused) {
|
|
232
231
|
previouslyFocused.focus({
|
|
233
232
|
preventScroll: true
|
|
@@ -241,18 +240,18 @@ export var Popover = /*#__PURE__*/forwardRef(function Popover(_ref, ref) {
|
|
|
241
240
|
// Reset reason so a stale 'escape' from a race with Escape keydown
|
|
242
241
|
// does not corrupt the next browser-dismiss cycle.
|
|
243
242
|
closeReasonRef.current = 'light-dismiss';
|
|
244
|
-
|
|
243
|
+
} else {
|
|
244
|
+
// Browser dismiss (Escape/click-outside).
|
|
245
|
+
var _reason = closeReasonRef.current;
|
|
246
|
+
closeReasonRef.current = 'light-dismiss';
|
|
247
|
+
// Optional: `manual` mode has no `onClose` in the forwarded type.
|
|
248
|
+
onClose === null || onClose === void 0 || onClose({
|
|
249
|
+
reason: _reason
|
|
250
|
+
});
|
|
245
251
|
}
|
|
246
|
-
|
|
247
|
-
// Browser dismiss (Escape/click-outside).
|
|
248
|
-
var reason = closeReasonRef.current;
|
|
249
|
-
closeReasonRef.current = 'light-dismiss';
|
|
250
|
-
// Optional: `manual` mode has no `onClose` in the forwarded type.
|
|
251
|
-
onClose === null || onClose === void 0 || onClose({
|
|
252
|
-
reason: reason
|
|
253
|
-
});
|
|
254
252
|
}
|
|
255
|
-
|
|
253
|
+
onToggle(event);
|
|
254
|
+
}, [onClose, onToggle, role]);
|
|
256
255
|
|
|
257
256
|
// Bind via `useLayoutEffect`, and BEFORE the show/hide layout effect
|
|
258
257
|
// below, so listeners are attached when `showPopover()` synchronously
|
|
@@ -14,8 +14,8 @@ import { type TDialogProps } from './types';
|
|
|
14
14
|
*
|
|
15
15
|
* Handles native `cancel` event (Escape) and backdrop click detection.
|
|
16
16
|
*
|
|
17
|
-
* Close flow:
|
|
18
|
-
*
|
|
17
|
+
* Close flow: allowed user dismissal closes the native dialog before `onClose`
|
|
18
|
+
* notifies the consumer. The consumer must synchronize `isOpen` in response.
|
|
19
19
|
*
|
|
20
20
|
* Accessibility: render at least one focusable element (typically a close
|
|
21
21
|
* button) when `isOpen` becomes `true`. Tab is always trapped inside the
|