@dloizides/ui-layout 1.28.4 → 1.29.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 +644 -631
- package/dist/index.d.mts +4 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.js +18 -7
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +18 -7
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -397,8 +397,10 @@ interface ModalProps {
|
|
|
397
397
|
testID?: string;
|
|
398
398
|
/** Accessible name of the dialog. Falls back to `title`, then the neutral "dialog" key. */
|
|
399
399
|
accessibilityLabel?: string;
|
|
400
|
+
/** testID of the control focused on open (web). Default: an autoFocus child, else the first focusable. */
|
|
401
|
+
initialFocusTestID?: string;
|
|
400
402
|
}
|
|
401
|
-
declare const Modal: ({ visible, onClose, title, children, footer, size, showClose, testID, accessibilityLabel, }: ModalProps) => React.ReactElement;
|
|
403
|
+
declare const Modal: ({ visible, onClose, title, children, footer, size, showClose, testID, accessibilityLabel, initialFocusTestID, }: ModalProps) => React.ReactElement;
|
|
402
404
|
|
|
403
405
|
/**
|
|
404
406
|
* ConfirmDialog — a confirm/cancel popup built ON {@link Modal}, for the "are you sure?" moment.
|
|
@@ -768,7 +770,7 @@ interface VersionResponse {
|
|
|
768
770
|
*/
|
|
769
771
|
declare function useApiCommit(apiBaseUrl?: string, fetchImpl?: typeof fetch): string | undefined;
|
|
770
772
|
|
|
771
|
-
declare function useFocusTrap(containerRef: RefObject<View | null>, enabled: boolean): void;
|
|
773
|
+
declare function useFocusTrap(containerRef: RefObject<View | null>, enabled: boolean, initialFocusTestID?: string): void;
|
|
772
774
|
|
|
773
775
|
/** Default testIDs — match the apps' existing values so Playwright selectors keep working. */
|
|
774
776
|
declare const LAYOUT_TEST_IDS: {
|
package/dist/index.d.ts
CHANGED
|
@@ -397,8 +397,10 @@ interface ModalProps {
|
|
|
397
397
|
testID?: string;
|
|
398
398
|
/** Accessible name of the dialog. Falls back to `title`, then the neutral "dialog" key. */
|
|
399
399
|
accessibilityLabel?: string;
|
|
400
|
+
/** testID of the control focused on open (web). Default: an autoFocus child, else the first focusable. */
|
|
401
|
+
initialFocusTestID?: string;
|
|
400
402
|
}
|
|
401
|
-
declare const Modal: ({ visible, onClose, title, children, footer, size, showClose, testID, accessibilityLabel, }: ModalProps) => React.ReactElement;
|
|
403
|
+
declare const Modal: ({ visible, onClose, title, children, footer, size, showClose, testID, accessibilityLabel, initialFocusTestID, }: ModalProps) => React.ReactElement;
|
|
402
404
|
|
|
403
405
|
/**
|
|
404
406
|
* ConfirmDialog — a confirm/cancel popup built ON {@link Modal}, for the "are you sure?" moment.
|
|
@@ -768,7 +770,7 @@ interface VersionResponse {
|
|
|
768
770
|
*/
|
|
769
771
|
declare function useApiCommit(apiBaseUrl?: string, fetchImpl?: typeof fetch): string | undefined;
|
|
770
772
|
|
|
771
|
-
declare function useFocusTrap(containerRef: RefObject<View | null>, enabled: boolean): void;
|
|
773
|
+
declare function useFocusTrap(containerRef: RefObject<View | null>, enabled: boolean, initialFocusTestID?: string): void;
|
|
772
774
|
|
|
773
775
|
/** Default testIDs — match the apps' existing values so Playwright selectors keep working. */
|
|
774
776
|
declare const LAYOUT_TEST_IDS: {
|
package/dist/index.js
CHANGED
|
@@ -284,6 +284,15 @@ function getFocusableElements(container) {
|
|
|
284
284
|
function savePreviousFocus() {
|
|
285
285
|
return document.activeElement instanceof HTMLElement ? document.activeElement : null;
|
|
286
286
|
}
|
|
287
|
+
function focusInitial(domNode, initialFocusTestID) {
|
|
288
|
+
const named = initialFocusTestID === void 0 ? null : domNode.querySelector(`[data-testid="${initialFocusTestID}"]`);
|
|
289
|
+
if (named) {
|
|
290
|
+
named.focus();
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
293
|
+
if (domNode.contains(document.activeElement)) return;
|
|
294
|
+
getFocusableElements(domNode)[0]?.focus();
|
|
295
|
+
}
|
|
287
296
|
function handleKeyDown(domNode, event) {
|
|
288
297
|
if (event.key !== "Tab") return;
|
|
289
298
|
const focusable = getFocusableElements(domNode);
|
|
@@ -306,14 +315,15 @@ function handleKeyDown(domNode, event) {
|
|
|
306
315
|
first.focus();
|
|
307
316
|
}
|
|
308
317
|
}
|
|
309
|
-
function useFocusTrap(containerRef, enabled) {
|
|
318
|
+
function useFocusTrap(containerRef, enabled, initialFocusTestID) {
|
|
310
319
|
const previousFocusRef = React10.useRef(null);
|
|
311
320
|
React10.useEffect(() => {
|
|
312
321
|
if (reactNative.Platform.OS !== "web" || !enabled) return;
|
|
313
322
|
const domNode = containerRef.current;
|
|
314
323
|
if (!domNode) return;
|
|
315
|
-
|
|
316
|
-
|
|
324
|
+
const previous = savePreviousFocus();
|
|
325
|
+
previousFocusRef.current = previous !== null && domNode.contains(previous) ? null : previous;
|
|
326
|
+
queueMicrotask(() => focusInitial(domNode, initialFocusTestID));
|
|
317
327
|
const listener = (e) => handleKeyDown(domNode, e);
|
|
318
328
|
domNode.addEventListener("keydown", listener);
|
|
319
329
|
return () => {
|
|
@@ -321,7 +331,7 @@ function useFocusTrap(containerRef, enabled) {
|
|
|
321
331
|
previousFocusRef.current?.focus();
|
|
322
332
|
previousFocusRef.current = null;
|
|
323
333
|
};
|
|
324
|
-
}, [containerRef, enabled]);
|
|
334
|
+
}, [containerRef, enabled, initialFocusTestID]);
|
|
325
335
|
}
|
|
326
336
|
|
|
327
337
|
// src/ModalDropdown/DropdownVariant.ts
|
|
@@ -984,7 +994,7 @@ function useTabsCollapsed(breakpoint) {
|
|
|
984
994
|
var PILL_RADIUS = 999;
|
|
985
995
|
var PILL_PAD_H = 16;
|
|
986
996
|
var PILL_PAD_V = 8;
|
|
987
|
-
var PILL_MIN_HEIGHT =
|
|
997
|
+
var PILL_MIN_HEIGHT = MIN_TARGET_PX;
|
|
988
998
|
var PILL_FONT = 14;
|
|
989
999
|
var PILL_WEIGHT = "600";
|
|
990
1000
|
var ROW_GAP = 8;
|
|
@@ -1340,14 +1350,15 @@ var Modal3 = ({
|
|
|
1340
1350
|
size = "md",
|
|
1341
1351
|
showClose = true,
|
|
1342
1352
|
testID = LAYOUT_TEST_IDS.modal,
|
|
1343
|
-
accessibilityLabel
|
|
1353
|
+
accessibilityLabel,
|
|
1354
|
+
initialFocusTestID
|
|
1344
1355
|
}) => {
|
|
1345
1356
|
const { theme, t } = uiFeedback.useUi();
|
|
1346
1357
|
const dialogRef = React10.useRef(null);
|
|
1347
1358
|
const backdrop = uiMotion.useEnterExit({ visible });
|
|
1348
1359
|
const panel = uiMotion.useEnterExit({ visible, fromScale: PANEL_ENTER_SCALE2 });
|
|
1349
1360
|
const mounted = panel.mounted || backdrop.mounted;
|
|
1350
|
-
useFocusTrap(dialogRef, visible);
|
|
1361
|
+
useFocusTrap(dialogRef, visible, initialFocusTestID);
|
|
1351
1362
|
useEscapeKey(visible, onClose);
|
|
1352
1363
|
useScrollLock(visible);
|
|
1353
1364
|
const accessibleName = accessibilityLabel ?? title ?? t(LAYOUT_I18N.dialog);
|