@atlaskit/popup 4.25.0 → 4.26.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 +14 -0
- package/__tests__/playwright/top-layer-focus.spec.tsx +274 -0
- package/compositional/popup/package.json +1 -8
- package/compositional/popup-content/package.json +1 -8
- package/compositional/popup-trigger/package.json +1 -8
- package/dist/cjs/compositional/popup-content-top-layer.js +91 -6
- package/dist/cjs/internal/top-layer-bridge.js +14 -9
- package/dist/cjs/popup-top-layer.js +89 -5
- package/dist/es2019/compositional/popup-content-top-layer.js +92 -4
- package/dist/es2019/internal/top-layer-bridge.js +14 -9
- package/dist/es2019/popup-top-layer.js +90 -3
- package/dist/esm/compositional/popup-content-top-layer.js +92 -7
- package/dist/esm/internal/top-layer-bridge.js +14 -9
- package/dist/esm/popup-top-layer.js +90 -6
- package/dist/types/internal/top-layer-bridge.d.ts +14 -0
- package/experimental/package.json +1 -8
- package/package.json +2 -2
- package/popup/package.json +1 -8
- package/types/package.json +1 -8
- package/dist/types-ts4.5/compositional/id-context.d.ts +0 -2
- package/dist/types-ts4.5/compositional/is-inside-popup-context.d.ts +0 -11
- package/dist/types-ts4.5/compositional/is-open-context.d.ts +0 -11
- package/dist/types-ts4.5/compositional/popup-content-top-layer.d.ts +0 -20
- package/dist/types-ts4.5/compositional/popup-content.d.ts +0 -35
- package/dist/types-ts4.5/compositional/popup-trigger.d.ts +0 -13
- package/dist/types-ts4.5/compositional/popup.d.ts +0 -27
- package/dist/types-ts4.5/compositional/role-context.d.ts +0 -2
- package/dist/types-ts4.5/compositional/set-trigger-ref-context.d.ts +0 -2
- package/dist/types-ts4.5/compositional/trigger-ref-context.d.ts +0 -2
- package/dist/types-ts4.5/compositional/trigger-ref-object-context.d.ts +0 -10
- package/dist/types-ts4.5/compositional/use-ensure-is-inside-popup.d.ts +0 -1
- package/dist/types-ts4.5/entry-points/compositional-popup-content.d.ts +0 -2
- package/dist/types-ts4.5/entry-points/compositional-popup-trigger.d.ts +0 -2
- package/dist/types-ts4.5/entry-points/compositional-popup.d.ts +0 -2
- package/dist/types-ts4.5/entry-points/experimental/compositional.d.ts +0 -6
- package/dist/types-ts4.5/entry-points/popup.d.ts +0 -1
- package/dist/types-ts4.5/entry-points/types.d.ts +0 -1
- package/dist/types-ts4.5/index.d.ts +0 -4
- package/dist/types-ts4.5/internal/top-layer-bridge.d.ts +0 -29
- package/dist/types-ts4.5/popper-wrapper.d.ts +0 -3
- package/dist/types-ts4.5/popup-top-layer.d.ts +0 -16
- package/dist/types-ts4.5/popup.d.ts +0 -7
- package/dist/types-ts4.5/reposition-on-update.d.ts +0 -3
- package/dist/types-ts4.5/types.d.ts +0 -357
- package/dist/types-ts4.5/use-appearance.d.ts +0 -15
- package/dist/types-ts4.5/use-close-manager.d.ts +0 -2
- package/dist/types-ts4.5/use-focus-manager.d.ts +0 -2
- package/dist/types-ts4.5/use-get-memoized-merged-trigger-ref-new.d.ts +0 -9
- package/dist/types-ts4.5/use-get-memoized-merged-trigger-ref.d.ts +0 -3
- package/dist/types-ts4.5/utils/is-element-interactive.d.ts +0 -1
- package/dist/types-ts4.5/utils/use-animation-frame.d.ts +0 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @atlaskit/popup
|
|
2
2
|
|
|
3
|
+
## 4.26.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [`032135d12186b`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/032135d12186b) -
|
|
8
|
+
Top-layer: fix initial focus regressions on the top-layer adapters for `@atlaskit/avatar-group`
|
|
9
|
+
and `@atlaskit/popup`. Behind the `platform-dst-top-layer` feature gate.
|
|
10
|
+
|
|
11
|
+
## 4.25.1
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- Updated dependencies
|
|
16
|
+
|
|
3
17
|
## 4.25.0
|
|
4
18
|
|
|
5
19
|
### Minor Changes
|
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
import { expect, test } from '@af/integration-testing';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Popup: focus contract on the top-layer code path.
|
|
5
|
+
*
|
|
6
|
+
* `Popup` is a generic positioned overlay whose initial-focus behaviour
|
|
7
|
+
* depends on the `role` prop and the `autoFocus` prop. The tests in this
|
|
8
|
+
* spec exercise each branch of `top-layer/useInitialFocus` reachable
|
|
9
|
+
* through the public `Popup` API:
|
|
10
|
+
*
|
|
11
|
+
* - `role="dialog"`: focus moves to the first focusable inside the popup
|
|
12
|
+
* (default case), or to an element carrying the native HTML `autofocus`
|
|
13
|
+
* attribute when present.
|
|
14
|
+
* - no `role`: focus stays on the trigger; no focus movement is performed.
|
|
15
|
+
* - `role="listbox"`: focus prefers `[aria-selected="true"]` over the
|
|
16
|
+
* first option, except when the popup is owned by a combobox.
|
|
17
|
+
* - combobox carve-outs: focus stays on the combobox input when the popup
|
|
18
|
+
* is its owned listbox, whether the combobox is the trigger or rendered
|
|
19
|
+
* outside the popup element (react-select pattern).
|
|
20
|
+
* - `autoFocus={false}`: focus stays on the trigger regardless of role.
|
|
21
|
+
*
|
|
22
|
+
* Escape-to-restore and Tab cycling are also exercised for the default
|
|
23
|
+
* dialog case as representative top-layer focus-trap behaviour.
|
|
24
|
+
*
|
|
25
|
+
* See: `platform/packages/design-system/top-layer/notes/architecture/focus.md`.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
const featureFlag = 'platform-dst-top-layer';
|
|
29
|
+
|
|
30
|
+
test.describe('Popup: top-layer focus contract', () => {
|
|
31
|
+
test('initial focus: focus moves to first focusable on open', async ({ page }) => {
|
|
32
|
+
await page.visitExample<typeof import('../../examples/97-testing-initial-focus-matrix.tsx')>(
|
|
33
|
+
'design-system',
|
|
34
|
+
'popup',
|
|
35
|
+
'testing-initial-focus-matrix',
|
|
36
|
+
{ featureFlag },
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
await page.getByTestId('dialog-popup-trigger').click();
|
|
40
|
+
await expect(page.getByTestId('dialog-popup-content')).toBeVisible();
|
|
41
|
+
|
|
42
|
+
await expect(page.getByTestId('dialog-popup-first-button')).toBeFocused();
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
test('focus restoration: Escape restores focus to the trigger', async ({ page }) => {
|
|
46
|
+
await page.visitExample<typeof import('../../examples/97-testing-initial-focus-matrix.tsx')>(
|
|
47
|
+
'design-system',
|
|
48
|
+
'popup',
|
|
49
|
+
'testing-initial-focus-matrix',
|
|
50
|
+
{ featureFlag },
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
const trigger = page.getByTestId('dialog-popup-trigger');
|
|
54
|
+
await trigger.click();
|
|
55
|
+
await expect(page.getByTestId('dialog-popup-content')).toBeVisible();
|
|
56
|
+
|
|
57
|
+
await page.keyboard.press('Escape');
|
|
58
|
+
await expect(page.getByTestId('dialog-popup-content')).toBeHidden();
|
|
59
|
+
await expect(trigger).toBeFocused();
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test('focus movement: Tab moves focus between focusable elements within the popup', async ({
|
|
63
|
+
page,
|
|
64
|
+
}) => {
|
|
65
|
+
await page.visitExample<typeof import('../../examples/97-testing-initial-focus-matrix.tsx')>(
|
|
66
|
+
'design-system',
|
|
67
|
+
'popup',
|
|
68
|
+
'testing-initial-focus-matrix',
|
|
69
|
+
{ featureFlag },
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
await page.getByTestId('dialog-popup-trigger').click();
|
|
73
|
+
await expect(page.getByTestId('dialog-popup-content')).toBeVisible();
|
|
74
|
+
|
|
75
|
+
const first = page.getByTestId('dialog-popup-first-button');
|
|
76
|
+
const second = page.getByTestId('dialog-popup-second-button');
|
|
77
|
+
|
|
78
|
+
await expect(first).toBeFocused();
|
|
79
|
+
await page.keyboard.press('Tab');
|
|
80
|
+
await expect(second).toBeFocused();
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
// WCAG 2.4.3 Focus Order + WAI-ARIA APG Dialog pattern
|
|
84
|
+
// (https://www.w3.org/WAI/ARIA/apg/patterns/dialog-modal/).
|
|
85
|
+
// For `role="dialog"`, when a descendant carries the native HTML
|
|
86
|
+
// `autofocus` attribute, focus must land on that element instead of
|
|
87
|
+
// the first focusable in source order.
|
|
88
|
+
test('initial focus: native [autofocus] element wins for role="dialog"', async ({ page }) => {
|
|
89
|
+
await page.visitExample<typeof import('../../examples/97-testing-initial-focus-matrix.tsx')>(
|
|
90
|
+
'design-system',
|
|
91
|
+
'popup',
|
|
92
|
+
'testing-initial-focus-matrix',
|
|
93
|
+
{ featureFlag },
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
await page.getByTestId('autofocus-dialog-popup-trigger').click();
|
|
97
|
+
await expect(page.getByTestId('autofocus-dialog-popup-content')).toBeVisible();
|
|
98
|
+
|
|
99
|
+
// The popup's first focusable is a button, but a sibling
|
|
100
|
+
// `<input>` carries `autofocus`, so focus must land on the
|
|
101
|
+
// input.
|
|
102
|
+
await expect(page.getByTestId('autofocus-dialog-popup-input')).toBeFocused();
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
// WCAG 2.4.3 Focus Order (no opinionated movement when no role is
|
|
106
|
+
// declared). The Popover API does not move focus on open; ARIA roles
|
|
107
|
+
// such as `dialog` / `menu` / `listbox` are what trigger the
|
|
108
|
+
// initial-focus contract. A popover without a role has no APG
|
|
109
|
+
// pattern, so focus must stay on the trigger.
|
|
110
|
+
test('initial focus: no `role` prop keeps focus on the trigger', async ({ page }) => {
|
|
111
|
+
await page.visitExample<typeof import('../../examples/97-testing-initial-focus-matrix.tsx')>(
|
|
112
|
+
'design-system',
|
|
113
|
+
'popup',
|
|
114
|
+
'testing-initial-focus-matrix',
|
|
115
|
+
{ featureFlag },
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
const trigger = page.getByTestId('no-role-popup-trigger');
|
|
119
|
+
// Explicitly focus the trigger before clicking so the assertion
|
|
120
|
+
// reflects the contract under test (focus is preserved across
|
|
121
|
+
// open). `button.click()` does not synchronously focus the
|
|
122
|
+
// element on every browser engine (notably WebKit), so we cannot
|
|
123
|
+
// rely on the click as the focus trigger here.
|
|
124
|
+
await trigger.focus();
|
|
125
|
+
await trigger.click();
|
|
126
|
+
await expect(page.getByTestId('no-role-popup-content')).toBeVisible();
|
|
127
|
+
|
|
128
|
+
// Without a role, the popup is `tabIndex={-1}` and is not a
|
|
129
|
+
// useful focus target, so focus remains on the trigger.
|
|
130
|
+
await expect(trigger).toBeFocused();
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
// WCAG 2.4.3 Focus Order + WAI-ARIA APG Listbox pattern
|
|
134
|
+
// (https://www.w3.org/WAI/ARIA/apg/patterns/listbox/).
|
|
135
|
+
// "If an option is selected, focus is set on the selected option."
|
|
136
|
+
// Focus must land on `[aria-selected="true"]` rather than the first
|
|
137
|
+
// `[role="option"]`.
|
|
138
|
+
test('initial focus: listbox prefers `[aria-selected="true"]` over the first option', async ({
|
|
139
|
+
page,
|
|
140
|
+
}) => {
|
|
141
|
+
await page.visitExample<typeof import('../../examples/97-testing-initial-focus-matrix.tsx')>(
|
|
142
|
+
'design-system',
|
|
143
|
+
'popup',
|
|
144
|
+
'testing-initial-focus-matrix',
|
|
145
|
+
{ featureFlag },
|
|
146
|
+
);
|
|
147
|
+
|
|
148
|
+
await page.getByTestId('selected-option-listbox-popup-trigger').click();
|
|
149
|
+
await expect(page.getByTestId('selected-option-listbox-popup-content')).toBeVisible();
|
|
150
|
+
|
|
151
|
+
await expect(page.getByTestId('selected-option-listbox-option-2')).toBeFocused();
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
// WCAG 2.4.3 Focus Order + WAI-ARIA APG Combobox pattern
|
|
155
|
+
// (https://www.w3.org/WAI/ARIA/apg/patterns/combobox/).
|
|
156
|
+
// "DOM focus remains on the combobox... the listbox does not
|
|
157
|
+
// receive focus." When the combobox's `aria-controls` references the
|
|
158
|
+
// popup id, focus must remain on the combobox input so the user can
|
|
159
|
+
// keep typing; the active option is surfaced via
|
|
160
|
+
// `aria-activedescendant`.
|
|
161
|
+
test('initial focus: combobox-controlled listbox keeps focus on the combobox input', async ({
|
|
162
|
+
page,
|
|
163
|
+
}) => {
|
|
164
|
+
await page.visitExample<typeof import('../../examples/97-testing-initial-focus-matrix.tsx')>(
|
|
165
|
+
'design-system',
|
|
166
|
+
'popup',
|
|
167
|
+
'testing-initial-focus-matrix',
|
|
168
|
+
{ featureFlag },
|
|
169
|
+
);
|
|
170
|
+
|
|
171
|
+
const combobox = page.getByTestId('combobox-controls-input');
|
|
172
|
+
await combobox.focus();
|
|
173
|
+
await expect(page.getByTestId('combobox-controls-popup-content')).toBeVisible();
|
|
174
|
+
|
|
175
|
+
await expect(combobox).toBeFocused();
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
// WCAG 2.4.3 Focus Order. Carve-out scoping: the APG Combobox
|
|
179
|
+
// exception only applies when the focused combobox's `aria-controls`
|
|
180
|
+
// references this popup. An unrelated combobox on the page must not
|
|
181
|
+
// block the standard listbox initial-focus behaviour.
|
|
182
|
+
test('initial focus: an unrelated combobox does not block focus movement into the listbox', async ({
|
|
183
|
+
page,
|
|
184
|
+
}) => {
|
|
185
|
+
await page.visitExample<typeof import('../../examples/97-testing-initial-focus-matrix.tsx')>(
|
|
186
|
+
'design-system',
|
|
187
|
+
'popup',
|
|
188
|
+
'testing-initial-focus-matrix',
|
|
189
|
+
{ featureFlag },
|
|
190
|
+
);
|
|
191
|
+
|
|
192
|
+
// Focus an unrelated combobox first so it is the active element
|
|
193
|
+
// at the moment the popup opens. Its `aria-controls` points
|
|
194
|
+
// elsewhere, so the carve-out must not apply.
|
|
195
|
+
await page.getByTestId('unrelated-combobox-input').focus();
|
|
196
|
+
await page.getByTestId('unrelated-combobox-popup-trigger').click();
|
|
197
|
+
await expect(page.getByTestId('unrelated-combobox-popup-content')).toBeVisible();
|
|
198
|
+
|
|
199
|
+
await expect(page.getByTestId('unrelated-combobox-option-1')).toBeFocused();
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
// WCAG 2.4.3 Focus Order + WAI-ARIA APG Combobox pattern
|
|
203
|
+
// (https://www.w3.org/WAI/ARIA/apg/patterns/combobox/).
|
|
204
|
+
// The combobox-carve-out is scoped by the `aria-controls`
|
|
205
|
+
// relationship, not by DOM containment. The `react-select` pattern
|
|
206
|
+
// portals the listbox separately from the textbox, so focus must
|
|
207
|
+
// still stay on the external input.
|
|
208
|
+
test('initial focus: external combobox (react-select pattern) keeps focus on the input', async ({
|
|
209
|
+
page,
|
|
210
|
+
}) => {
|
|
211
|
+
await page.visitExample<typeof import('../../examples/97-testing-initial-focus-matrix.tsx')>(
|
|
212
|
+
'design-system',
|
|
213
|
+
'popup',
|
|
214
|
+
'testing-initial-focus-matrix',
|
|
215
|
+
{ featureFlag },
|
|
216
|
+
);
|
|
217
|
+
|
|
218
|
+
const combobox = page.getByTestId('external-combobox-input');
|
|
219
|
+
await combobox.focus();
|
|
220
|
+
await expect(page.getByTestId('external-combobox-popup-content')).toBeVisible();
|
|
221
|
+
|
|
222
|
+
await expect(combobox).toBeFocused();
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
// Consumer escape hatch. `autoFocus={false}` disables Popup's
|
|
226
|
+
// initial-focus behaviour entirely. Note: pairing `autoFocus={false}`
|
|
227
|
+
// with `role="dialog"` deviates from the WAI-ARIA APG Dialog
|
|
228
|
+
// pattern, which expects focus to move into the dialog on open.
|
|
229
|
+
// The escape hatch is intended for patterns where the popup is
|
|
230
|
+
// visual-only (e.g. a hover-card / tooltip-like surface) and must
|
|
231
|
+
// not be combined with a focus-receiving role in production code.
|
|
232
|
+
test('initial focus: `autoFocus={false}` keeps focus on the trigger', async ({ page }) => {
|
|
233
|
+
await page.visitExample<typeof import('../../examples/97-testing-initial-focus-matrix.tsx')>(
|
|
234
|
+
'design-system',
|
|
235
|
+
'popup',
|
|
236
|
+
'testing-initial-focus-matrix',
|
|
237
|
+
{ featureFlag },
|
|
238
|
+
);
|
|
239
|
+
|
|
240
|
+
const trigger = page.getByTestId('auto-focus-disabled-popup-trigger');
|
|
241
|
+
// Explicitly focus the trigger before clicking so the assertion
|
|
242
|
+
// reflects the contract under test (focus is preserved across
|
|
243
|
+
// open). `button.click()` does not synchronously focus the
|
|
244
|
+
// element on every browser engine (notably WebKit).
|
|
245
|
+
await trigger.focus();
|
|
246
|
+
await trigger.click();
|
|
247
|
+
await expect(page.getByTestId('auto-focus-disabled-popup-content')).toBeVisible();
|
|
248
|
+
|
|
249
|
+
await expect(trigger).toBeFocused();
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
// WCAG 2.4.3 Focus Order. `Popup`'s `content` render prop exposes
|
|
253
|
+
// `setInitialFocusRef` so consumers can override the default
|
|
254
|
+
// `getInitialFocusTarget` resolution and pick a specific element to
|
|
255
|
+
// focus on open. The consumer-supplied ref must win over the role-
|
|
256
|
+
// based default (first focusable for `role="dialog"`).
|
|
257
|
+
test('initial focus: consumer-supplied `setInitialFocusRef` overrides the role-based default', async ({
|
|
258
|
+
page,
|
|
259
|
+
}) => {
|
|
260
|
+
await page.visitExample<typeof import('../../examples/97-testing-initial-focus-matrix.tsx')>(
|
|
261
|
+
'design-system',
|
|
262
|
+
'popup',
|
|
263
|
+
'testing-initial-focus-matrix',
|
|
264
|
+
{ featureFlag },
|
|
265
|
+
);
|
|
266
|
+
|
|
267
|
+
await page.getByTestId('set-initial-focus-ref-popup-trigger').click();
|
|
268
|
+
await expect(page.getByTestId('set-initial-focus-ref-popup-content')).toBeVisible();
|
|
269
|
+
|
|
270
|
+
// The first focusable in the popup is the first button, but the
|
|
271
|
+
// consumer wired `setInitialFocusRef` to the second button.
|
|
272
|
+
await expect(page.getByTestId('set-initial-focus-ref-popup-second-button')).toBeFocused();
|
|
273
|
+
});
|
|
274
|
+
});
|
|
@@ -6,12 +6,5 @@
|
|
|
6
6
|
"sideEffects": [
|
|
7
7
|
"**/*.compiled.css"
|
|
8
8
|
],
|
|
9
|
-
"types": "../../dist/types/entry-points/compositional-popup.d.ts"
|
|
10
|
-
"typesVersions": {
|
|
11
|
-
">=4.5 <5.9": {
|
|
12
|
-
"*": [
|
|
13
|
-
"../../dist/types-ts4.5/entry-points/compositional-popup.d.ts"
|
|
14
|
-
]
|
|
15
|
-
}
|
|
16
|
-
}
|
|
9
|
+
"types": "../../dist/types/entry-points/compositional-popup.d.ts"
|
|
17
10
|
}
|
|
@@ -6,12 +6,5 @@
|
|
|
6
6
|
"sideEffects": [
|
|
7
7
|
"**/*.compiled.css"
|
|
8
8
|
],
|
|
9
|
-
"types": "../../dist/types/entry-points/compositional-popup-content.d.ts"
|
|
10
|
-
"typesVersions": {
|
|
11
|
-
">=4.5 <5.9": {
|
|
12
|
-
"*": [
|
|
13
|
-
"../../dist/types-ts4.5/entry-points/compositional-popup-content.d.ts"
|
|
14
|
-
]
|
|
15
|
-
}
|
|
16
|
-
}
|
|
9
|
+
"types": "../../dist/types/entry-points/compositional-popup-content.d.ts"
|
|
17
10
|
}
|
|
@@ -6,12 +6,5 @@
|
|
|
6
6
|
"sideEffects": [
|
|
7
7
|
"**/*.compiled.css"
|
|
8
8
|
],
|
|
9
|
-
"types": "../../dist/types/entry-points/compositional-popup-trigger.d.ts"
|
|
10
|
-
"typesVersions": {
|
|
11
|
-
">=4.5 <5.9": {
|
|
12
|
-
"*": [
|
|
13
|
-
"../../dist/types-ts4.5/entry-points/compositional-popup-trigger.d.ts"
|
|
14
|
-
]
|
|
15
|
-
}
|
|
16
|
-
}
|
|
9
|
+
"types": "../../dist/types/entry-points/compositional-popup-trigger.d.ts"
|
|
17
10
|
}
|
|
@@ -11,9 +11,9 @@ require("./popup-content-top-layer.compiled.css");
|
|
|
11
11
|
var _react = _interopRequireWildcard(require("react"));
|
|
12
12
|
var React = _react;
|
|
13
13
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
14
|
-
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
15
14
|
var _runtime = require("@compiled/react/runtime");
|
|
16
15
|
var _noop = _interopRequireDefault(require("@atlaskit/ds-lib/noop"));
|
|
16
|
+
var _openLayerObserver = require("@atlaskit/layering/experimental/open-layer-observer");
|
|
17
17
|
var _animations = require("@atlaskit/top-layer/animations");
|
|
18
18
|
var _placementMap = require("@atlaskit/top-layer/placement-map");
|
|
19
19
|
var _popover = require("@atlaskit/top-layer/popover");
|
|
@@ -66,11 +66,26 @@ function PopupContentTopLayer(_ref) {
|
|
|
66
66
|
_shouldFlip = _ref.shouldFlip,
|
|
67
67
|
_appearance = _ref.appearance,
|
|
68
68
|
_shouldDisableGpuAcceleration = _ref.shouldDisableGpuAcceleration;
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
69
|
+
/**
|
|
70
|
+
* Escape hatch for consumer-chosen initial focus target.
|
|
71
|
+
*
|
|
72
|
+
* The legacy compositional `PopupContent` surfaced
|
|
73
|
+
* `setInitialFocusRef` on the content children render prop with a
|
|
74
|
+
* `Dispatch<SetStateAction<HTMLElement | null>>` signature so it
|
|
75
|
+
* could be passed as a React `ref` callback. We keep the same shape
|
|
76
|
+
* for API compatibility, but store the value in a ref rather than
|
|
77
|
+
* component state. Flipping state on every open caused a needless
|
|
78
|
+
* re-render and, more importantly, raced the initial-focus effect
|
|
79
|
+
* below. The ref is read in the open-side effect to override the
|
|
80
|
+
* role-based default focus chosen by `useInitialFocus` inside the
|
|
81
|
+
* underlying `Popover`.
|
|
82
|
+
*/
|
|
83
|
+
var consumerInitialFocusRef = (0, _react.useRef)(null);
|
|
84
|
+
var setInitialFocusRef = (0, _react.useCallback)(function (value) {
|
|
85
|
+
consumerInitialFocusRef.current = typeof value === 'function' ? value(consumerInitialFocusRef.current) : value;
|
|
86
|
+
}, []);
|
|
72
87
|
|
|
73
|
-
//
|
|
88
|
+
// Placement conversion
|
|
74
89
|
// Legacy `offset` is the popper `[along, away]` tuple; `fromLegacyPlacement`
|
|
75
90
|
// folds it into the new `placement.offset` shape.
|
|
76
91
|
var topLayerPlacement = (0, _react.useMemo)(function () {
|
|
@@ -99,7 +114,7 @@ function PopupContentTopLayer(_ref) {
|
|
|
99
114
|
onClose: onClose,
|
|
100
115
|
setInitialFocusRef: setInitialFocusRef
|
|
101
116
|
};
|
|
102
|
-
}, [isOpen, onClose]);
|
|
117
|
+
}, [isOpen, onClose, setInitialFocusRef]);
|
|
103
118
|
|
|
104
119
|
// ── Role mapping ──
|
|
105
120
|
var roleProps = (0, _topLayerBridge.useRoleProps)({
|
|
@@ -110,6 +125,49 @@ function PopupContentTopLayer(_ref) {
|
|
|
110
125
|
var popoverRef = (0, _react.useRef)(null);
|
|
111
126
|
var anchorRef = (0, _react.useContext)(_triggerRefObjectContext.TriggerRefObjectContext);
|
|
112
127
|
|
|
128
|
+
/**
|
|
129
|
+
* Override the role-based initial focus chosen by the underlying
|
|
130
|
+
* `Popover` (its internal `useInitialFocus`).
|
|
131
|
+
*
|
|
132
|
+
* React flushes child effects before parent effects, so by the time
|
|
133
|
+
* this effect runs the role-based default focus has already moved.
|
|
134
|
+
* We then apply the legacy `Popup` contract:
|
|
135
|
+
*
|
|
136
|
+
* 1. If the consumer wired `setInitialFocusRef`, focus that element
|
|
137
|
+
* (escape hatch wins).
|
|
138
|
+
* 2. Otherwise, if `autoFocus={false}`, return focus to the trigger.
|
|
139
|
+
* The `autoFocus` prop on `Popup` opts out of any initial-focus
|
|
140
|
+
* movement, even for roles like `dialog`.
|
|
141
|
+
*
|
|
142
|
+
* When neither applies the role-based default from the underlying
|
|
143
|
+
* `Popover` stays in place.
|
|
144
|
+
*/
|
|
145
|
+
(0, _react.useEffect)(function () {
|
|
146
|
+
if (!isOpen) {
|
|
147
|
+
/**
|
|
148
|
+
* Clear the consumer-supplied focus target on close so a
|
|
149
|
+
* subsequent open does not silently inherit a stale ref from
|
|
150
|
+
* the previous open cycle. The next open will re-collect a
|
|
151
|
+
* target only if the content render prop re-wires
|
|
152
|
+
* `setInitialFocusRef`.
|
|
153
|
+
*/
|
|
154
|
+
consumerInitialFocusRef.current = null;
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
var consumerTarget = consumerInitialFocusRef.current;
|
|
158
|
+
if (consumerTarget && consumerTarget.isConnected) {
|
|
159
|
+
consumerTarget.focus();
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
if (!autoFocus) {
|
|
163
|
+
var _anchorRef$current;
|
|
164
|
+
var trigger = (_anchorRef$current = anchorRef === null || anchorRef === void 0 ? void 0 : anchorRef.current) !== null && _anchorRef$current !== void 0 ? _anchorRef$current : null;
|
|
165
|
+
if (trigger && trigger.isConnected) {
|
|
166
|
+
trigger.focus();
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}, [isOpen, autoFocus, anchorRef]);
|
|
170
|
+
|
|
113
171
|
// `isOpen` is included so the anchor positioning effect re-runs when
|
|
114
172
|
// the Popover host element is unmounted/remounted across open cycles.
|
|
115
173
|
(0, _useAnchorPosition.useAnchorPosition)({
|
|
@@ -125,6 +183,33 @@ function PopupContentTopLayer(_ref) {
|
|
|
125
183
|
isOpen: isOpen
|
|
126
184
|
});
|
|
127
185
|
|
|
186
|
+
/**
|
|
187
|
+
* Register with the open-layer observer as a `popup` while open.
|
|
188
|
+
*
|
|
189
|
+
* The legacy compositional `PopupContent` registered every open
|
|
190
|
+
* popup with the observer regardless of role, and product surfaces
|
|
191
|
+
* such as the side-nav panel splitter rely on this signal to detect
|
|
192
|
+
* open popups via `getCount({ type: 'popup' }) > 0`. The underlying
|
|
193
|
+
* top-layer `Popover` only self-registers when its role is one of
|
|
194
|
+
* `menu | listbox | dialog | alertdialog | tree | grid`, which would
|
|
195
|
+
* miss role-less popups and silently regress the splitter.
|
|
196
|
+
*
|
|
197
|
+
* Registering here unconditionally preserves the legacy contract.
|
|
198
|
+
* When the role does opt the `Popover` into observer registration
|
|
199
|
+
* the count is incremented twice, which is safe because every known
|
|
200
|
+
* consumer treats the count as a boolean (`> 0` / `=== 0`).
|
|
201
|
+
*/
|
|
202
|
+
var handleObserverClose = (0, _react.useCallback)(function () {
|
|
203
|
+
onClose === null || onClose === void 0 || onClose((0, _popover.createPopoverCloseEvent)({
|
|
204
|
+
reason: 'programmatic'
|
|
205
|
+
}));
|
|
206
|
+
}, [onClose]);
|
|
207
|
+
(0, _openLayerObserver.useNotifyOpenLayerObserver)({
|
|
208
|
+
type: 'popup',
|
|
209
|
+
isOpen: isOpen,
|
|
210
|
+
onClose: handleObserverClose
|
|
211
|
+
});
|
|
212
|
+
|
|
128
213
|
// Narrow to ForwardRefExoticComponent so JSX accepts the ref prop.
|
|
129
214
|
// All popupComponent implementations use forwardRef per the PopupComponentProps contract.
|
|
130
215
|
var Container = PopupContainer;
|
|
@@ -7,6 +7,13 @@ exports.useRoleProps = useRoleProps;
|
|
|
7
7
|
var _react = require("react");
|
|
8
8
|
/**
|
|
9
9
|
* Props shape passed from legacy `role` / `label` / `titleId` into `@atlaskit/top-layer` `Popup.Content`.
|
|
10
|
+
*
|
|
11
|
+
* The `{ role: undefined }` variant covers the legacy contract where a
|
|
12
|
+
* consumer omits `role` to opt out of any popup semantics (and the
|
|
13
|
+
* associated role-based initial-focus movement). Legacy `Popup` left the
|
|
14
|
+
* popup element role-less in that case; we preserve that behaviour here
|
|
15
|
+
* rather than defaulting to `'dialog'`, which would move focus into the
|
|
16
|
+
* popup on open.
|
|
10
17
|
*/
|
|
11
18
|
|
|
12
19
|
/**
|
|
@@ -16,6 +23,10 @@ var _react = require("react");
|
|
|
16
23
|
* `Popup.Content` enforces at the type level that dialog/alertdialog/menu
|
|
17
24
|
* roles must have `label` or `labelledBy`. This hook bridges the legacy
|
|
18
25
|
* flat-prop API (`role`, `label`, `titleId`) to that shape.
|
|
26
|
+
*
|
|
27
|
+
* When `role` is omitted entirely, the result carries `role: undefined`
|
|
28
|
+
* (no implicit default). This matches the legacy `Popup` contract and
|
|
29
|
+
* keeps the underlying `Popover` from running role-based initial focus.
|
|
19
30
|
*/
|
|
20
31
|
function useRoleProps(_ref) {
|
|
21
32
|
var role = _ref.role,
|
|
@@ -40,16 +51,10 @@ function useRoleProps(_ref) {
|
|
|
40
51
|
label: label
|
|
41
52
|
};
|
|
42
53
|
}
|
|
43
|
-
//
|
|
44
|
-
if (titleId) {
|
|
45
|
-
return {
|
|
46
|
-
role: 'dialog',
|
|
47
|
-
labelledBy: titleId
|
|
48
|
-
};
|
|
49
|
-
}
|
|
54
|
+
// No role supplied: preserve the legacy "no popup semantics" contract.
|
|
50
55
|
return {
|
|
51
|
-
role:
|
|
52
|
-
label: label
|
|
56
|
+
role: undefined,
|
|
57
|
+
label: label
|
|
53
58
|
};
|
|
54
59
|
}, [role, label, titleId]);
|
|
55
60
|
}
|
|
@@ -12,8 +12,8 @@ var _react = _interopRequireWildcard(require("react"));
|
|
|
12
12
|
var React = _react;
|
|
13
13
|
var _runtime = require("@compiled/react/runtime");
|
|
14
14
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
15
|
-
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
16
15
|
var _noop = _interopRequireDefault(require("@atlaskit/ds-lib/noop"));
|
|
16
|
+
var _openLayerObserver = require("@atlaskit/layering/experimental/open-layer-observer");
|
|
17
17
|
var _animations = require("@atlaskit/top-layer/animations");
|
|
18
18
|
var _getAriaForTrigger = require("@atlaskit/top-layer/get-aria-for-trigger");
|
|
19
19
|
var _placementMap = require("@atlaskit/top-layer/placement-map");
|
|
@@ -80,9 +80,66 @@ var PopupTopLayer = exports.PopupTopLayer = /*#__PURE__*/(0, _react.memo)(functi
|
|
|
80
80
|
var triggerRef = (0, _react.useRef)(null);
|
|
81
81
|
var popoverRef = (0, _react.useRef)(null);
|
|
82
82
|
var popupContainerRef = (0, _react.useRef)(null);
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Escape hatch for consumer-chosen initial focus target.
|
|
86
|
+
*
|
|
87
|
+
* The legacy `Popup` surfaced `setInitialFocusRef` on the content
|
|
88
|
+
* render prop with a `Dispatch<SetStateAction<HTMLElement | null>>`
|
|
89
|
+
* signature so it could be passed as a React `ref` callback. We
|
|
90
|
+
* keep the same shape for API compatibility, but store the value in
|
|
91
|
+
* a ref rather than component state. Flipping state on every open
|
|
92
|
+
* caused a needless re-render and, more importantly, raced the
|
|
93
|
+
* initial-focus effect below. The ref is read in the open-side
|
|
94
|
+
* effect to override the role-based default focus chosen by
|
|
95
|
+
* `useInitialFocus` inside the underlying `Popover`.
|
|
96
|
+
*/
|
|
97
|
+
var consumerInitialFocusRef = (0, _react.useRef)(null);
|
|
98
|
+
var setInitialFocusRef = (0, _react.useCallback)(function (value) {
|
|
99
|
+
consumerInitialFocusRef.current = typeof value === 'function' ? value(consumerInitialFocusRef.current) : value;
|
|
100
|
+
}, []);
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Override the role-based initial focus chosen by the underlying
|
|
104
|
+
* `Popover` (its internal `useInitialFocus`).
|
|
105
|
+
*
|
|
106
|
+
* React flushes child effects before parent effects, so by the time
|
|
107
|
+
* this effect runs the role-based default focus has already moved.
|
|
108
|
+
* We then apply the legacy `Popup` contract:
|
|
109
|
+
*
|
|
110
|
+
* 1. If the consumer wired `setInitialFocusRef`, focus that element
|
|
111
|
+
* (escape hatch wins).
|
|
112
|
+
* 2. Otherwise, if `autoFocus={false}`, return focus to the trigger.
|
|
113
|
+
* The `autoFocus` prop on `Popup` opts out of any initial-focus
|
|
114
|
+
* movement, even for roles like `dialog`.
|
|
115
|
+
*
|
|
116
|
+
* When neither applies the role-based default from the underlying
|
|
117
|
+
* `Popover` stays in place.
|
|
118
|
+
*/
|
|
119
|
+
(0, _react.useEffect)(function () {
|
|
120
|
+
if (!isOpen) {
|
|
121
|
+
/**
|
|
122
|
+
* Clear the consumer-supplied focus target on close so a
|
|
123
|
+
* subsequent open does not silently inherit a stale ref from
|
|
124
|
+
* the previous open cycle. The next open will re-collect a
|
|
125
|
+
* target only if the content render prop re-wires
|
|
126
|
+
* `setInitialFocusRef`.
|
|
127
|
+
*/
|
|
128
|
+
consumerInitialFocusRef.current = null;
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
var consumerTarget = consumerInitialFocusRef.current;
|
|
132
|
+
if (consumerTarget && consumerTarget.isConnected) {
|
|
133
|
+
consumerTarget.focus();
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
if (!autoFocus) {
|
|
137
|
+
var _trigger = triggerRef.current;
|
|
138
|
+
if (_trigger && _trigger.isConnected) {
|
|
139
|
+
_trigger.focus();
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}, [isOpen, autoFocus]);
|
|
86
143
|
var popoverId = (0, _usePopoverId.usePopoverId)();
|
|
87
144
|
|
|
88
145
|
// Placement conversion.
|
|
@@ -107,6 +164,33 @@ var PopupTopLayer = exports.PopupTopLayer = /*#__PURE__*/(0, _react.memo)(functi
|
|
|
107
164
|
isOpen: isOpen
|
|
108
165
|
});
|
|
109
166
|
|
|
167
|
+
/**
|
|
168
|
+
* Register with the open-layer observer as a `popup` while open.
|
|
169
|
+
*
|
|
170
|
+
* The legacy `Popup` registered every open popup with the observer
|
|
171
|
+
* regardless of role, and product surfaces such as the side-nav
|
|
172
|
+
* panel splitter rely on this signal to detect open popups via
|
|
173
|
+
* `getCount({ type: 'popup' }) > 0`. The underlying top-layer
|
|
174
|
+
* `Popover` only self-registers when its role is one of
|
|
175
|
+
* `menu | listbox | dialog | alertdialog | tree | grid`, which would
|
|
176
|
+
* miss role-less popups and silently regress the splitter.
|
|
177
|
+
*
|
|
178
|
+
* Registering here unconditionally preserves the legacy contract.
|
|
179
|
+
* When the role does opt the `Popover` into observer registration
|
|
180
|
+
* the count is incremented twice, which is safe because every known
|
|
181
|
+
* consumer treats the count as a boolean (`> 0` / `=== 0`).
|
|
182
|
+
*/
|
|
183
|
+
var handleObserverClose = (0, _react.useCallback)(function () {
|
|
184
|
+
onClose === null || onClose === void 0 || onClose((0, _popover.createPopoverCloseEvent)({
|
|
185
|
+
reason: 'programmatic'
|
|
186
|
+
}));
|
|
187
|
+
}, [onClose]);
|
|
188
|
+
(0, _openLayerObserver.useNotifyOpenLayerObserver)({
|
|
189
|
+
type: 'popup',
|
|
190
|
+
isOpen: isOpen,
|
|
191
|
+
onClose: handleObserverClose
|
|
192
|
+
});
|
|
193
|
+
|
|
110
194
|
// onClose bridge.
|
|
111
195
|
// Translates top-layer's { reason: TPopoverCloseReason } into legacy
|
|
112
196
|
// onClose(event, currentLevel?) by synthesizing DOM events.
|
|
@@ -135,7 +219,7 @@ var PopupTopLayer = exports.PopupTopLayer = /*#__PURE__*/(0, _react.memo)(functi
|
|
|
135
219
|
onClose: onClose,
|
|
136
220
|
setInitialFocusRef: setInitialFocusRef
|
|
137
221
|
};
|
|
138
|
-
}, [isOpen, onClose]);
|
|
222
|
+
}, [isOpen, onClose, setInitialFocusRef]);
|
|
139
223
|
|
|
140
224
|
// Role mapping.
|
|
141
225
|
// Build the role/label props for Popover.
|