@dloizides/ui-layout 1.41.0 → 1.43.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.d.mts CHANGED
@@ -489,7 +489,7 @@ interface ModalProps {
489
489
  testID?: string;
490
490
  /** Accessible name of the dialog. Falls back to `title`, then the neutral "dialog" key. */
491
491
  accessibilityLabel?: string;
492
- /** testID of the control focused on open (web). Default: an autoFocus child, else the first focusable. */
492
+ /** testID focused on open (web); the dialog's own testID focuses the dialog. Default: autoFocus child, else first focusable. */
493
493
  initialFocusTestID?: string;
494
494
  }
495
495
  declare const Modal: ({ visible, onClose, title, children, footer, size, showClose, testID, accessibilityLabel, initialFocusTestID, }: ModalProps) => React.ReactElement;
@@ -521,6 +521,13 @@ interface BottomSheetProps {
521
521
  /** A content-height panel docked to the screen bottom, with a dimmed backdrop and an optional pinned footer. */
522
522
  declare const BottomSheet: ({ visible, onClose, title, children, footer, maxHeightFraction, testID, accessibilityLabel, initialFocusTestID, }: BottomSheetProps) => React.ReactElement;
523
523
 
524
+ /** Which control a {@link ConfirmDialog} focuses on open (web). `None` focuses the dialog itself. */
525
+ declare const enum ConfirmDialogFocus {
526
+ Cancel = "cancel",
527
+ Confirm = "confirm",
528
+ None = "none"
529
+ }
530
+
524
531
  /**
525
532
  * ConfirmDialog — a confirm/cancel popup built ON {@link Modal}, for the "are you sure?" moment.
526
533
  *
@@ -554,10 +561,28 @@ interface ConfirmDialogProps {
554
561
  onCancel: () => void;
555
562
  /** In-flight: Confirm shows a spinner and Cancel is disabled. Default `false`. */
556
563
  busy?: boolean;
564
+ /** Control focused on open (web). Default `Cancel`; never use `Confirm` for a destructive action. */
565
+ initialFocus?: ConfirmDialogFocus;
557
566
  /** Base testID. Default `confirm-dialog`. Confirm is `${testID}-confirm`, Cancel `${testID}-cancel`. */
558
567
  testID?: string;
559
568
  }
560
- declare const ConfirmDialog: ({ visible, title, message, confirmLabel, cancelLabel, destructive, onConfirm, onCancel, busy, testID, }: ConfirmDialogProps) => React.ReactElement;
569
+ declare const ConfirmDialog: ({ visible, title, message, confirmLabel, cancelLabel, destructive, onConfirm, onCancel, busy, initialFocus, testID, }: ConfirmDialogProps) => React.ReactElement;
570
+
571
+ interface FormDialogProps {
572
+ visible: boolean;
573
+ title: string;
574
+ children: React.ReactNode;
575
+ submitLabel: string;
576
+ submitHint: string;
577
+ cancelLabel?: string;
578
+ loading?: boolean;
579
+ onSubmit: () => void;
580
+ onCancel: () => void;
581
+ size?: ModalSize;
582
+ testID?: string;
583
+ }
584
+ /** A centred dialog of form fields with Cancel + Submit; ids `${testID}-dialog`, `-save`, `-cancel`. */
585
+ declare const FormDialog: ({ visible, title, children, submitLabel, submitHint, cancelLabel, loading, onSubmit, onCancel, size, testID, }: FormDialogProps) => React.ReactElement;
561
586
 
562
587
  /**
563
588
  * AccordionVariant — the two visual treatments for an {@link Accordion}.
@@ -910,10 +935,14 @@ declare const LAYOUT_TEST_IDS: {
910
935
  readonly bottomSheet: "bottom-sheet";
911
936
  /** Default base testID for `ConfirmDialog`; Confirm/Cancel are `confirm-dialog-{confirm,cancel}`. */
912
937
  readonly confirmDialog: "confirm-dialog";
938
+ /** Default base testID for `FormDialog`: `form-dialog`, `form-save`, `form-cancel`. */
939
+ readonly formDialog: "form";
913
940
  readonly accordion: "accordion";
914
941
  /** Default testID for the `BuildInfoFooter` caption (`v<version>`). */
915
942
  readonly buildInfoFooter: "build-info-footer";
916
943
  };
944
+ /** Window width (px) below which a dialog footer stacks its actions full width. */
945
+ declare const MODAL_FOOTER_STACK_BELOW = 400;
917
946
  /** Route the UpgradePrompt CTA navigates to by default (the apps' billing settings path). */
918
947
  declare const DEFAULT_BILLING_ROUTE = "/settings/billing";
919
948
  /**
@@ -1023,6 +1052,8 @@ declare const MIN_TARGET_PX = 44;
1023
1052
  * `false`, whatever the width.
1024
1053
  */
1025
1054
  declare function isWideWebViewport(width: number, platformOS: string, breakpoint?: number): boolean;
