@dloizides/ui-forms 1.42.0 → 1.42.1

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
@@ -1491,8 +1491,8 @@ interface DropdownFrame {
1491
1491
  }
1492
1492
  /** Opens below when the list fits there, else on whichever side has more room. */
1493
1493
  declare function placeDropdown(anchor: AnchorRect, panelHeight: number, viewportHeight: number): DropdownPlacement;
1494
- /** The window frame for the list next to `anchor`, on the side `placeDropdown` picks. */
1495
- declare function dropdownFrame(anchor: AnchorRect, panelHeight: number, viewportHeight: number): DropdownFrame;
1494
+ /** The window frame for the list next to `anchor`, kept inside the viewport; `preferBelow` always opens under the field. */
1495
+ declare function dropdownFrame(anchor: AnchorRect, panelHeight: number, viewportHeight: number, preferBelow?: boolean): DropdownFrame;
1496
1496
  /** Widens a narrow anchor's list to `minWidth` (default a readable width) and keeps it inside the viewport. */
1497
1497
  declare function fitDropdownWidth(frame: DropdownFrame, viewportWidth: number, minWidth?: number): DropdownFrame;
1498
1498
 
package/dist/index.d.ts CHANGED
@@ -1491,8 +1491,8 @@ interface DropdownFrame {
1491
1491
  }
1492
1492
  /** Opens below when the list fits there, else on whichever side has more room. */
1493
1493
  declare function placeDropdown(anchor: AnchorRect, panelHeight: number, viewportHeight: number): DropdownPlacement;
1494
- /** The window frame for the list next to `anchor`, on the side `placeDropdown` picks. */
1495
- declare function dropdownFrame(anchor: AnchorRect, panelHeight: number, viewportHeight: number): DropdownFrame;
1494
+ /** The window frame for the list next to `anchor`, kept inside the viewport; `preferBelow` always opens under the field. */
1495
+ declare function dropdownFrame(anchor: AnchorRect, panelHeight: number, viewportHeight: number, preferBelow?: boolean): DropdownFrame;
1496
1496
  /** Widens a narrow anchor's list to `minWidth` (default a readable width) and keeps it inside the viewport. */
1497
1497
  declare function fitDropdownWidth(frame: DropdownFrame, viewportWidth: number, minWidth?: number): DropdownFrame;
1498
1498
 
package/dist/index.js CHANGED
@@ -2396,7 +2396,7 @@ function PickerDialog({ testID, sheet, onDismiss, children }) {
2396
2396
  event.preventDefault();
2397
2397
  (event.shiftKey ? last : first).focus();
2398
2398
  };
2399
- const shape = sheet ? { borderTopLeftRadius: SHEET_RADIUS, borderTopRightRadius: SHEET_RADIUS, maxHeight: SHEET_MAX_HEIGHT, overflowY: "auto" } : { borderRadius: RADIUS, boxShadow: `0 12px 32px ${colors.border}` };
2399
+ const shape = sheet ? { borderTopLeftRadius: SHEET_RADIUS, borderTopRightRadius: SHEET_RADIUS, width: "100%", maxHeight: SHEET_MAX_HEIGHT, overflowY: "auto" } : { borderRadius: RADIUS, boxShadow: `0 12px 32px ${colors.border}` };
2400
2400
  const style = { boxSizing: "border-box", padding: PAD, background: colors.surface, color: colors.text, border: `1px solid ${colors.border}`, fontFamily: "inherit", ...shape };
2401
2401
  return /* @__PURE__ */ jsxRuntime.jsx("div", { ref, "data-testid": testID, "data-variant": sheet ? "sheet" : "popover", style, onKeyDown, children });
2402
2402
  }
@@ -2423,23 +2423,26 @@ function placeDropdown(anchor, panelHeight, viewportHeight) {
2423
2423
  if (roomBelow >= panelHeight) return "below" /* Below */;
2424
2424
  return anchor.y > roomBelow ? "above" /* Above */ : "below" /* Below */;
2425
2425
  }
