@atlaskit/modal-dialog 17.2.5 → 17.2.6

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 CHANGED
@@ -1,5 +1,13 @@
1
1
  # @atlaskit/modal-dialog
2
2
 
3
+ ## 17.2.6
4
+
5
+ ### Patch Changes
6
+
7
+ - [`6594fc2cf92b4`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/6594fc2cf92b4) -
8
+ On the top-layer path, `ModalDialog` now forwards its `ref` to the native `<dialog>`.
9
+ - Updated dependencies
10
+
3
11
  ## 17.2.5
4
12
 
5
13
  ### Patch Changes
@@ -1,4 +1,4 @@
1
- import { expect, test } from '@af/integration-testing';
1
+ import { expect, type Page, test } from '@af/integration-testing';
2
2
 
3
3
  /**
4
4
  * Modal dialog: focus contract on the top-layer code path.
@@ -125,3 +125,100 @@ test.describe('Modal dialog: top-layer focus contract', () => {
125
125
  await expect(page.getByTestId('default-modal--close-button')).toBeFocused();
126
126
  });
127
127
  });
128
+
129
+ async function visitMatrix({ page }: { page: Page }) {
130
+ await page.visitExample<typeof import('../../examples/98-testing-initial-focus-matrix.tsx')>(
131
+ 'design-system',
132
+ 'modal-dialog',
133
+ 'testing-initial-focus-matrix',
134
+ { featureFlag },
135
+ );
136
+ }
137
+
138
+ // Waits two frames, so work that runs after a paint (effects, animation frames) has run.
139
+ async function waitForFrames({ page }: { page: Page }) {
140
+ await page.evaluate(
141
+ () =>
142
+ new Promise((resolve) => {
143
+ requestAnimationFrame(() => requestAnimationFrame(resolve));
144
+ }),
145
+ );
146
+ }
147
+
148
+ /**
149
+ * `showModal()` runs before the content effects (`autoFocus`, ref callbacks, layout effects), so a
150
+ * content `focus()` call works. The modal moves focus only as it opens. See `@atlaskit/top-layer`
151
+ * `notes/decisions/react-autofocus-and-focus-on-open.md`.
152
+ */
153
+ test.describe('Modal dialog: top-layer focus timing', () => {
154
+ test('several `autoFocus` fields: the last one keeps focus, as on the legacy path', async ({
155
+ page,
156
+ }) => {
157
+ await visitMatrix({ page });
158
+
159
+ await page.getByTestId('several-autofocus-modal-trigger').click();
160
+
161
+ await expect(page.getByTestId('several-autofocus-second')).toBeFocused();
162
+ });
163
+
164
+ test('a field with `autoFocus` that mounts after the open takes focus', async ({ page }) => {
165
+ await visitMatrix({ page });
166
+ await page.getByTestId('late-autofocus-field-modal-trigger').click();
167
+ await expect(page.getByTestId('late-autofocus-field-modal')).toBeVisible();
168
+
169
+ await page.getByTestId('late-autofocus-field-load').press('Enter');
170
+
171
+ await expect(page.getByTestId('late-autofocus-field')).toBeFocused();
172
+ });
173
+
174
+ test('an `autoFocus` ref wins over a field with `autoFocus`, as on the legacy path', async ({
175
+ page,
176
+ }) => {
177
+ await visitMatrix({ page });
178
+
179
+ await page.getByTestId('auto-focus-ref-over-field-modal-trigger').click();
180
+
181
+ await expect(page.getByTestId('auto-focus-ref-over-field-target')).toBeFocused();
182
+ });
183
+
184
+ test('an element that a ref callback hands to the `autoFocus` ref takes focus', async ({
185
+ page,
186
+ }) => {
187
+ await visitMatrix({ page });
188
+
189
+ await page.getByTestId('ref-callback-auto-focus-ref-modal-trigger').click();
190
+
191
+ await expect(page.getByTestId('ref-callback-auto-focus-ref-input')).toBeFocused();
192
+ });
193
+
194
+ test('content that mounts after the open does not take focus from the `<dialog>`', async ({
195
+ page,
196
+ }) => {
197
+ await visitMatrix({ page });
198
+ const dialog = page.getByRole('dialog', { name: 'Late content' });
199
+
200
+ await page.getByTestId('late-content-modal-trigger').click();
201
+ await expect(dialog).toBeFocused();
202
+
203
+ await expect(page.getByTestId('late-content-modal-action')).toBeVisible();
204
+ await waitForFrames({ page });
205
+
206
+ await expect(dialog).toBeFocused();
207
+ });
208
+
209
+ test('an `autoFocus` ref target that mounts after the open does not take focus', async ({
210
+ page,
211
+ }) => {
212
+ await visitMatrix({ page });
213
+ const dialog = page.getByRole('dialog', { name: 'Late autoFocus ref' });
214
+
215
+ await page.getByTestId('late-auto-focus-ref-modal-trigger').click();
216
+ await expect(dialog).toBeFocused();
217
+
218
+ await expect(page.getByTestId('late-auto-focus-ref-target')).toBeVisible();
219
+ await waitForFrames({ page });
220
+
221
+ await expect(page.getByTestId('late-auto-focus-ref-target')).not.toBeFocused();
222
+ await expect(dialog).toBeFocused();
223
+ });
224
+ });
@@ -13,10 +13,12 @@ var React = _react;
13
13
  var _runtime = require("@compiled/react/runtime");