1055
+ /** Whether a dialog footer stacks its actions full width at this window width. */
1056
+ declare function isModalFooterStacked(width: number): boolean;
1026
1057
 
1027
1058
  declare enum RowSelectedStyle {
1028
1059
  Surface = "surface",
@@ -1084,4 +1115,4 @@ interface RowLook {
1084
1115
  /** Resolves a row's container style and text colours from its selected style and state. */
1085
1116
  declare function resolveRowLook(style: RowSelectedStyle, state: RowState, palette: RowPalette): RowLook;
1086
1117
 
1087
- export { A4_PAGE, API_COMMIT_SEPARATOR, Accordion, AccordionItem, type AccordionItemProps, type AccordionProps, type AccordionVariant, AppText, type AppTextProps, BUILD_INFO_PREFIX, BottomSheet, type BottomSheetProps, BuildInfoFooter, type BuildInfoFooterProps, COPY_FEEDBACK_MS, ConfirmDialog, type ConfirmDialogProps, CopyStatus, type CopyToClipboard, CopyableId, type CopyableIdProps, DEFAULT_BILLING_ROUTE, type DropdownOption, type DropdownTriggerState, DropdownVariant, ELLIPSIS, HEADER_STACK_BREAKPOINT, Heading, type HeadingLevel, type HeadingProps, LAYOUT_COLLAPSE_BREAKPOINT, LAYOUT_I18N, LAYOUT_TEST_IDS, ListRow, type ListRowProps, type ListRowTone, MIN_TARGET_PX, Modal, ModalDropdown, type ModalDropdownProps, type ModalProps, ModalShell, type ModalShellProps, type ModalSize, PageFrame, type PageFrameProps, type PageSize, type RowLook, type RowPalette, RowSelectedStyle, type RowState, type ScaledFrame, ScreenColumn, type ScreenColumnProps, Section, type SectionProps, SectionVariant, SegmentedControl, type SegmentedControlProps, type SegmentedOption, SelectedMarker, SideSheet, type SideSheetProps, StatusBadge, type StatusBadgeProps, StickyPreview, type StickyPreviewProps, TYPE_SCALE_BREAKPOINT, type TabDescriptor, Tabs, TabsCollapsedTrigger, type TabsProps, TextKind, TruncatedText, type TruncatedTextProps, UpgradePrompt, type UpgradePromptProps, type VersionResponse, type VisibleViewport, copyText, formatBuildInfo, formatUrlForDisplay, isKeyboardOpen, isWideWebViewport, pageScale, resolveRowLook, scaledFrame, shortenCommit, trimTrailingSlash, truncateMiddle, useApiCommit, useCopyToClipboard, useFocusTrap, useIsWideViewport, useListRowTone, useVisibleViewport };
1118
+ export { A4_PAGE, API_COMMIT_SEPARATOR, Accordion, AccordionItem, type AccordionItemProps, type AccordionProps, type AccordionVariant, AppText, type AppTextProps, BUILD_INFO_PREFIX, BottomSheet, type BottomSheetProps, BuildInfoFooter, type BuildInfoFooterProps, COPY_FEEDBACK_MS, ConfirmDialog, ConfirmDialogFocus, type ConfirmDialogProps, CopyStatus, type CopyToClipboard, CopyableId, type CopyableIdProps, DEFAULT_BILLING_ROUTE, type DropdownOption, type DropdownTriggerState, DropdownVariant, ELLIPSIS, FormDialog, type FormDialogProps, HEADER_STACK_BREAKPOINT, Heading, type HeadingLevel, type HeadingProps, LAYOUT_COLLAPSE_BREAKPOINT, LAYOUT_I18N, LAYOUT_TEST_IDS, ListRow, type ListRowProps, type ListRowTone, MIN_TARGET_PX, MODAL_FOOTER_STACK_BELOW, Modal, ModalDropdown, type ModalDropdownProps, type ModalProps, ModalShell, type ModalShellProps, type ModalSize, PageFrame, type PageFrameProps, type PageSize, type RowLook, type RowPalette, RowSelectedStyle, type RowState, type ScaledFrame, ScreenColumn, type ScreenColumnProps, Section, type SectionProps, SectionVariant, SegmentedControl, type SegmentedControlProps, type SegmentedOption, SelectedMarker, SideSheet, type SideSheetProps, StatusBadge, type StatusBadgeProps, StickyPreview, type StickyPreviewProps, TYPE_SCALE_BREAKPOINT, type TabDescriptor, Tabs, TabsCollapsedTrigger, type TabsProps, TextKind, TruncatedText, type TruncatedTextProps, UpgradePrompt, type UpgradePromptProps, type VersionResponse, type VisibleViewport, copyText, formatBuildInfo, formatUrlForDisplay, isKeyboardOpen, isModalFooterStacked, isWideWebViewport, pageScale, resolveRowLook, scaledFrame, shortenCommit, trimTrailingSlash, truncateMiddle, useApiCommit, useCopyToClipboard, useFocusTrap, useIsWideViewport, useListRowTone, useVisibleViewport };
package/dist/index.d.ts CHANGED
@@ -489,7 +489,7 @@ interface ModalProps {
489
489
  testID?: string;
490
490
  /** Accessible name of the dialog. Falls back to `title`, then the neutral "dialog" key. */
491
491
  accessibilityLabel?: string;
492
- /** testID of the control focused on open (web). Default: an autoFocus child, else the first focusable. */
492
+ /** testID focused on open (web); the dialog's own testID focuses the dialog. Default: autoFocus child, else first focusable. */
493
493
  initialFocusTestID?: string;
494
494
  }
495
495
  declare const Modal: ({ visible, onClose, title, children, footer, size, showClose, testID, accessibilityLabel, initialFocusTestID, }: ModalProps) => React.ReactElement;
@@ -521,6 +521,13 @@ interface BottomSheetProps {
521
521
  /** A content-height panel docked to the screen bottom, with a dimmed backdrop and an optional pinned footer. */
522
522
  declare const BottomSheet: ({ visible, onClose, title, children, footer, maxHeightFraction, testID, accessibilityLabel, initialFocusTestID, }: BottomSheetProps) => React.ReactElement;
523
523
 
524
+ /** Which control a {@link ConfirmDialog} focuses on open (web). `None` focuses the dialog itself. */
525
+ declare const enum ConfirmDialogFocus {
526
+ Cancel = "cancel",
527
+ Confirm = "confirm",
528
+ None = "none"
529
+ }
530
+
524
531
  /**
525
532
  * ConfirmDialog — a confirm/cancel popup built ON {@link Modal}, for the "are you sure?" moment.
526
533
  *
@@ -554,10 +561,28 @@ interface ConfirmDialogProps {
554
561
  onCancel: () => void;
555
562
  /** In-flight: Confirm shows a spinner and Cancel is disabled. Default `false`. */
556
563
  busy?: boolean;
564
+ /** Control focused on open (web). Default `Cancel`; never use `Confirm` for a destructive action. */
565
+ initialFocus?: ConfirmDialogFocus;
557
566
  /** Base testID. Default `confirm-dialog`. Confirm is `${testID}-confirm`, Cancel `${testID}-cancel`. */
558
567
  testID?: string;
559
568
  }
560
- declare const ConfirmDialog: ({ visible, title, message, confirmLabel, cancelLabel, destructive, onConfirm, onCancel, busy, testID, }: ConfirmDialogProps) => React.ReactElement;
569
+ declare const ConfirmDialog: ({ visible, title, message, confirmLabel, cancelLabel, destructive, onConfirm, onCancel, busy, initialFocus, testID, }: ConfirmDialogProps) => React.ReactElement;
570
+
571
+ interface FormDialogProps {
572
+ visible: boolean;
573
+ title: string;
574
+ children: React.ReactNode;
575
+ submitLabel: string;
576
+ submitHint: string;
577
+ cancelLabel?: string;
578
+ loading?: boolean;
579
+ onSubmit: () => void;
580
+ onCancel: () => void;
581
+ size?: ModalSize;
582
+ testID?: string;
583
+ }
584
+ /** A centred dialog of form fields with Cancel + Submit; ids `${testID}-dialog`, `-save`, `-cancel`. */
585
+ declare const FormDialog: ({ visible, title, children, submitLabel, submitHint, cancelLabel, loading, onSubmit, onCancel, size, testID, }: FormDialogProps) => React.ReactElement;
561
586
 
562
587
  /**
563
588
  * AccordionVariant — the two visual treatments for an {@link Accordion}.
@@ -910,10 +935,14 @@ declare const LAYOUT_TEST_IDS: {
910
935
  readonly bottomSheet: "bottom-sheet";
911
936
  /** Default base testID for `ConfirmDialog`; Confirm/Cancel are `confirm-dialog-{confirm,cancel}`. */
912
937
  readonly confirmDialog: "confirm-dialog";
938
+ /** Default base testID for `FormDialog`: `form-dialog`, `form-save`, `form-cancel`. */
939
+ readonly formDialog: "form";
913
940
  readonly accordion: "accordion";
914
941
  /** Default testID for the `BuildInfoFooter` caption (`v<version>`). */
915
942
  readonly buildInfoFooter: "build-info-footer";
916
943
  };
944
+ /** Window width (px) below which a dialog footer stacks its actions full width. */
945
+ declare const MODAL_FOOTER_STACK_BELOW = 400;
917
946
  /** Route the UpgradePrompt CTA navigates to by default (the apps' billing settings path). */
918
947
  declare const DEFAULT_BILLING_ROUTE = "/settings/billing";
919
948
  /**
@@ -1023,6 +1052,8 @@ declare const MIN_TARGET_PX = 44;
1023
1052
  * `false`, whatever the width.
1024
1053
  */
1025
1054
  declare function isWideWebViewport(width: number, platformOS: string, breakpoint?: number): boolean;
1055
+ /** Whether a dialog footer stacks its actions full width at this window width. */
1056
+ declare function isModalFooterStacked(width: number): boolean;
1026
1057
 
1027
1058
  declare enum RowSelectedStyle {
1028
1059
  Surface = "surface",
@@ -1084,4 +1115,4 @@ interface RowLook {
1084
1115
  /** Resolves a row's container style and text colours from its selected style and state. */
1085
1116
  declare function resolveRowLook(style: RowSelectedStyle, state: RowState, palette: RowPalette): RowLook;
1086
1117
 
1087
- export { A4_PAGE, API_COMMIT_SEPARATOR, Accordion, AccordionItem, type AccordionItemProps, type AccordionProps, type AccordionVariant, AppText, type AppTextProps, BUILD_INFO_PREFIX, BottomSheet, type BottomSheetProps, BuildInfoFooter, type BuildInfoFooterProps, COPY_FEEDBACK_MS, ConfirmDialog, type ConfirmDialogProps, CopyStatus, type CopyToClipboard, CopyableId, type CopyableIdProps, DEFAULT_BILLING_ROUTE, type DropdownOption, type DropdownTriggerState, DropdownVariant, ELLIPSIS, HEADER_STACK_BREAKPOINT, Heading, type HeadingLevel, type HeadingProps, LAYOUT_COLLAPSE_BREAKPOINT, LAYOUT_I18N, LAYOUT_TEST_IDS, ListRow, type ListRowProps, type ListRowTone, MIN_TARGET_PX, Modal, ModalDropdown, type ModalDropdownProps, type ModalProps, ModalShell, type ModalShellProps, type ModalSize, PageFrame, type PageFrameProps, type PageSize, type RowLook, type RowPalette, RowSelectedStyle, type RowState, type ScaledFrame, ScreenColumn, type ScreenColumnProps, Section, type SectionProps, SectionVariant, SegmentedControl, type SegmentedControlProps, type SegmentedOption, SelectedMarker, SideSheet, type SideSheetProps, StatusBadge, type StatusBadgeProps, StickyPreview, type StickyPreviewProps, TYPE_SCALE_BREAKPOINT, type TabDescriptor, Tabs, TabsCollapsedTrigger, type TabsProps, TextKind, TruncatedText, type TruncatedTextProps, UpgradePrompt, type UpgradePromptProps, type VersionResponse, type VisibleViewport, copyText, formatBuildInfo, formatUrlForDisplay, isKeyboardOpen, isWideWebViewport, pageScale, resolveRowLook, scaledFrame, shortenCommit, trimTrailingSlash, truncateMiddle, useApiCommit, useCopyToClipboard, useFocusTrap, useIsWideViewport, useListRowTone, useVisibleViewport };
1118
+ export { A4_PAGE, API_COMMIT_SEPARATOR, Accordion, AccordionItem, type AccordionItemProps, type AccordionProps, type AccordionVariant, AppText, type AppTextProps, BUILD_INFO_PREFIX, BottomSheet, type BottomSheetProps, BuildInfoFooter, type BuildInfoFooterProps, COPY_FEEDBACK_MS, ConfirmDialog, ConfirmDialogFocus, type ConfirmDialogProps, CopyStatus, type CopyToClipboard, CopyableId, type CopyableIdProps, DEFAULT_BILLING_ROUTE, type DropdownOption, type DropdownTriggerState, DropdownVariant, ELLIPSIS, FormDialog, type FormDialogProps, HEADER_STACK_BREAKPOINT, Heading, type HeadingLevel, type HeadingProps, LAYOUT_COLLAPSE_BREAKPOINT, LAYOUT_I18N, LAYOUT_TEST_IDS, ListRow, type ListRowProps, type ListRowTone, MIN_TARGET_PX, MODAL_FOOTER_STACK_BELOW, Modal, ModalDropdown, type ModalDropdownProps, type ModalProps, ModalShell, type ModalShellProps, type ModalSize, PageFrame, type PageFrameProps, type PageSize, type RowLook, type RowPalette, RowSelectedStyle, type RowState, type ScaledFrame, ScreenColumn, type ScreenColumnProps, Section, type SectionProps, SectionVariant, SegmentedControl, type SegmentedControlProps, type SegmentedOption, SelectedMarker, SideSheet, type SideSheetProps, StatusBadge, type StatusBadgeProps, StickyPreview, type StickyPreviewProps, TYPE_SCALE_BREAKPOINT, type TabDescriptor, Tabs, TabsCollapsedTrigger, type TabsProps, TextKind, TruncatedText, type TruncatedTextProps, UpgradePrompt, type UpgradePromptProps, type VersionResponse, type VisibleViewport, copyText, formatBuildInfo, formatUrlForDisplay, isKeyboardOpen, isModalFooterStacked, isWideWebViewport, pageScale, resolveRowLook, scaledFrame, shortenCommit, trimTrailingSlash, truncateMiddle, useApiCommit, useCopyToClipboard, useFocusTrap, useIsWideViewport, useListRowTone, useVisibleViewport };
package/dist/index.js CHANGED
@@ -109,10 +109,13 @@ var LAYOUT_TEST_IDS = {
109
109
  bottomSheet: "bottom-sheet",
110
110
  /** Default base testID for `ConfirmDialog`; Confirm/Cancel are `confirm-dialog-{confirm,cancel}`. */
111
111
  confirmDialog: "confirm-dialog",
112
+ /** Default base testID for `FormDialog`: `form-dialog`, `form-save`, `form-cancel`. */
113
+ formDialog: "form",
112
114
  accordion: "accordion",
113
115
  /** Default testID for the `BuildInfoFooter` caption (`v<version>`). */
114
116
  buildInfoFooter: "build-info-footer"
115
117
  };
118
+ var MODAL_FOOTER_STACK_BELOW = 400;
116
119
  var DEFAULT_BILLING_ROUTE = "/settings/billing";
117
120
  var LAYOUT_I18N = {
118
121
  /** Placeholder shown by `ModalDropdown` when no option matches the current value. */
@@ -182,6 +185,9 @@ var WEB_PLATFORM = "web";
182
185
  function isWideWebViewport(width, platformOS, breakpoint = LAYOUT_COLLAPSE_BREAKPOINT) {
183
186
  return platformOS === WEB_PLATFORM && width >= breakpoint;
184
187
  }
188
+ function isModalFooterStacked(width) {
189
+ return width < MODAL_FOOTER_STACK_BELOW;
190
+ }
185
191
 
186
192
  // src/hooks/useIsWideViewport.ts
187
193
  function useIsWideViewport(breakpoint = LAYOUT_COLLAPSE_BREAKPOINT) {
@@ -420,8 +426,14 @@ function getFocusableElements(container) {
420
426
  function savePreviousFocus() {
421
427
  return document.activeElement instanceof HTMLElement ? document.activeElement : null;
422
428
  }
429
+ var MAX_ATTACH_FRAMES = 10;
430
+ function findNamed(domNode, initialFocusTestID) {
431
+ if (initialFocusTestID === void 0) return null;
432
+ const selector = `[data-testid="${initialFocusTestID}"]`;
433
+ return domNode.matches(selector) ? domNode : domNode.querySelector(selector);
434
+ }
423
435
  function focusInitial(domNode, initialFocusTestID) {
424
- const named = initialFocusTestID === void 0 ? null : domNode.querySelector(`[data-testid="${initialFocusTestID}"]`);
436
+ const named = findNamed(domNode, initialFocusTestID);
425
437
  if (named) {
426
438
  named.focus();
427
439
  return;
@@ -455,15 +467,29 @@ function useFocusTrap(containerRef, enabled, initialFocusTestID) {
455
467
  const previousFocusRef = React14.useRef(null);
456
468
  React14.useEffect(() => {
457
469
  if (reactNative.Platform.OS !== "web" || !enabled) return;
458
- const domNode = containerRef.current;
459
- if (!domNode) return;
460
- const previous = savePreviousFocus();
461
- previousFocusRef.current = previous !== null && domNode.contains(previous) ? null : previous;
462
- queueMicrotask(() => focusInitial(domNode, initialFocusTestID));
463
- const listener = (e) => handleKeyDown(domNode, e);
464
- domNode.addEventListener("keydown", listener);
470
+ let domNode = null;
471
+ let frame = 0;
472
+ let attempts = 0;
473
+ const listener = (e) => {
474
+ if (domNode) handleKeyDown(domNode, e);
475
+ };
476
+ const attach = () => {
477
+ const node = containerRef.current;
478
+ if (!node) {
479
+ attempts += 1;
480
+ if (attempts <= MAX_ATTACH_FRAMES) frame = requestAnimationFrame(attach);
481
+ return;
482
+ }
483
+ domNode = node;
484
+ const previous = savePreviousFocus();
485
+ previousFocusRef.current = previous !== null && node.contains(previous) ? null : previous;
486
+ queueMicrotask(() => focusInitial(node, initialFocusTestID));
487
+ node.addEventListener("keydown", listener);
488
+ };
489
+ attach();
465
490
  return () => {
466
- domNode.removeEventListener("keydown", listener);
491
+ cancelAnimationFrame(frame);
492
+ domNode?.removeEventListener("keydown", listener);
467
493
  previousFocusRef.current?.focus();
468
494
  previousFocusRef.current = null;
469
495
  };
@@ -485,6 +511,7 @@ var DIALOG_RADIUS = 12;
485
511
  var DIALOG_PADDING = 16;
486
512
  var HEADER_GAP = 12;
487
513
  var FOOTER_MARGIN = 16;
514
+ var FOOTER_GAP = 12;
488
515
  var HEADER_MARGIN = 12;
489
516
  var DIALOG_MAX_HEIGHT = "90%";
490
517
  var PANEL_ENTER_SCALE = 0.96;
@@ -501,7 +528,9 @@ var styles6 = reactNative.StyleSheet.create({
501
528
  // react-native-web, which is why the fade is driven by `Animated` instead. `pointerEvents` lives
502
529
  // in style (not the deprecated prop) so taps fall through to the sibling tap-catcher below.
503
530
  scrim: { backgroundColor: uiFeedback.MODAL_OVERLAY_COLOR, pointerEvents: "none" },
531
+ backdrop: { zIndex: 0 },
504
532
  dialog: {
533
+ zIndex: 1,
505
534
  width: "100%",
506
535
  borderRadius: DIALOG_RADIUS,
507
536
  padding: DIALOG_PADDING,
@@ -516,8 +545,27 @@ var styles6 = reactNative.StyleSheet.create({
516
545
  },
517
546
  // Occupies the header's leading space so the ✕ pins to the trailing edge even without a title.
518
547
  titleWrap: { flex: 1 },
519
- footer: { marginTop: FOOTER_MARGIN }
548
+ footerRow: {
549
+ marginTop: FOOTER_MARGIN,
550
+ flexDirection: "row",
551
+ flexWrap: "wrap",
552
+ justifyContent: "flex-end",
553
+ alignItems: "center",
554
+ columnGap: FOOTER_GAP,
555
+ rowGap: FOOTER_GAP
556
+ },
557
+ footerStack: {
558
+ marginTop: FOOTER_MARGIN,
559
+ flexDirection: "column-reverse",
560
+ alignItems: "stretch",
561
+ rowGap: FOOTER_GAP
562
+ }
520
563
  });
564
+ var ModalFooter = ({ children, testID }) => {
565
+ const { width } = reactNative.useWindowDimensions();
566
+ const style = isModalFooterStacked(width) ? styles6.footerStack : styles6.footerRow;
567
+ return /* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style, testID, children });
568
+ };
521
569
  var Modal = ({
522
570
  visible,
523
571
  onClose,
@@ -545,6 +593,7 @@ var Modal = ({
545
593
  [theme.colors.surface, size]
546
594
  );
547
595
  const hasHeader = title !== void 0 || showClose;
596
+ const focusesDialog = initialFocusTestID === testID;
548
597
  const hardwareBackClose = reactNative.Platform.OS === "web" ? void 0 : onClose;
549
598
  return /* @__PURE__ */ jsxRuntime.jsx(reactNative.Modal, { transparent: true, visible: mounted, onRequestClose: hardwareBackClose, children: /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: styles6.overlay, children: [
550
599
  /* @__PURE__ */ jsxRuntime.jsx(
@@ -553,19 +602,6 @@ var Modal = ({
553
602
  style: [reactNative.StyleSheet.absoluteFill, styles6.scrim, { opacity: backdrop.style.opacity }]
554
603
  }
555
604
  ),
556
- /* @__PURE__ */ jsxRuntime.jsx(
557
- reactNative.TouchableOpacity,
558
- {
559
- accessible: true,
560
- accessibilityHint: t(LAYOUT_I18N.dismissDropdownHint),
561
- accessibilityLabel: t(LAYOUT_I18N.dismissDropdown),
562
- accessibilityRole: "button",
563
- activeOpacity: 1,
564
- style: reactNative.StyleSheet.absoluteFill,
565
- testID: `${testID}-backdrop`,
566
- onPress: onClose
567
- }
568
- ),
569
605
  /* @__PURE__ */ jsxRuntime.jsxs(
570
606
  reactNative.Animated.View,
571
607
  {
@@ -574,6 +610,7 @@ var Modal = ({
574
610
  "aria-label": accessibleName,
575
611
  role: "dialog",
576
612
  style: [dialogStyle, panel.style],
613
+ tabIndex: focusesDialog ? -1 : void 0,
577
614
  testID,
578
615
  children: [
579
616
  hasHeader ? /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: styles6.headerRow, children: [
@@ -594,9 +631,23 @@ var Modal = ({
594
631
  ) : null
595
632
  ] }) : null,
596
633
  /* @__PURE__ */ jsxRuntime.jsx(reactNative.ScrollView, { children }),
597
- footer !== void 0 ? /* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style: styles6.footer, children: footer }) : null
634
+ footer !== void 0 ? /* @__PURE__ */ jsxRuntime.jsx(ModalFooter, { testID: `${testID}-footer`, children: footer }) : null
598
635
  ]
599
636
  }
637
+ ),
638
+ /* @__PURE__ */ jsxRuntime.jsx(
639
+ reactNative.TouchableOpacity,
640
+ {
641
+ accessible: true,
642
+ accessibilityHint: t(LAYOUT_I18N.dismissDropdownHint),
643
+ accessibilityLabel: t(LAYOUT_I18N.dismissDropdown),
644
+ accessibilityRole: "button",
645
+ activeOpacity: 1,
646
+ style: [reactNative.StyleSheet.absoluteFill, styles6.backdrop],
647
+ focusable: false,
648
+ testID: `${testID}-backdrop`,
649
+ onPress: onClose
650
+ }
600
651
  )
601
652
  ] }) });
602
653
  };
@@ -2024,12 +2075,18 @@ var BottomSheet = ({
2024
2075
  )
2025
2076
  ] }) });
2026
2077
  };
2078
+
2079
+ // src/Modal/ConfirmDialogFocus.ts
2080
+ var ConfirmDialogFocus = /* @__PURE__ */ ((ConfirmDialogFocus2) => {
2081
+ ConfirmDialogFocus2["Cancel"] = "cancel";
2082
+ ConfirmDialogFocus2["Confirm"] = "confirm";
2083
+ ConfirmDialogFocus2["None"] = "none";
2084
+ return ConfirmDialogFocus2;
2085
+ })(ConfirmDialogFocus || {});
2027
2086
  var MESSAGE_FONT_SIZE2 = 14;
2028
2087
  var MESSAGE_LINE_HEIGHT = 20;
2029
- var BUTTON_GAP = 12;
2030
2088
  var styles18 = reactNative.StyleSheet.create({
2031
- message: { fontSize: MESSAGE_FONT_SIZE2, lineHeight: MESSAGE_LINE_HEIGHT },
2032
- footer: { flexDirection: "row", justifyContent: "flex-end", columnGap: BUTTON_GAP }
2089
+ message: { fontSize: MESSAGE_FONT_SIZE2, lineHeight: MESSAGE_LINE_HEIGHT }
2033
2090
  });
2034
2091
  var ConfirmDialog = ({
2035
2092
  visible,
@@ -2041,12 +2098,18 @@ var ConfirmDialog = ({
2041
2098
  onConfirm,
2042
2099
  onCancel,
2043
2100
  busy = false,
2101
+ initialFocus = "cancel" /* Cancel */,
2044
2102
  testID = LAYOUT_TEST_IDS.confirmDialog
2045
2103
  }) => {
2046
2104
  const { theme, t } = uiFeedback.useUi();
2047
2105
  const resolvedConfirm = confirmLabel ?? t(LAYOUT_I18N.confirm);
2048
2106
  const resolvedCancel = cancelLabel ?? t(LAYOUT_I18N.cancel);
2049
- const footer = /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: styles18.footer, children: [
2107
+ const focusTestID = {
2108
+ ["cancel" /* Cancel */]: `${testID}-cancel`,
2109
+ ["confirm" /* Confirm */]: `${testID}-confirm`,
2110
+ ["none" /* None */]: testID
2111
+ };
2112
+ const footer = /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
2050
2113
  /* @__PURE__ */ jsxRuntime.jsx(
2051
2114
  uiButtons.Button,
2052
2115
  {
@@ -2076,6 +2139,7 @@ var ConfirmDialog = ({
2076
2139
  Modal,
2077
2140
  {
2078
2141
  footer,
2142
+ initialFocusTestID: focusTestID[initialFocus],
2079
2143
  showClose: false,
2080
2144
  size: "sm",
2081
2145
  testID,
@@ -2086,6 +2150,87 @@ var ConfirmDialog = ({
2086
2150
  }
2087
2151
  );
2088
2152
  };
2153
+ var FIELD_SELECTOR = "input:not([disabled]), textarea:not([disabled]), select:not([disabled])";
2154
+ var FORM_STYLE = { display: "contents" };
2155
+ var WebFormBody = ({ children, visible, onSubmit }) => {
2156
+ const formRef = React14.useRef(null);
2157
+ React14.useEffect(() => {
2158
+ if (reactNative.Platform.OS !== "web" || !visible) return;
2159
+ formRef.current?.querySelector(FIELD_SELECTOR)?.focus();
2160
+ }, [visible]);
2161
+ const handleSubmit = React14.useCallback(
2162
+ (event) => {
2163
+ event.preventDefault();
2164
+ onSubmit();
2165
+ },
2166
+ [onSubmit]
2167
+ );
2168
+ if (reactNative.Platform.OS !== "web") return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children });
2169
+ return React14__default.default.createElement(
2170
+ "form",
2171
+ { ref: formRef, noValidate: true, style: FORM_STYLE, onSubmit: handleSubmit },
2172
+ children,
2173
+ React14__default.default.createElement("button", { type: "submit", hidden: true, tabIndex: -1, "aria-hidden": true })
2174
+ );
2175
+ };
2176
+ var FormDialogActions = (props) => /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
2177
+ /* @__PURE__ */ jsxRuntime.jsx(
2178
+ uiButtons.Button,
2179
+ {
2180
+ accessibilityHint: props.cancelHint,
2181
+ accessibilityLabel: props.cancelLabel,
2182
+ disabled: props.loading,
2183
+ label: props.cancelLabel,
2184
+ testID: `${props.testID}-cancel`,
2185
+ variant: "secondary",
2186
+ onPress: props.onCancel
2187
+ }
2188
+ ),
2189
+ /* @__PURE__ */ jsxRuntime.jsx(
2190
+ uiButtons.Button,
2191
+ {
2192
+ accessibilityHint: props.submitHint,
2193
+ accessibilityLabel: props.submitLabel,
2194
+ label: props.submitLabel,
2195
+ loading: props.loading,
2196
+ testID: `${props.testID}-save`,
2197
+ variant: "primary",
2198
+ onPress: props.onSubmit
2199
+ }
2200
+ )
2201
+ ] });
2202
+ var FormDialog = ({
2203
+ visible,
2204
+ title,
2205
+ children,
2206
+ submitLabel,
2207
+ submitHint,
2208
+ cancelLabel,
2209
+ loading = false,
2210
+ onSubmit,
2211
+ onCancel,
2212
+ size = "md",
2213
+ testID = LAYOUT_TEST_IDS.formDialog
2214
+ }) => {
2215
+ const { t } = uiFeedback.useUi();
2216
+ const submit = React14.useCallback(() => {
2217
+ if (!loading) onSubmit();
2218
+ }, [loading, onSubmit]);
2219
+ const footer = /* @__PURE__ */ jsxRuntime.jsx(
2220
+ FormDialogActions,
2221
+ {
2222
+ cancelHint: t(LAYOUT_I18N.cancelHint),
2223
+ cancelLabel: cancelLabel ?? t(LAYOUT_I18N.cancel),
2224
+ loading,
2225
+ submitHint,
2226
+ submitLabel,
2227
+ testID,
2228
+ onCancel,
2229
+ onSubmit: submit
2230
+ }
2231
+ );
2232
+ return /* @__PURE__ */ jsxRuntime.jsx(Modal, { footer, size, testID: `${testID}-dialog`, title, visible, onClose: onCancel, children: /* @__PURE__ */ jsxRuntime.jsx(WebFormBody, { visible, onSubmit: submit, children }) });
2233
+ };
2089
2234
  var AccordionContext = React14.createContext(null);
2090
2235
  function useAccordionContext() {
2091
2236
  const value = React14.useContext(AccordionContext);
@@ -2964,11 +3109,13 @@ exports.BottomSheet = BottomSheet;
2964
3109
  exports.BuildInfoFooter = BuildInfoFooter;
2965
3110
  exports.COPY_FEEDBACK_MS = COPY_FEEDBACK_MS;
2966
3111
  exports.ConfirmDialog = ConfirmDialog;
3112
+ exports.ConfirmDialogFocus = ConfirmDialogFocus;
2967
3113
  exports.CopyStatus = CopyStatus;
2968
3114
  exports.CopyableId = CopyableId;
2969
3115
  exports.DEFAULT_BILLING_ROUTE = DEFAULT_BILLING_ROUTE;
2970
3116
  exports.DropdownVariant = DropdownVariant;
2971
3117
  exports.ELLIPSIS = ELLIPSIS;
3118
+ exports.FormDialog = FormDialog;
2972
3119
  exports.HEADER_STACK_BREAKPOINT = HEADER_STACK_BREAKPOINT;
2973
3120
  exports.Heading = Heading;
2974
3121
  exports.LAYOUT_COLLAPSE_BREAKPOINT = LAYOUT_COLLAPSE_BREAKPOINT;
@@ -2976,6 +3123,7 @@ exports.LAYOUT_I18N = LAYOUT_I18N;
2976
3123
  exports.LAYOUT_TEST_IDS = LAYOUT_TEST_IDS;
2977
3124
  exports.ListRow = ListRow;
2978
3125
  exports.MIN_TARGET_PX = MIN_TARGET_PX;
3126
+ exports.MODAL_FOOTER_STACK_BELOW = MODAL_FOOTER_STACK_BELOW;
2979
3127
  exports.Modal = Modal;
2980
3128
  exports.ModalDropdown = ModalDropdown;
2981
3129
  exports.ModalShell = ModalShell;
@@ -2999,6 +3147,7 @@ exports.copyText = copyText;
2999
3147
  exports.formatBuildInfo = formatBuildInfo;
3000
3148
  exports.formatUrlForDisplay = formatUrlForDisplay;
3001
3149
  exports.isKeyboardOpen = isKeyboardOpen;
3150
+ exports.isModalFooterStacked = isModalFooterStacked;
3002
3151
  exports.isWideWebViewport = isWideWebViewport;
3003
3152
  exports.pageScale = pageScale;
3004
3153
  exports.resolveRowLook = resolveRowLook;