2426
- function dropdownFrame(anchor, panelHeight, viewportHeight) {
2427
- const placement = placeDropdown(anchor, panelHeight, viewportHeight);
2426
+ function clampTop(top, panelHeight, viewportHeight) {
2427
+ return Math.max(EDGE, Math.min(top, viewportHeight - panelHeight - EDGE));
2428
+ }
2429
+ function dropdownFrame(anchor, panelHeight, viewportHeight, preferBelow = false) {
2430
+ const placement = preferBelow ? "below" /* Below */ : placeDropdown(anchor, panelHeight, viewportHeight);
2428
2431
  const base = { placement, left: anchor.x, width: anchor.width };
2429
- if (placement === "above" /* Above */) return { ...base, bottom: viewportHeight - anchor.y };
2430
- return { ...base, top: anchor.y + anchor.height };
2432
+ if (placement === "above" /* Above */) return { ...base, bottom: viewportHeight - clampTop(anchor.y - panelHeight, panelHeight, viewportHeight) - panelHeight };
2433
+ return { ...base, top: clampTop(anchor.y + anchor.height, panelHeight, viewportHeight) };
2431
2434
  }
2432
2435
  function fitDropdownWidth(frame, viewportWidth, minWidth = MIN_PANEL_WIDTH) {
2433
2436
  const width = Math.max(frame.width, Math.min(minWidth, viewportWidth - EDGE - EDGE));
2434
2437
  const left = Math.max(EDGE, Math.min(frame.left, viewportWidth - width - EDGE));
2435
2438
  return { ...frame, width, left: frame.width >= width ? frame.left : left };
2436
2439
  }
2437
- function DropdownSurface({ progress, translateY, anchorRef, onDismiss, closeLabel, closeHint, testID, children, minWidth, scale, accessibilityLabel }) {
2440
+ function DropdownSurface({ progress, translateY, anchorRef, onDismiss, closeLabel, closeHint, testID, children, minWidth, scale, accessibilityLabel, preferBelow = false }) {
2438
2441
  const { height: viewportHeight, width: viewportWidth } = reactNative.useWindowDimensions();
2439
2442
  const anchor = useAnchorRect2(anchorRef);
2440
2443
  const [panelHeight, setPanelHeight] = React37.useState(0);
2441
2444
  const onLayout = React37.useCallback((event) => setPanelHeight(event.nativeEvent.layout.height), []);
2442
- const frame = anchor === null ? null : fitDropdownWidth(dropdownFrame(anchor, panelHeight, viewportHeight), viewportWidth, minWidth);
2445
+ const frame = anchor === null ? null : fitDropdownWidth(dropdownFrame(anchor, panelHeight, viewportHeight, preferBelow), viewportWidth, minWidth);
2443
2446
  const place = frame === null ? null : { left: frame.left, width: frame.width, top: frame.top, bottom: frame.bottom };
2444
2447
  return /* @__PURE__ */ jsxRuntime.jsxs(reactNative.Modal, { transparent: true, visible: true, animationType: "none", "aria-label": accessibilityLabel, onRequestClose: onDismiss, children: [
2445
2448
  /* @__PURE__ */ jsxRuntime.jsx(reactNative.Pressable, { accessibilityHint: closeHint, accessibilityLabel: closeLabel, accessibilityRole: "button", style: reactNative.StyleSheet.absoluteFill, testID: `${testID}-backdrop`, onPress: onDismiss }),
@@ -2453,11 +2456,12 @@ var styles15 = reactNative.StyleSheet.create({
2453
2456
  function SheetSurface({ translateY, onDismiss, closeLabel, closeHint, testID, children, progress, scale, accessibilityLabel }) {
2454
2457
  return /* @__PURE__ */ jsxRuntime.jsx(reactNative.Modal, { transparent: true, visible: true, animationType: "none", "aria-label": accessibilityLabel, onRequestClose: onDismiss, children: /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: styles16.backdrop, children: [
2455
2458
  /* @__PURE__ */ jsxRuntime.jsx(reactNative.Pressable, { accessibilityHint: closeHint, accessibilityLabel: closeLabel, accessibilityRole: "button", style: reactNative.StyleSheet.absoluteFill, testID: `${testID}-backdrop`, onPress: onDismiss }),
2456
- /* @__PURE__ */ jsxRuntime.jsx(reactNative.Animated.View, { style: [{ transform: scale === void 0 ? [{ translateY }] : [{ translateY }, { scale }] }, progress === void 0 ? null : { opacity: progress }], children })
2459
+ /* @__PURE__ */ jsxRuntime.jsx(reactNative.Animated.View, { testID: `${testID}-sheet`, style: [styles16.sheet, { transform: scale === void 0 ? [{ translateY }] : [{ translateY }, { scale }] }, progress === void 0 ? null : { opacity: progress }], children })
2457
2460
  ] }) });
2458
2461
  }
2459
2462
  var styles16 = reactNative.StyleSheet.create({
2460
- backdrop: { flex: 1, justifyContent: "flex-end" }
2463
+ backdrop: { flex: 1, justifyContent: "flex-end" },
2464
+ sheet: { width: "100%", alignSelf: "stretch" }
2461
2465
  });
2462
2466
  function useReducedMotion() {
2463
2467
  const [reduced, setReduced] = React37.useState(false);
@@ -2639,9 +2643,9 @@ function PickerSurface({ anchorRef, phone, minWidth, label, testID, onDismiss, c
2639
2643
  const { progress, scale, still } = useOpenProgress();
2640
2644
  const body = /* @__PURE__ */ jsxRuntime.jsx(PickerDialog, { sheet: phone, testID, onDismiss, children });
2641
2645
  if (phone) {
2642
- return /* @__PURE__ */ jsxRuntime.jsx(SheetSurface, { accessibilityLabel: label, closeHint: labels.cancelHint, closeLabel: labels.cancel, progress, scale, testID, translateY: still, onDismiss, children: body });
2646
+ return /* @__PURE__ */ jsxRuntime.jsx(SheetSurface, { accessibilityLabel: label, closeHint: labels.cancelHint, closeLabel: labels.cancel, progress, testID, translateY: still, onDismiss, children: body });
2643
2647
  }
2644
- return /* @__PURE__ */ jsxRuntime.jsx(DropdownSurface, { accessibilityLabel: label, anchorRef, closeHint: labels.cancelHint, closeLabel: labels.cancel, minWidth, progress, scale, testID, translateY: still, onDismiss, children: body });
2648
+ return /* @__PURE__ */ jsxRuntime.jsx(DropdownSurface, { accessibilityLabel: label, anchorRef, closeHint: labels.cancelHint, closeLabel: labels.cancel, minWidth, preferBelow: true, progress, scale, testID, translateY: still, onDismiss, children: body });
2645
2649
  }
2646
2650
 
2647
2651
  // src/DatePicker/utils/calendarKeys.ts
@@ -2706,7 +2710,7 @@ var REGULAR = 400;
2706
2710
  function DayCell({ iso, state, testID, label, hint, onPick, onKey }) {
2707
2711
  const colors = usePickerColors();
2708
2712
  const { inRange, isEnd, isToday, enabled, focusable } = state;
2709
- const cellStyle = { width: DAY_CELL_PX, height: DAY_CELL_PX, background: inRange && !isEnd ? colors.tint : "transparent" };
2713
+ const cellStyle = { width: DAY_CELL_PX, height: DAY_CELL_PX, flexShrink: 0, background: inRange && !isEnd ? colors.tint : "transparent" };
2710
2714
  const textColor = isEnd ? colors.onBrand : enabled ? colors.text : colors.textSecondary;
2711
2715
  const buttonStyle = {
2712
2716
  width: DAY_CELL_PX,
@@ -2829,7 +2833,7 @@ var CAPTION_FONT = 15;
2829
2833
  var WEEKDAY_FONT = 12;
2830
2834
  var BOLD2 = 700;
2831
2835
  var ROW = { display: "flex" };
2832
- var EMPTY = { width: DAY_CELL_PX, height: DAY_CELL_PX };
2836
+ var EMPTY = { width: DAY_CELL_PX, height: DAY_CELL_PX, flexShrink: 0 };
2833
2837
  var FALLBACK = { year: 1970, month: 1};
2834
2838
  function MonthGrid({ month, selection, focusedDay, bounds, testID, onPick, onKey, showCaption = false, motion }) {
2835
2839
  const { labels, locale, today, firstDay } = useDatePickerConfig();
@@ -2946,8 +2950,11 @@ function useIsPhone() {
2946
2950
  function useReturnFocus(open, target) {
2947
2951
  const wasOpen = React37.useRef(open);
2948
2952
  React37.useEffect(() => {
2949
- if (wasOpen.current && !open) target.current?.focus();
2953
+ const closed = wasOpen.current && !open;
2950
2954
  wasOpen.current = open;
2955
+ if (!closed) return void 0;
2956
+ const timer = setTimeout(() => target.current?.focus(), 0);
2957
+ return () => clearTimeout(timer);
2951
2958
  }, [open, target]);
2952
2959
  }
2953
2960
  function useTypedDate({ value, onChange, bounds, format, onError, rangeMessage }) {
@@ -3000,6 +3007,17 @@ function useTypedDate({ value, onChange, bounds, format, onError, rangeMessage }
3000
3007
  isReady
3001
3008
  };
3002
3009
  }
3010
+
3011
+ // src/DatePicker/utils/fieldWidth.ts
3012
+ var FONT_PX = 14;
3013
+ var GLYPH_EM = 0.62;
3014
+ var PAD_INLINE = 12;
3015
+ var BORDER = 1;
3016
+ var PLACEHOLDER_CHARS = 15;
3017
+ function closedFieldMinWidth(text, iconRoom) {
3018
+ const chars = Math.max(text.length, PLACEHOLDER_CHARS);
3019
+ return Math.ceil(chars * FONT_PX * GLYPH_EM) + PAD_INLINE + iconRoom + BORDER + BORDER;
3020
+ }
3003
3021
  var SINGLE_PICKER_WIDTH = 340;
3004
3022
  var ICON_ROOM = 48;
3005
3023
  var ICON_SLOT = { position: "absolute", right: 2, top: 0, bottom: 0, display: "flex", alignItems: "center" };
@@ -3033,7 +3051,7 @@ function DatePickerInput({ fieldProps, context, onTypedError }) {
3033
3051
  event.preventDefault();
3034
3052
  if (typed.isReady()) onSubmit();
3035
3053
  };
3036
- return /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { ref: anchorRef, style: anchorStyles.wrap, children: [
3054
+ return /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { ref: anchorRef, style: [anchorStyles.wrap, { minWidth: closedFieldMinWidth(typed.display, ICON_ROOM) }], testID: `${testID}-anchor`, children: [
3037
3055
  /* @__PURE__ */ jsxRuntime.jsx(
3038
3056
  "input",
3039
3057
  {