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