@atlaskit/drawer 13.1.1 → 13.3.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 +24 -0
- package/__tests__/playwright/top-layer-focus.spec.tsx +148 -0
- package/compass.yml +38 -0
- package/dist/cjs/drawer-panel/drawer-content.js +11 -2
- package/dist/cjs/drawer-panel/drawer-top-layer.compiled.css +34 -0
- package/dist/cjs/drawer-panel/drawer-top-layer.js +271 -0
- package/dist/cjs/drawer-panel/hooks/use-prevent-programmatic-scroll.js +6 -0
- package/dist/cjs/drawer.js +25 -14
- package/dist/cjs/use-drawer-stack.js +88 -0
- package/dist/es2019/drawer-panel/drawer-content.js +11 -2
- package/dist/es2019/drawer-panel/drawer-top-layer.compiled.css +34 -0
- package/dist/es2019/drawer-panel/drawer-top-layer.js +255 -0
- package/dist/es2019/drawer-panel/hooks/use-prevent-programmatic-scroll.js +6 -0
- package/dist/es2019/drawer.js +25 -14
- package/dist/es2019/use-drawer-stack.js +75 -0
- package/dist/esm/drawer-panel/drawer-content.js +11 -2
- package/dist/esm/drawer-panel/drawer-top-layer.compiled.css +34 -0
- package/dist/esm/drawer-panel/drawer-top-layer.js +262 -0
- package/dist/esm/drawer-panel/hooks/use-prevent-programmatic-scroll.js +6 -0
- package/dist/esm/drawer.js +25 -14
- package/dist/esm/use-drawer-stack.js +82 -0
- package/dist/types/drawer-panel/drawer-top-layer.d.ts +24 -0
- package/dist/types/drawer.d.ts +1 -1
- package/dist/types/use-drawer-stack.d.ts +17 -0
- package/drawer.docs.tsx +4 -4
- package/package.json +15 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
# @atlaskit/drawer
|
|
2
2
|
|
|
3
|
+
## 13.3.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [`530dfb5aee695`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/530dfb5aee695) -
|
|
8
|
+
Updates how animations are applied to Drawer when the `platform-dst-top-layer` feature gate is
|
|
9
|
+
enabled.
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Updated dependencies
|
|
14
|
+
|
|
15
|
+
## 13.2.0
|
|
16
|
+
|
|
17
|
+
### Minor Changes
|
|
18
|
+
|
|
19
|
+
- [`e297058763bc0`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/e297058763bc0) -
|
|
20
|
+
Add a top-layer rendering path for `Drawer` behind the `platform-dst-top-layer` feature gate. Some
|
|
21
|
+
focus-management and labelling props behave slightly differently on the native dialog path.
|
|
22
|
+
|
|
23
|
+
### Patch Changes
|
|
24
|
+
|
|
25
|
+
- Updated dependencies
|
|
26
|
+
|
|
3
27
|
## 13.1.1
|
|
4
28
|
|
|
5
29
|
### Patch Changes
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { expect, test } from '@af/integration-testing';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Drawer: focus contract on the top-layer code path.
|
|
5
|
+
*
|
|
6
|
+
* The top-layer `Drawer` renders as a native modal `<dialog>` (via the
|
|
7
|
+
* `@atlaskit/top-layer` `Dialog` primitive). Per WCAG 2.4.3 (Focus Order) and
|
|
8
|
+
* the top-layer focus rules:
|
|
9
|
+
*
|
|
10
|
+
* 1. Initial focus moves to the first focusable element on open (or to the
|
|
11
|
+
* element marked with the native HTML `autofocus` attribute when present).
|
|
12
|
+
* 2. Closing the drawer (Escape) restores focus to the trigger.
|
|
13
|
+
* 3. Tab / Shift+Tab cycle focus within the drawer (focus does not escape to
|
|
14
|
+
* elements behind the inert modal surface).
|
|
15
|
+
*
|
|
16
|
+
* `Drawer` has no `autoFocus` ref prop (unlike `ModalDialog`); its consumer
|
|
17
|
+
* focus override is `shouldReturnFocus`, exercised in the top-layer
|
|
18
|
+
* `drawer.spec.tsx`.
|
|
19
|
+
*
|
|
20
|
+
* See: `platform/packages/design-system/top-layer/notes/architecture/focus.md`.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
const featureFlag = 'platform-dst-top-layer';
|
|
24
|
+
|
|
25
|
+
test.describe('Drawer: top-layer focus contract', () => {
|
|
26
|
+
test('initial focus: focus moves to the first focusable element on open', async ({ page }) => {
|
|
27
|
+
await page.visitExample<typeof import('../../examples/98-testing-initial-focus-matrix.tsx')>(
|
|
28
|
+
'design-system',
|
|
29
|
+
'drawer',
|
|
30
|
+
'testing-initial-focus-matrix',
|
|
31
|
+
{ featureFlag },
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
await page.getByTestId('default-drawer-trigger').click();
|
|
35
|
+
|
|
36
|
+
const dialog = page.getByTestId('default-drawer');
|
|
37
|
+
await expect(dialog).toBeVisible();
|
|
38
|
+
|
|
39
|
+
// The first focusable inside the drawer is the sidebar close button.
|
|
40
|
+
await expect(page.getByTestId('DrawerCloseButton')).toBeFocused();
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test('focus restoration: Escape restores focus to the trigger', async ({ page }) => {
|
|
44
|
+
await page.visitExample<typeof import('../../examples/98-testing-initial-focus-matrix.tsx')>(
|
|
45
|
+
'design-system',
|
|
46
|
+
'drawer',
|
|
47
|
+
'testing-initial-focus-matrix',
|
|
48
|
+
{ featureFlag },
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
const trigger = page.getByTestId('default-drawer-trigger');
|
|
52
|
+
await trigger.click();
|
|
53
|
+
await expect(page.getByTestId('default-drawer')).toBeVisible();
|
|
54
|
+
|
|
55
|
+
await page.keyboard.press('Escape');
|
|
56
|
+
await expect(page.getByTestId('default-drawer')).toBeHidden();
|
|
57
|
+
await expect(trigger).toBeFocused();
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
// WCAG 2.4.3 Focus Order + HTML `<dialog>` focusing steps
|
|
61
|
+
// (https://html.spec.whatwg.org/multipage/interactive-elements.html#dialog-focusing-steps).
|
|
62
|
+
// When a descendant of the dialog carries the native HTML `autofocus`
|
|
63
|
+
// attribute, focus must land on that element instead of the first
|
|
64
|
+
// focusable. This matches both `<dialog>.showModal()` and the WAI-ARIA APG
|
|
65
|
+
// Dialog pattern.
|
|
66
|
+
test('initial focus: native [autofocus] element wins over the first focusable element', async ({
|
|
67
|
+
page,
|
|
68
|
+
}) => {
|
|
69
|
+
await page.visitExample<typeof import('../../examples/98-testing-initial-focus-matrix.tsx')>(
|
|
70
|
+
'design-system',
|
|
71
|
+
'drawer',
|
|
72
|
+
'testing-initial-focus-matrix',
|
|
73
|
+
{ featureFlag },
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
await page.getByTestId('native-autofocus-drawer-trigger').click();
|
|
77
|
+
|
|
78
|
+
const dialog = page.getByTestId('native-autofocus-drawer');
|
|
79
|
+
await expect(dialog).toBeVisible();
|
|
80
|
+
|
|
81
|
+
// The first focusable inside the drawer is the sidebar close button, but
|
|
82
|
+
// the body input carries `autofocus`, so focus must land on the input.
|
|
83
|
+
await expect(page.getByTestId('native-autofocus-input')).toBeFocused();
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
test('focus movement: Tab cycles focus forward within the drawer', async ({ page }) => {
|
|
87
|
+
await page.visitExample<typeof import('../../examples/98-testing-initial-focus-matrix.tsx')>(
|
|
88
|
+
'design-system',
|
|
89
|
+
'drawer',
|
|
90
|
+
'testing-initial-focus-matrix',
|
|
91
|
+
{ featureFlag },
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
await page.getByTestId('multi-focusable-drawer-trigger').click();
|
|
95
|
+
const dialog = page.getByTestId('multi-focusable-drawer');
|
|
96
|
+
await expect(dialog).toBeVisible();
|
|
97
|
+
|
|
98
|
+
// Walk forward through every focusable element in the drawer and verify
|
|
99
|
+
// focus never escapes the dialog surface.
|
|
100
|
+
const focusables = [
|
|
101
|
+
page.getByTestId('DrawerCloseButton'),
|
|
102
|
+
page.getByTestId('focusable-1'),
|
|
103
|
+
page.getByTestId('focusable-2'),
|
|
104
|
+
page.getByTestId('focusable-3'),
|
|
105
|
+
];
|
|
106
|
+
|
|
107
|
+
for (const target of focusables) {
|
|
108
|
+
await expect(target).toBeFocused();
|
|
109
|
+
await page.keyboard.press('Tab');
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// After cycling past the last focusable, focus must remain inside the
|
|
113
|
+
// drawer (focus wrap), never on a node behind it.
|
|
114
|
+
const activeWithinDialog = await dialog.evaluate(
|
|
115
|
+
(dialogElement) =>
|
|
116
|
+
document.activeElement !== null && dialogElement.contains(document.activeElement),
|
|
117
|
+
);
|
|
118
|
+
expect(activeWithinDialog).toBe(true);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
test('focus movement: Shift+Tab cycles focus backward within the drawer', async ({ page }) => {
|
|
122
|
+
await page.visitExample<typeof import('../../examples/98-testing-initial-focus-matrix.tsx')>(
|
|
123
|
+
'design-system',
|
|
124
|
+
'drawer',
|
|
125
|
+
'testing-initial-focus-matrix',
|
|
126
|
+
{ featureFlag },
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
await page.getByTestId('multi-focusable-drawer-trigger').click();
|
|
130
|
+
const dialog = page.getByTestId('multi-focusable-drawer');
|
|
131
|
+
await expect(dialog).toBeVisible();
|
|
132
|
+
await expect(page.getByTestId('DrawerCloseButton')).toBeFocused();
|
|
133
|
+
|
|
134
|
+
// From the first focusable, Shift+Tab wraps to the last, then walks back
|
|
135
|
+
// up. Focus stays trapped within the drawer throughout.
|
|
136
|
+
const backwardOrder = [
|
|
137
|
+
page.getByTestId('focusable-3'),
|
|
138
|
+
page.getByTestId('focusable-2'),
|
|
139
|
+
page.getByTestId('focusable-1'),
|
|
140
|
+
page.getByTestId('DrawerCloseButton'),
|
|
141
|
+
];
|
|
142
|
+
|
|
143
|
+
for (const target of backwardOrder) {
|
|
144
|
+
await page.keyboard.press('Shift+Tab');
|
|
145
|
+
await expect(target).toBeFocused();
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
});
|
package/compass.yml
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
configVersion: 1
|
|
2
|
+
id: ari:cloud:compass:a436116f-02ce-4520-8fbb-7301462a1674:component/c5751cc6-3513-4070-9deb-af31e86aed34/77224ba7-72d9-4d2b-a3f6-a78dcc8067ee
|
|
3
|
+
name: '@atlaskit/drawer'
|
|
4
|
+
ownerId: ari:cloud:identity::team/be19136e-6275-419f-be0c-fcee844b8684 # Design System Engineers
|
|
5
|
+
labels:
|
|
6
|
+
- platform-code
|
|
7
|
+
- platform-afm
|
|
8
|
+
typeId: OTHER
|
|
9
|
+
fields:
|
|
10
|
+
tier: 4
|
|
11
|
+
lifecycle: Active
|
|
12
|
+
isMonorepoProject: true
|
|
13
|
+
links:
|
|
14
|
+
- name: Root Repository
|
|
15
|
+
type: REPOSITORY
|
|
16
|
+
url: https://bitbucket.org/atlassian/atlassian-frontend-monorepo/src/master
|
|
17
|
+
- name: Slack Channel
|
|
18
|
+
type: CHAT_CHANNEL
|
|
19
|
+
url: https://atlassian.enterprise.slack.com/archives/CFJ9DU39U # #help-design-system
|
|
20
|
+
- name: Drawer
|
|
21
|
+
type: REPOSITORY
|
|
22
|
+
url: https://bitbucket.org/atlassian/atlassian-frontend-monorepo/src/master/platform/packages/design-system/drawer
|
|
23
|
+
customFields:
|
|
24
|
+
- name: Department
|
|
25
|
+
type: text
|
|
26
|
+
value: Eng - Design System Fundamentals
|
|
27
|
+
- name: Technical Owner
|
|
28
|
+
type: user
|
|
29
|
+
value: ari:cloud:identity::user/557058:86a9b692-7997-49cb-9984-080801b1de91 # Jared Crowe
|
|
30
|
+
- name: Required Reviewers Opt In
|
|
31
|
+
type: boolean
|
|
32
|
+
value: true
|
|
33
|
+
- name: Reviewer Selection Mechanism
|
|
34
|
+
type: text
|
|
35
|
+
value: random(3)
|
|
36
|
+
- name: Required Reviewer Approvals
|
|
37
|
+
type: number
|
|
38
|
+
value: 1
|
|
@@ -14,6 +14,7 @@ var _runtime = require("@compiled/react/runtime");
|
|
|
14
14
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
15
15
|
var _reactScrolllock = _interopRequireDefault(require("react-scrolllock"));
|
|
16
16
|
var _useCallbackRef = require("use-callback-ref");
|
|
17
|
+
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
17
18
|
var _useEnsureIsInsideDrawer = require("../use-ensure-is-inside-drawer");
|
|
18
19
|
var _usePreventProgrammaticScroll = _interopRequireDefault(require("./hooks/use-prevent-programmatic-scroll"));
|
|
19
20
|
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); }
|
|
@@ -60,8 +61,16 @@ var DrawerContent = exports.DrawerContent = function DrawerContent(_ref2) {
|
|
|
60
61
|
xcss = _ref2.xcss;
|
|
61
62
|
(0, _useEnsureIsInsideDrawer.useEnsureIsInsideDrawer)();
|
|
62
63
|
(0, _usePreventProgrammaticScroll.default)();
|
|
63
|
-
|
|
64
|
+
var content = /*#__PURE__*/React.createElement(DrawerContentBase, {
|
|
64
65
|
scrollContentLabel: scrollContentLabel,
|
|
65
66
|
xcss: xcss
|
|
66
|
-
}, children)
|
|
67
|
+
}, children);
|
|
68
|
+
|
|
69
|
+
// Under the top-layer flag, background scroll is handled by `DialogScrollLock`
|
|
70
|
+
// (rendered by `DrawerTopLayer`), so we skip `react-scrolllock` here to avoid
|
|
71
|
+
// double-locking the body. See the top-layer migration scroll decision.
|
|
72
|
+
if ((0, _platformFeatureFlags.fg)('platform-dst-top-layer')) {
|
|
73
|
+
return content;
|
|
74
|
+
}
|
|
75
|
+
return /*#__PURE__*/React.createElement(_reactScrolllock.default, null, content);
|
|
67
76
|
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
._13ku1fu8::-ms-backdrop{transition-timing-function:cubic-bezier(.15,1,.3,1)}
|
|
2
|
+
._13ku1fu8::backdrop{transition-timing-function:cubic-bezier(.15,1,.3,1)}
|
|
3
|
+
._18m915vq{overflow-y:hidden}
|
|
4
|
+
._1bsb1osq{width:100%}
|
|
5
|
+
._1e0c1txw{display:flex}
|
|
6
|
+
._1fsl1yx9[open]{transition-duration:.1s}
|
|
7
|
+
._1fyf1a5r::-ms-backdrop{transition-behavior:allow-discrete}
|
|
8
|
+
._1fyf1a5r::backdrop{transition-behavior:allow-discrete}
|
|
9
|
+
._1kdeglyw[open]{transform:none}
|
|
10
|
+
._1ltk1j28::-ms-backdrop{background-color:transparent}
|
|
11
|
+
._1ltk1j28::backdrop{background-color:transparent}
|
|
12
|
+
._1oec14ed{transition-duration:50ms}
|
|
13
|
+
._1q1l1bhr{--ds-elevation-surface-current:var(--ds-surface-overlay,#fff)}
|
|
14
|
+
._1reo15vq{overflow-x:hidden}
|
|
15
|
+
._1s9z1a5r{transition-behavior:allow-discrete}
|
|
16
|
+
._4t3i1osq{height:100%}
|
|
17
|
+
._4v7ipwmj[open]::-ms-backdrop{transition-duration:.7s}
|
|
18
|
+
._4v7ipwmj[open]::backdrop{transition-duration:.7s}
|
|
19
|
+
._6fl4dkwg{transition-timing-function:cubic-bezier(.2,0,0,1)}
|
|
20
|
+
._bfhk1bhr{background-color:var(--ds-surface-overlay,#fff)}
|
|
21
|
+
._d7fr1i5c[open]::-ms-backdrop{background-color:var(--ds-blanket,#050c1f75)}
|
|
22
|
+
._d7fr1i5c[open]::backdrop{background-color:var(--ds-blanket,#050c1f75)}
|
|
23
|
+
._ect4ttxp{font-family:var(--ds-font-family-body,"Atlassian Sans",ui-sans-serif,-apple-system,BlinkMacSystemFont,"Segoe UI",Ubuntu,"Helvetica Neue",sans-serif)}
|
|
24
|
+
._k8m05ji5{transition-property:transform,overlay,display}
|
|
25
|
+
._njwkivc9::-ms-backdrop{-ms-transition-property:background-color,overlay,display;transition-property:background-color,overlay,display}
|
|
26
|
+
._njwkivc9::backdrop{transition-property:background-color,overlay,display}
|
|
27
|
+
._t9ec3k1b{transform:translateY(100%)}
|
|
28
|
+
._t9ecjq3t{transform:translateX(-100%)}
|
|
29
|
+
._t9ecxwn4{transform:translateX(100%)}
|
|
30
|
+
._t9ecz6y5{transform:translateY(-100%)}
|
|
31
|
+
._yhpq1ttt::-ms-backdrop{transition-duration:.35s}
|
|
32
|
+
._yhpq1ttt::backdrop{transition-duration:.35s}
|
|
33
|
+
@media (prefers-reduced-motion:reduce){._156yru3m{transition-duration:0s}._aeldru3m[open]{transition-duration:0s}._1sbqru3m::-ms-backdrop{transition-duration:0s}._1sbqru3m::backdrop{transition-duration:0s}._1i6zru3m[open]::-ms-backdrop{transition-duration:0s}._1i6zru3m[open]::backdrop{transition-duration:0s}}
|
|
34
|
+
@starting-style{._1dar1j28[open]::-ms-backdrop{background-color:transparent}._1dar1j28[open]::backdrop{background-color:transparent}._1hqt3k1b[open]{transform:translateY(100%)}._1hqtjq3t[open]{transform:translateX(-100%)}._1hqtxwn4[open]{transform:translateX(100%)}._1hqtz6y5[open]{transform:translateY(-100%)}}
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
/* drawer-top-layer.tsx generated by @compiled/babel-plugin v0.39.1 */
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
5
|
+
var _typeof3 = require("@babel/runtime/helpers/typeof");
|
|
6
|
+
Object.defineProperty(exports, "__esModule", {
|
|
7
|
+
value: true
|
|
8
|
+
});
|
|
9
|
+
exports.DrawerTopLayer = DrawerTopLayer;
|
|
10
|
+
require("./drawer-top-layer.compiled.css");
|
|
11
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
12
|
+
var React = _react;
|
|
13
|
+
var _runtime = require("@compiled/react/runtime");
|
|
14
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
15
|
+
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
16
|
+
var _react2 = require("@compiled/react");
|
|
17
|
+
var _bindEventListener = require("bind-event-listener");
|
|
18
|
+
var _usePlatformLeafEventHandler = require("@atlaskit/analytics-next/usePlatformLeafEventHandler");
|
|
19
|
+
var _dialog = require("@atlaskit/top-layer/dialog");
|
|
20
|
+
var _dialogScrollLock = require("@atlaskit/top-layer/dialog-scroll-lock");
|
|
21
|
+
var _ensureIsInsideDrawerContext = require("../ensure-is-inside-drawer-context");
|
|
22
|
+
var _onCloseContext = require("../on-close-context");
|
|
23
|
+
var _useDrawerStack = _interopRequireDefault(require("../use-drawer-stack"));
|
|
24
|
+
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); }
|
|
25
|
+
var LOCAL_CURRENT_SURFACE_CSS_VAR = '--ds-elevation-surface-current';
|
|
26
|
+
|
|
27
|
+
// Legacy drawer panel uses `SlideIn duration="small"`, which resolves to
|
|
28
|
+
// 100ms on enter and 50ms on exit.
|
|
29
|
+
var slideEnterDurationMs = 100;
|
|
30
|
+
var slideExitDurationMs = 50;
|
|
31
|
+
|
|
32
|
+
// Legacy drawer blanket is a separate `FadeIn duration="large"`, which resolves
|
|
33
|
+
// to 700ms on enter and 350ms on exit. These intentionally differ from the panel
|
|
34
|
+
// slide timings to preserve the old visual behavior.
|
|
35
|
+
var fadeEnterDurationMs = 700;
|
|
36
|
+
var fadeExitDurationMs = 350;
|
|
37
|
+
var animate = {
|
|
38
|
+
kind: 'dialog',
|
|
39
|
+
name: 'custom'
|
|
40
|
+
};
|
|
41
|
+
var styles = {
|
|
42
|
+
root: "_k8m05ji5 _1oec14ed _6fl4dkwg _1s9z1a5r _1kdeglyw _1fsl1yx9 _1ltk1j28 _njwkivc9 _yhpq1ttt _13ku1fu8 _1fyf1a5r _d7fr1i5c _4v7ipwmj _1dar1j28 _156yru3m _aeldru3m _1sbqru3m _1i6zru3m",
|
|
43
|
+
surface: "_1reo15vq _18m915vq _1e0c1txw _1bsb1osq _4t3i1osq _bfhk1bhr _1q1l1bhr _ect4ttxp"
|
|
44
|
+
};
|
|
45
|
+
var drawerAnimationStyles = {
|
|
46
|
+
left: "_t9ecjq3t _1hqtjq3t",
|
|
47
|
+
right: "_t9ecxwn4 _1hqtxwn4",
|
|
48
|
+
top: "_t9ecz6y5 _1hqtz6y5",
|
|
49
|
+
bottom: "_t9ec3k1b _1hqt3k1b"
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
// Width presets mirror the legacy `DrawerPanel`. Applied to the `<dialog>` (the
|
|
53
|
+
// sized, edge-pinned element) and clamped to the viewport for mobile safety.
|
|
54
|
+
var WIDTH_MAP = {
|
|
55
|
+
narrow: '360px',
|
|
56
|
+
medium: '480px',
|
|
57
|
+
wide: '600px',
|
|
58
|
+
extended: '95vw',
|
|
59
|
+
full: '100vw'
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Resolve the native `<dialog>` accessible name props. Prefer the consumer's
|
|
64
|
+
* `label`, then their `titleId`. If neither is supplied (legacy allowed this),
|
|
65
|
+
* fall back to a generic name so the dialog is never unlabelled. Note:
|
|
66
|
+
* `@atlaskit/drawer` has no i18n setup, so this fallback is English only;
|
|
67
|
+
* consumers should pass a localised `label` or `titleId`.
|
|
68
|
+
*/
|
|
69
|
+
function getAccessibleName(_ref) {
|
|
70
|
+
var label = _ref.label,
|
|
71
|
+
titleId = _ref.titleId;
|
|
72
|
+
if (label) {
|
|
73
|
+
return {
|
|
74
|
+
label: label
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
if (titleId) {
|
|
78
|
+
return {
|
|
79
|
+
labelledBy: titleId
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
return {
|
|
83
|
+
label: 'Drawer'
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* **DrawerTopLayer**
|
|
89
|
+
*
|
|
90
|
+
* Top-layer (`platform-dst-top-layer`) implementation of `Drawer`. Renders a
|
|
91
|
+
* native `<dialog>` via `@atlaskit/top-layer`, replacing Portal, Blanket,
|
|
92
|
+
* react-focus-lock, react-scrolllock and `@atlaskit/layering` with native
|
|
93
|
+
* modality, `::backdrop`, focus trap and return, and `DialogScrollLock`.
|
|
94
|
+
*
|
|
95
|
+
* The `Dialog` primitive owns the entry and exit animation lifecycle (it keeps
|
|
96
|
+
* the host element mounted through the exit transition, then fires
|
|
97
|
+
* `onExitFinish`), so no `ExitingPersistence` wrapper is needed: the drawer
|
|
98
|
+
* renders `<Dialog isOpen={isOpen}>` directly. `useDrawerStack` tracks stack
|
|
99
|
+
* depth so only the foreground drawer shows a `::backdrop`.
|
|
100
|
+
*
|
|
101
|
+
* `isFocusLockEnabled` is intentionally unsupported: a native modal `<dialog>`
|
|
102
|
+
* always traps focus, so `isFocusLockEnabled={false}` is a no-op under this gate.
|
|
103
|
+
*/
|
|
104
|
+
function DrawerTopLayer(_ref2) {
|
|
105
|
+
var _ref2$width = _ref2.width,
|
|
106
|
+
width = _ref2$width === void 0 ? 'narrow' : _ref2$width,
|
|
107
|
+
isOpen = _ref2.isOpen,
|
|
108
|
+
_ref2$shouldReturnFoc = _ref2.shouldReturnFocus,
|
|
109
|
+
shouldReturnFocus = _ref2$shouldReturnFoc === void 0 ? true : _ref2$shouldReturnFoc,
|
|
110
|
+
onKeyDown = _ref2.onKeyDown,
|
|
111
|
+
testId = _ref2.testId,
|
|
112
|
+
children = _ref2.children,
|
|
113
|
+
onClose = _ref2.onClose,
|
|
114
|
+
onCloseComplete = _ref2.onCloseComplete,
|
|
115
|
+
onOpenComplete = _ref2.onOpenComplete,
|
|
116
|
+
label = _ref2.label,
|
|
117
|
+
titleId = _ref2.titleId,
|
|
118
|
+
_ref2$enterFrom = _ref2.enterFrom,
|
|
119
|
+
enterFrom = _ref2$enterFrom === void 0 ? 'left' : _ref2$enterFrom;
|
|
120
|
+
var stackIndex = (0, _useDrawerStack.default)({
|
|
121
|
+
isOpen: isOpen
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Points to the panel surface. Passed to `onOpenComplete` / `onCloseComplete`.
|
|
126
|
+
*/
|
|
127
|
+
var contentRef = (0, _react.useRef)(null);
|
|
128
|
+
// Cache the last content element so `onCloseComplete` still receives a node
|
|
129
|
+
// after children unmount (with reduced motion `contentRef` can clear before
|
|
130
|
+
// `onExitFinish` fires).
|
|
131
|
+
var lastContentElRef = (0, _react.useRef)(null);
|
|
132
|
+
// Callback ref runs at commit (not during render), so both refs stay
|
|
133
|
+
// populated without a render-time side effect. `lastContentElRef` only
|
|
134
|
+
// overwrites with a non-null node, preserving it across the unmount.
|
|
135
|
+
var setContentEl = (0, _react.useCallback)(function (el) {
|
|
136
|
+
contentRef.current = el;
|
|
137
|
+
if (el) {
|
|
138
|
+
lastContentElRef.current = el;
|
|
139
|
+
}
|
|
140
|
+
}, []);
|
|
141
|
+
|
|
142
|
+
// Analytics-wrapped close handlers, one per legacy trigger.
|
|
143
|
+
var handleEscapeClose = (0, _usePlatformLeafEventHandler.usePlatformLeafEventHandler)({
|
|
144
|
+
fn: function fn(evt, analyticsEvent) {
|
|
145
|
+
return onClose === null || onClose === void 0 ? void 0 : onClose(evt, analyticsEvent);
|
|
146
|
+
},
|
|
147
|
+
action: 'dismissed',
|
|
148
|
+
componentName: 'drawer',
|
|
149
|
+
packageName: "@atlaskit/drawer",
|
|
150
|
+
packageVersion: "13.2.0",
|
|
151
|
+
analyticsData: {
|
|
152
|
+
trigger: 'escKey'
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
var handleBlanketClose = (0, _usePlatformLeafEventHandler.usePlatformLeafEventHandler)({
|
|
156
|
+
fn: function fn(evt, analyticsEvent) {
|
|
157
|
+
return onClose === null || onClose === void 0 ? void 0 : onClose(evt, analyticsEvent);
|
|
158
|
+
},
|
|
159
|
+
action: 'dismissed',
|
|
160
|
+
componentName: 'drawer',
|
|
161
|
+
packageName: "@atlaskit/drawer",
|
|
162
|
+
packageVersion: "13.2.0",
|
|
163
|
+
analyticsData: {
|
|
164
|
+
trigger: 'blanket'
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
var handleBackButtonClose = (0, _usePlatformLeafEventHandler.usePlatformLeafEventHandler)({
|
|
168
|
+
fn: function fn(evt, analyticsEvent) {
|
|
169
|
+
return onClose === null || onClose === void 0 ? void 0 : onClose(evt, analyticsEvent);
|
|
170
|
+
},
|
|
171
|
+
action: 'dismissed',
|
|
172
|
+
componentName: 'drawer',
|
|
173
|
+
packageName: "@atlaskit/drawer",
|
|
174
|
+
packageVersion: "13.2.0",
|
|
175
|
+
analyticsData: {
|
|
176
|
+
trigger: 'backButton'
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
// Bridge the Dialog primitive's `onClose({ reason })` to the legacy
|
|
181
|
+
// `onClose(event, analyticsEvent)` contract via a synthetic event. Drawer
|
|
182
|
+
// has no `shouldCloseOn*` props, so both reasons always forward.
|
|
183
|
+
var handleDialogClose = (0, _react.useCallback)(function (_ref3) {
|
|
184
|
+
var reason = _ref3.reason;
|
|
185
|
+
var event = (0, _dialog.createCloseEvent)({
|
|
186
|
+
reason: reason
|
|
187
|
+
});
|
|
188
|
+
if (reason === 'escape') {
|
|
189
|
+
handleEscapeClose(event);
|
|
190
|
+
} else {
|
|
191
|
+
handleBlanketClose(event);
|
|
192
|
+
}
|
|
193
|
+
}, [handleEscapeClose, handleBlanketClose]);
|
|
194
|
+
|
|
195
|
+
// Mirror the legacy window `keydown` listener so `onKeyDown` still fires
|
|
196
|
+
// while the drawer is open.
|
|
197
|
+
var handleKeyDown = (0, _react.useCallback)(function (evt) {
|
|
198
|
+
onKeyDown === null || onKeyDown === void 0 || onKeyDown(evt);
|
|
199
|
+
}, [onKeyDown]);
|
|
200
|
+
(0, _react.useEffect)(function () {
|
|
201
|
+
if (!isOpen) {
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
return (0, _bindEventListener.bind)(window, {
|
|
205
|
+
type: 'keydown',
|
|
206
|
+
listener: handleKeyDown
|
|
207
|
+
});
|
|
208
|
+
}, [isOpen, handleKeyDown]);
|
|
209
|
+
|
|
210
|
+
// `onOpenComplete` once the entry animation settles (via `Dialog`'s
|
|
211
|
+
// `onEnterFinish`, which the underlying hook fires for animated,
|
|
212
|
+
// non-animated and reduced-motion paths).
|
|
213
|
+
var handleEnterFinish = (0, _react.useCallback)(function () {
|
|
214
|
+
onOpenComplete === null || onOpenComplete === void 0 || onOpenComplete(contentRef.current);
|
|
215
|
+
}, [onOpenComplete]);
|
|
216
|
+
|
|
217
|
+
// `onCloseComplete` once the exit animation settles (via `Dialog`'s
|
|
218
|
+
// `onExitFinish`). This is also where a custom `shouldReturnFocus={ref}` is
|
|
219
|
+
// honoured: native `<dialog>` restores focus to the trigger at the start of
|
|
220
|
+
// close, so the consumer's ref is focused now that the exit is done.
|
|
221
|
+
// `shouldReturnFocus={false}` is a documented best-effort limitation; native
|
|
222
|
+
// always restores focus to the trigger.
|
|
223
|
+
var handleExitFinish = (0, _react.useCallback)(function () {
|
|
224
|
+
var _contentRef$current;
|
|
225
|
+
onCloseComplete === null || onCloseComplete === void 0 || onCloseComplete((_contentRef$current = contentRef.current) !== null && _contentRef$current !== void 0 ? _contentRef$current : lastContentElRef.current);
|
|
226
|
+
lastContentElRef.current = null;
|
|
227
|
+
if ((0, _typeof2.default)(shouldReturnFocus) === 'object' && shouldReturnFocus !== null && shouldReturnFocus !== void 0 && shouldReturnFocus.current) {
|
|
228
|
+
shouldReturnFocus.current.focus();
|
|
229
|
+
}
|
|
230
|
+
}, [onCloseComplete, shouldReturnFocus]);
|
|
231
|
+
|
|
232
|
+
// Pin the `<dialog>` full-height to the inline-start edge (overriding the
|
|
233
|
+
// primitive's centred `margin: auto`); width from the preset, clamped to the
|
|
234
|
+
// viewport. `enterFrom` only drives the slide animation, not the pin edge;
|
|
235
|
+
// it matches the legacy panel, which always pins `inset-inline-start`.
|
|
236
|
+
var dialogStyle = {
|
|
237
|
+
margin: 0,
|
|
238
|
+
insetBlockStart: 0,
|
|
239
|
+
insetInlineStart: 0,
|
|
240
|
+
insetInlineEnd: 'auto',
|
|
241
|
+
height: '100dvh',
|
|
242
|
+
maxHeight: '100dvh',
|
|
243
|
+
width: "min(".concat(WIDTH_MAP[width], ", 100vw)")
|
|
244
|
+
};
|
|
245
|
+
var accessibleName = getAccessibleName({
|
|
246
|
+
label: label,
|
|
247
|
+
titleId: titleId
|
|
248
|
+
});
|
|
249
|
+
return /*#__PURE__*/React.createElement(_dialog.Dialog, (0, _extends2.default)({
|
|
250
|
+
isOpen: isOpen,
|
|
251
|
+
onClose: handleDialogClose,
|
|
252
|
+
onEnterFinish: handleEnterFinish,
|
|
253
|
+
onExitFinish: handleExitFinish,
|
|
254
|
+
animate: animate,
|
|
255
|
+
xcss: (0, _react2.cx)(styles.root, drawerAnimationStyles[enterFrom]),
|
|
256
|
+
shouldHideBackdrop: stackIndex > 0,
|
|
257
|
+
testId: testId
|
|
258
|
+
}, accessibleName, {
|
|
259
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop
|
|
260
|
+
style: dialogStyle
|
|
261
|
+
}), /*#__PURE__*/React.createElement(_dialogScrollLock.DialogScrollLock, {
|
|
262
|
+
isOpen: true
|
|
263
|
+
}), /*#__PURE__*/React.createElement("div", {
|
|
264
|
+
ref: setContentEl,
|
|
265
|
+
className: (0, _runtime.ax)([styles.surface])
|
|
266
|
+
}, /*#__PURE__*/React.createElement(_ensureIsInsideDrawerContext.EnsureIsInsideDrawerContext.Provider, {
|
|
267
|
+
value: true
|
|
268
|
+
}, /*#__PURE__*/React.createElement(_onCloseContext.OnCloseContext.Provider, {
|
|
269
|
+
value: handleBackButtonClose
|
|
270
|
+
}, children))));
|
|
271
|
+
}
|
|
@@ -8,6 +8,7 @@ exports.default = usePreventProgrammaticScroll;
|
|
|
8
8
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
9
9
|
var _react = require("react");
|
|
10
10
|
var _bindEventListener = require("bind-event-listener");
|
|
11
|
+
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
11
12
|
/**
|
|
12
13
|
* Returns how far the body is scrolled from the top of the viewport.
|
|
13
14
|
*
|
|
@@ -47,6 +48,11 @@ function usePreventProgrammaticScroll() {
|
|
|
47
48
|
}
|
|
48
49
|
}, [scrollTopOffset]);
|
|
49
50
|
(0, _react.useEffect)(function () {
|
|
51
|
+
// The top-layer drawer relies on native modality + `DialogScrollLock`; the
|
|
52
|
+
// programmatic-scroll guard is intentionally dropped under the flag.
|
|
53
|
+
if ((0, _platformFeatureFlags.fg)('platform-dst-top-layer')) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
50
56
|
return (0, _bindEventListener.bind)(window, {
|
|
51
57
|
type: 'scroll',
|
|
52
58
|
listener: onWindowScroll
|
package/dist/cjs/drawer.js
CHANGED
|
@@ -10,9 +10,11 @@ var _react = _interopRequireWildcard(require("react"));
|
|
|
10
10
|
var _exenv = require("exenv");
|
|
11
11
|
var _analyticsNext = require("@atlaskit/analytics-next");
|
|
12
12
|
var _layering = require("@atlaskit/layering");
|
|
13
|
+
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
13
14
|
var _portal = _interopRequireDefault(require("@atlaskit/portal"));
|
|
14
15
|
var _blanket = _interopRequireDefault(require("./blanket"));
|
|
15
16
|
var _drawerPanel = require("./drawer-panel/drawer-panel");
|
|
17
|
+
var _drawerTopLayer = require("./drawer-panel/drawer-top-layer");
|
|
16
18
|
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); }
|
|
17
19
|
/// <reference types="node" />
|
|
18
20
|
/* eslint-disable @repo/internal/dom-events/no-unsafe-event-listeners */
|
|
@@ -29,17 +31,7 @@ var EscapeCloseManager = function EscapeCloseManager(_ref) {
|
|
|
29
31
|
});
|
|
30
32
|
return /*#__PURE__*/_react.default.createElement("span", null);
|
|
31
33
|
};
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* __Drawer__
|
|
35
|
-
*
|
|
36
|
-
* A drawer is a panel that slides in from the left side of the screen.
|
|
37
|
-
*
|
|
38
|
-
* - [Examples](https://atlassian.design/components/drawer/examples)
|
|
39
|
-
* - [Code](https://atlassian.design/components/drawer/code)
|
|
40
|
-
* - [Usage](https://atlassian.design/components/drawer/usage)
|
|
41
|
-
*/
|
|
42
|
-
var Drawer = exports.Drawer = function Drawer(_ref2) {
|
|
34
|
+
var DrawerBase = function DrawerBase(_ref2) {
|
|
43
35
|
var _ref2$width = _ref2.width,
|
|
44
36
|
width = _ref2$width === void 0 ? 'narrow' : _ref2$width,
|
|
45
37
|
isOpen = _ref2.isOpen,
|
|
@@ -67,7 +59,7 @@ var Drawer = exports.Drawer = function Drawer(_ref2) {
|
|
|
67
59
|
action: 'dismissed',
|
|
68
60
|
componentName: 'drawer',
|
|
69
61
|
packageName: "@atlaskit/drawer",
|
|
70
|
-
packageVersion: "13.
|
|
62
|
+
packageVersion: "13.2.0",
|
|
71
63
|
analyticsData: {
|
|
72
64
|
trigger: 'escKey'
|
|
73
65
|
}
|
|
@@ -90,7 +82,7 @@ var Drawer = exports.Drawer = function Drawer(_ref2) {
|
|
|
90
82
|
action: 'dismissed',
|
|
91
83
|
componentName: 'drawer',
|
|
92
84
|
packageName: "@atlaskit/drawer",
|
|
93
|
-
packageVersion: "13.
|
|
85
|
+
packageVersion: "13.2.0",
|
|
94
86
|
analyticsData: {
|
|
95
87
|
trigger: 'blanket'
|
|
96
88
|
}
|
|
@@ -102,7 +94,7 @@ var Drawer = exports.Drawer = function Drawer(_ref2) {
|
|
|
102
94
|
action: 'dismissed',
|
|
103
95
|
componentName: 'drawer',
|
|
104
96
|
packageName: "@atlaskit/drawer",
|
|
105
|
-
packageVersion: "13.
|
|
97
|
+
packageVersion: "13.2.0",
|
|
106
98
|
analyticsData: {
|
|
107
99
|
trigger: 'backButton'
|
|
108
100
|
}
|
|
@@ -135,4 +127,23 @@ var Drawer = exports.Drawer = function Drawer(_ref2) {
|
|
|
135
127
|
}, children, /*#__PURE__*/_react.default.createElement(EscapeCloseManager, {
|
|
136
128
|
onClose: handleClose
|
|
137
129
|
})) : children));
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* __Drawer__
|
|
134
|
+
*
|
|
135
|
+
* A drawer is a panel that slides in from the left side of the screen.
|
|
136
|
+
*
|
|
137
|
+
* - [Examples](https://atlassian.design/components/drawer/examples)
|
|
138
|
+
* - [Code](https://atlassian.design/components/drawer/code)
|
|
139
|
+
* - [Usage](https://atlassian.design/components/drawer/usage)
|
|
140
|
+
*/
|
|
141
|
+
var Drawer = exports.Drawer = function Drawer(props) {
|
|
142
|
+
if ((0, _platformFeatureFlags.fg)('platform-dst-top-layer')) {
|
|
143
|
+
// eslint-disable-next-line @repo/internal/react/no-unsafe-spread-props -- internal implementation component takes the same DrawerProps
|
|
144
|
+
return /*#__PURE__*/_react.default.createElement(_drawerTopLayer.DrawerTopLayer, props);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// eslint-disable-next-line @repo/internal/react/no-unsafe-spread-props -- internal implementation component takes the same DrawerProps
|
|
148
|
+
return /*#__PURE__*/_react.default.createElement(DrawerBase, props);
|
|
138
149
|
};
|