@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/dist/index.mjs CHANGED
@@ -278,6 +278,15 @@ function getFocusableElements(container) {
278
278
  function savePreviousFocus() {
279
279
  return document.activeElement instanceof HTMLElement ? document.activeElement : null;
280
280
  }
281
+ function focusInitial(domNode, initialFocusTestID) {
282
+ const named = initialFocusTestID === void 0 ? null : domNode.querySelector(`[data-testid="${initialFocusTestID}"]`);
283
+ if (named) {
284
+ named.focus();
285
+ return;
286
+ }
287
+ if (domNode.contains(document.activeElement)) return;
288
+ getFocusableElements(domNode)[0]?.focus();
289
+ }
281
290
  function handleKeyDown(domNode, event) {
282
291
  if (event.key !== "Tab") return;
283
292
  const focusable = getFocusableElements(domNode);
@@ -300,14 +309,15 @@ function handleKeyDown(domNode, event) {
300
309
  first.focus();
301
310
  }
302
311
  }
303
- function useFocusTrap(containerRef, enabled) {
312
+ function useFocusTrap(containerRef, enabled, initialFocusTestID) {
304
313
  const previousFocusRef = useRef(null);
305
314
  useEffect(() => {
306
315
  if (Platform.OS !== "web" || !enabled) return;
307
316
  const domNode = containerRef.current;
308
317
  if (!domNode) return;
309
- previousFocusRef.current = savePreviousFocus();
310
- queueMicrotask(() => getFocusableElements(domNode)[0]?.focus());
318
+ const previous = savePreviousFocus();
319
+ previousFocusRef.current = previous !== null && domNode.contains(previous) ? null : previous;
320
+ queueMicrotask(() => focusInitial(domNode, initialFocusTestID));
311
321
  const listener = (e) => handleKeyDown(domNode, e);
312
322
  domNode.addEventListener("keydown", listener);
313
323
  return () => {
@@ -315,7 +325,7 @@ function useFocusTrap(containerRef, enabled) {
315
325
  previousFocusRef.current?.focus();
316
326
  previousFocusRef.current = null;
317
327
  };
318
- }, [containerRef, enabled]);
328
+ }, [containerRef, enabled, initialFocusTestID]);
319
329
  }
320
330
 
321
331
  // src/ModalDropdown/DropdownVariant.ts
@@ -978,7 +988,7 @@ function useTabsCollapsed(breakpoint) {
978
988
  var PILL_RADIUS = 999;
979
989
  var PILL_PAD_H = 16;
980
990
  var PILL_PAD_V = 8;
981
- var PILL_MIN_HEIGHT = 40;
991
+ var PILL_MIN_HEIGHT = MIN_TARGET_PX;
982
992
  var PILL_FONT = 14;
983
993
  var PILL_WEIGHT = "600";
984
994
  var ROW_GAP = 8;
@@ -1334,14 +1344,15 @@ var Modal3 = ({
1334
1344
  size = "md",
1335
1345
  showClose = true,
1336
1346
  testID = LAYOUT_TEST_IDS.modal,
1337
- accessibilityLabel
1347
+ accessibilityLabel,
1348
+ initialFocusTestID
1338
1349
  }) => {
1339
1350
  const { theme, t } = useUi();
1340
1351
  const dialogRef = useRef(null);
1341
1352
  const backdrop = useEnterExit({ visible });
1342
1353
  const panel = useEnterExit({ visible, fromScale: PANEL_ENTER_SCALE2 });
1343
1354
  const mounted = panel.mounted || backdrop.mounted;
1344
- useFocusTrap(dialogRef, visible);
1355
+ useFocusTrap(dialogRef, visible, initialFocusTestID);
1345
1356
  useEscapeKey(visible, onClose);
1346
1357
  useScrollLock(visible);
1347
1358
  const accessibleName = accessibilityLabel ?? title ?? t(LAYOUT_I18N.dialog);