14
14
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
15
15
  var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
16
+ var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
16
17
  var _reactFocusLock = _interopRequireDefault(require("react-focus-lock"));
17
18
  var _reactScrolllock = _interopRequireWildcard(require("react-scrolllock"));
18
19
  var _usePlatformLeafEventHandler = require("@atlaskit/analytics-next/usePlatformLeafEventHandler");
19
20
  var _blanket = _interopRequireDefault(require("@atlaskit/blanket/blanket"));
21
+ var _mergeRefs = _interopRequireDefault(require("@atlaskit/ds-lib/merge-refs"));
20
22
  var _noop = _interopRequireDefault(require("@atlaskit/ds-lib/noop"));
21
23
  var _useAutoFocus = _interopRequireDefault(require("@atlaskit/ds-lib/use-auto-focus"));
22
24
  var _useId = require("@atlaskit/ds-lib/use-id");
@@ -42,9 +44,9 @@ var _textSelection = require("../pragmatic-drag-and-drop/disable-dragging-to-cro
42
44
  var _scrollContext = require("../scroll-context");
43
45
  var _width = require("../width");
44
46
  var _modalDialog = _interopRequireDefault(require("./modal-dialog"));
45
- 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" != _typeof3(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); }
46
- // eslint-disable-next-line @atlaskit/design-system/no-third-party-focus-traps -- existing usage from before this rule was added
47
+ var _excluded = ["forwardedRef"]; // eslint-disable-next-line @atlaskit/design-system/no-third-party-focus-traps -- existing usage from before this rule was added
47
48
  // eslint-disable-next-line @atlaskit/ui-styling-standard/no-atlaskit-theme
49
+ 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" != _typeof3(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); }
48
50
  var fillScreenStyles = null;
49
51
 
50
52
  /**
@@ -106,7 +108,7 @@ function useModalCloseHandler(providedOnClose) {
106
108
  action: 'closed',
107
109
  componentName: 'modalDialog',
108
110
  packageName: "@atlaskit/modal-dialog",
109
- packageVersion: "17.2.4"
111
+ packageVersion: "17.2.5"
110
112
  });
111
113
  }
112
114
  function getScrollMode(_ref) {
@@ -198,7 +200,9 @@ function getDismissedBy(_ref2) {
198
200
  * Every hook here runs unconditionally: this component only mounts on the
199
201
  * top-layer path, so it never shares a hook sequence with the legacy path.
200
202
  */
201
- function ModalWrapperTopLayer(props) {
203
+ function ModalWrapperTopLayer(_ref3) {
204
+ var forwardedRef = _ref3.forwardedRef,
205
+ props = (0, _objectWithoutProperties2.default)(_ref3, _excluded);
202
206
  var autoFocus = props.autoFocus,
203
207
  UNSAFE__disableInitialAutoFocus = props.UNSAFE__disableInitialAutoFocus,
204
208
  _props$shouldCloseOnE = props.shouldCloseOnEscapePress,
@@ -261,8 +265,8 @@ function ModalWrapperTopLayer(props) {
261
265
 
262
266
  // Pass a synthetic event to satisfy the KeyboardOrMouseEvent contract. Dialog calls this
263
267
  // for an allowed Escape or backdrop click.
264
- var onDialogClose = (0, _react.useCallback)(function (_ref3) {
265
- var reason = _ref3.reason;
268
+ var onDialogClose = (0, _react.useCallback)(function (_ref4) {
269
+ var reason = _ref4.reason;
266
270
  onCloseHandler((0, _createCloseEvent.createCloseEvent)({
267
271
  reason: reason
268
272
  }));
@@ -272,8 +276,8 @@ function ModalWrapperTopLayer(props) {
272
276
  * Dialog asks on an allowed Escape or backdrop click. Ignoring an Escape ask refuses it:
273
277
  * Dialog still cancels the Escape `keydown`, so nothing else closes.
274
278
  */
275
- var onDialogAsk = (0, _react.useCallback)(function (_ref4) {
276
- var reason = _ref4.reason;
279
+ var onDialogAsk = (0, _react.useCallback)(function (_ref5) {
280
+ var reason = _ref5.reason;
277
281
  if (reason === 'escape' && !shouldCloseOnEscapePress) {
278
282
  return;
279
283
  }
@@ -338,8 +342,11 @@ function ModalWrapperTopLayer(props) {
338
342
  isFullScreen: isFullScreen,
339
343
  shouldScrollInViewport: shouldScrollInViewport
340
344
  });
341
- return /*#__PURE__*/React.createElement(_dialogContent.Dialog, (0, _extends2.default)({
342
- ref: dialogRef,
345
+ return /*#__PURE__*/React.createElement(_dialogContent.Dialog
346
+ // The consumer `ref` gets the native <dialog>. Like the legacy `section`, it has the dialog
347
+ // role, the accessible name and the test id, and it contains all the content.
348
+ , (0, _extends2.default)({
349
+ ref: (0, _mergeRefs.default)([dialogRef, forwardedRef]),
343
350
  onClose: onDialogAsk,
344
351
  dismissedBy: getDismissedBy({
345
352
  shouldCloseOnEscapePress: shouldCloseOnEscapePress,
@@ -512,13 +519,9 @@ var ModalWrapperLegacy = /*#__PURE__*/(0, _react.forwardRef)(function (props, re
512
519
  // (a clean remount) instead of changing the hook order of a mounted component.
513
520
  var InternalModalWrapper = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
514
521
  if ((0, _fg.fg)('platform-dst-top-layer')) {
515
- // TODO: the top-layer path does not forward the external `ref` (parity
516
- // with the pre-refactor behavior, where the top-layer branch never
517
- // consumed it). The public type still advertises `RefAttributes`, so a
518
- // consumer ref silently no-ops here. Follow up by forwarding `ref` to a
519
- // sensible element (for example the content `div`) once ref parity is
520
- // intentionally desired.
521
- return /*#__PURE__*/React.createElement(ModalWrapperTopLayer, props);
522
+ return /*#__PURE__*/React.createElement(ModalWrapperTopLayer, (0, _extends2.default)({}, props, {
523
+ forwardedRef: ref
524
+ }));
522
525
  }
523
526
  return /*#__PURE__*/React.createElement(ModalWrapperLegacy, (0, _extends2.default)({
524
527
  ref: ref
@@ -9,6 +9,7 @@ import FocusLock from 'react-focus-lock';
9
9
  import ScrollLock, { TouchScrollable } from 'react-scrolllock';
10
10
  import { usePlatformLeafEventHandler } from '@atlaskit/analytics-next/usePlatformLeafEventHandler';
11
11
  import Blanket from '@atlaskit/blanket/blanket';
12
+ import mergeRefs from '@atlaskit/ds-lib/merge-refs';
12
13
  import noop from '@atlaskit/ds-lib/noop';
13
14
  import useAutoFocus from '@atlaskit/ds-lib/use-auto-focus';
14
15
  import { useId } from '@atlaskit/ds-lib/use-id';
@@ -96,7 +97,7 @@ function useModalCloseHandler(providedOnClose) {
96
97
  action: 'closed',
97
98
  componentName: 'modalDialog',
98
99
  packageName: "@atlaskit/modal-dialog",
99
- packageVersion: "17.2.4"
100
+ packageVersion: "17.2.5"
100
101
  });
101
102
  }
102
103
  function getScrollMode({
@@ -190,7 +191,10 @@ function getDismissedBy({
190
191
  * Every hook here runs unconditionally: this component only mounts on the
191
192
  * top-layer path, so it never shares a hook sequence with the legacy path.
192
193
  */
193
- function ModalWrapperTopLayer(props) {
194
+ function ModalWrapperTopLayer({
195
+ forwardedRef,
196
+ ...props
197
+ }) {
194
198
  const {
195
199
  autoFocus,
196
200
  UNSAFE__disableInitialAutoFocus,
@@ -326,8 +330,11 @@ function ModalWrapperTopLayer(props) {
326
330
  isFullScreen,
327
331
  shouldScrollInViewport
328
332
  });
329
- return /*#__PURE__*/React.createElement(Dialog, _extends({
330
- ref: dialogRef,
333
+ return /*#__PURE__*/React.createElement(Dialog
334
+ // The consumer `ref` gets the native <dialog>. Like the legacy `section`, it has the dialog
335
+ // role, the accessible name and the test id, and it contains all the content.
336
+ , _extends({
337
+ ref: mergeRefs([dialogRef, forwardedRef]),
331
338
  onClose: onDialogAsk,
332
339
  dismissedBy: getDismissedBy({
333
340
  shouldCloseOnEscapePress,
@@ -491,13 +498,9 @@ const ModalWrapperLegacy = /*#__PURE__*/forwardRef((props, ref) => {
491
498
  // (a clean remount) instead of changing the hook order of a mounted component.
492
499
  const InternalModalWrapper = /*#__PURE__*/forwardRef((props, ref) => {
493
500
  if (fg('platform-dst-top-layer')) {
494
- // TODO: the top-layer path does not forward the external `ref` (parity
495
- // with the pre-refactor behavior, where the top-layer branch never
496
- // consumed it). The public type still advertises `RefAttributes`, so a
497
- // consumer ref silently no-ops here. Follow up by forwarding `ref` to a
498
- // sensible element (for example the content `div`) once ref parity is
499
- // intentionally desired.
500
- return /*#__PURE__*/React.createElement(ModalWrapperTopLayer, props);
501
+ return /*#__PURE__*/React.createElement(ModalWrapperTopLayer, _extends({}, props, {
502
+ forwardedRef: ref
503
+ }));
501
504
  }
502
505
  return /*#__PURE__*/React.createElement(ModalWrapperLegacy, _extends({
503
506
  ref: ref
@@ -1,6 +1,8 @@
1
1
  /* modal-wrapper.tsx generated by @compiled/babel-plugin v3.0.4 */
2
2
  import _extends from "@babel/runtime/helpers/extends";
3
3
  import _typeof from "@babel/runtime/helpers/typeof";
4
+ import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
5
+ var _excluded = ["forwardedRef"];
4
6
  import "./modal-wrapper.compiled.css";
5
7
  import * as React from 'react';
6
8
  import { ax, ix } from "@compiled/react/runtime";
@@ -10,6 +12,7 @@ import FocusLock from 'react-focus-lock';
10
12
  import ScrollLock, { TouchScrollable } from 'react-scrolllock';
11
13
  import { usePlatformLeafEventHandler } from '@atlaskit/analytics-next/usePlatformLeafEventHandler';
12
14
  import Blanket from '@atlaskit/blanket/blanket';
15
+ import mergeRefs from '@atlaskit/ds-lib/merge-refs';
13
16
  import noop from '@atlaskit/ds-lib/noop';
14
17
  import useAutoFocus from '@atlaskit/ds-lib/use-auto-focus';
15
18
  import { useId } from '@atlaskit/ds-lib/use-id';
@@ -97,7 +100,7 @@ function useModalCloseHandler(providedOnClose) {
97
100
  action: 'closed',
98
101
  componentName: 'modalDialog',
99
102
  packageName: "@atlaskit/modal-dialog",
100
- packageVersion: "17.2.4"
103
+ packageVersion: "17.2.5"
101
104
  });
102
105
  }
103
106
  function getScrollMode(_ref) {
@@ -189,7 +192,9 @@ function getDismissedBy(_ref2) {
189
192
  * Every hook here runs unconditionally: this component only mounts on the
190
193
  * top-layer path, so it never shares a hook sequence with the legacy path.
191
194
  */
192
- function ModalWrapperTopLayer(props) {
195
+ function ModalWrapperTopLayer(_ref3) {
196
+ var forwardedRef = _ref3.forwardedRef,
197
+ props = _objectWithoutProperties(_ref3, _excluded);
193
198
  var autoFocus = props.autoFocus,
194
199
  UNSAFE__disableInitialAutoFocus = props.UNSAFE__disableInitialAutoFocus,
195
200
  _props$shouldCloseOnE = props.shouldCloseOnEscapePress,
@@ -252,8 +257,8 @@ function ModalWrapperTopLayer(props) {
252
257
 
253
258
  // Pass a synthetic event to satisfy the KeyboardOrMouseEvent contract. Dialog calls this
254
259
  // for an allowed Escape or backdrop click.
255
- var onDialogClose = useCallback(function (_ref3) {
256
- var reason = _ref3.reason;
260
+ var onDialogClose = useCallback(function (_ref4) {
261
+ var reason = _ref4.reason;
257
262
  onCloseHandler(createCloseEvent({
258
263
  reason: reason
259
264
  }));
@@ -263,8 +268,8 @@ function ModalWrapperTopLayer(props) {
263
268
  * Dialog asks on an allowed Escape or backdrop click. Ignoring an Escape ask refuses it:
264
269
  * Dialog still cancels the Escape `keydown`, so nothing else closes.
265
270
  */
266
- var onDialogAsk = useCallback(function (_ref4) {
267
- var reason = _ref4.reason;
271
+ var onDialogAsk = useCallback(function (_ref5) {
272
+ var reason = _ref5.reason;
268
273
  if (reason === 'escape' && !shouldCloseOnEscapePress) {
269
274
  return;
270
275
  }
@@ -329,8 +334,11 @@ function ModalWrapperTopLayer(props) {
329
334
  isFullScreen: isFullScreen,
330
335
  shouldScrollInViewport: shouldScrollInViewport
331
336
  });
332
- return /*#__PURE__*/React.createElement(Dialog, _extends({
333
- ref: dialogRef,
337
+ return /*#__PURE__*/React.createElement(Dialog
338
+ // The consumer `ref` gets the native <dialog>. Like the legacy `section`, it has the dialog
339
+ // role, the accessible name and the test id, and it contains all the content.
340
+ , _extends({
341
+ ref: mergeRefs([dialogRef, forwardedRef]),
334
342
  onClose: onDialogAsk,
335
343
  dismissedBy: getDismissedBy({
336
344
  shouldCloseOnEscapePress: shouldCloseOnEscapePress,
@@ -503,13 +511,9 @@ var ModalWrapperLegacy = /*#__PURE__*/forwardRef(function (props, ref) {
503
511
  // (a clean remount) instead of changing the hook order of a mounted component.
504
512
  var InternalModalWrapper = /*#__PURE__*/forwardRef(function (props, ref) {
505
513
  if (fg('platform-dst-top-layer')) {
506
- // TODO: the top-layer path does not forward the external `ref` (parity
507
- // with the pre-refactor behavior, where the top-layer branch never
508
- // consumed it). The public type still advertises `RefAttributes`, so a
509
- // consumer ref silently no-ops here. Follow up by forwarding `ref` to a
510
- // sensible element (for example the content `div`) once ref parity is
511
- // intentionally desired.
512
- return /*#__PURE__*/React.createElement(ModalWrapperTopLayer, props);
514
+ return /*#__PURE__*/React.createElement(ModalWrapperTopLayer, _extends({}, props, {
515
+ forwardedRef: ref
516
+ }));
513
517
  }
514
518
  return /*#__PURE__*/React.createElement(ModalWrapperLegacy, _extends({
515
519
  ref: ref
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/modal-dialog",
3
- "version": "17.2.5",
3
+ "version": "17.2.6",
4
4
  "description": "A modal dialog displays content that requires user interaction, in a layer above the page.",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -52,7 +52,7 @@
52
52
  "@atlaskit/react-compiler-gating": "^0.2.0",
53
53
  "@atlaskit/theme": "^28.2.0",
54
54
  "@atlaskit/tokens": "^20.12.0",
55
- "@atlaskit/top-layer": "^8.0.0",
55
+ "@atlaskit/top-layer": "^8.1.0",
56
56
  "@babel/runtime": "^7.0.0",
57
57
  "@compiled/react": "^1.0.2",
58
58
  "bind-event-listener": "^3.0.0",
@@ -74,7 +74,7 @@
74
74
  "@atlaskit/checkbox": "^19.3.0",
75
75
  "@atlaskit/code": "^20.0.0",
76
76
  "@atlaskit/codemod-utils": "^5.2.0",
77
- "@atlaskit/datetime-picker": "^19.4.0",
77
+ "@atlaskit/datetime-picker": "^19.5.0",
78
78
  "@atlaskit/docs": "^12.3.0",
79
79
  "@atlaskit/dropdown-menu": "^21.3.0",
80
80
  "@atlaskit/flag": "^19.0.0",
@@ -88,7 +88,7 @@
88
88
  "@atlaskit/spotlight": "^4.2.0",
89
89
  "@atlaskit/textfield": "^10.3.0",
90
90
  "@atlaskit/tooltip": "^24.4.0",
91
- "@atlassian/feature-flags-test-utils": "^1.3.0",
91
+ "@atlassian/feature-flags-test-utils": "^2.0.0",
92
92
  "@atlassian/ssr-tests": "workspace:^",
93
93
  "@atlassian/structured-docs-types": "workspace:^",
94
94
  "@atlassian/testing-library": "^0.12.0",