@cboxdk/cbox-ui 0.19.3 → 0.19.4

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.ts CHANGED
@@ -1697,7 +1697,8 @@ declare function SheetClose({ onClick, ...props }: ButtonProps): react_jsx_runti
1697
1697
  * drags down to close. Cbox never centres a modal over the page; forms and confirmations open here.
1698
1698
  *
1699
1699
  * - Focus moves in on open: to an element marked `autoFocus` or `data-autofocus`, else the first
1700
- * field in the body, else the close button (never a destructive footer action).
1700
+ * field in the body, else the close button (never a destructive footer action). On touch a text
1701
+ * field is not focused (the keyboard would cover the sheet); the panel takes focus instead.
1701
1702
  * - Tab and Shift+Tab stay inside; everything behind is `inert` and hidden from assistive
1702
1703
  * technology; the page behind does not scroll (iOS included).
1703
1704
  * - Escape closes it (unless a control inside handled Escape first, an open combobox say), as do
package/dist/index.js CHANGED
@@ -1821,6 +1821,8 @@ var TABBABLE = [
1821
1821
  '[contenteditable]:not([contenteditable="false"])',
1822
1822
  '[tabindex]:not([tabindex="-1"])'
1823
1823
  ].join(",");
1824
+ var TOUCH = "(pointer: coarse)";
1825
+ var TEXT_ENTRY = 'textarea, [contenteditable="true"], input:not([type="checkbox"]):not([type="radio"]):not([type="button"]):not([type="submit"]):not([type="range"]):not([type="color"]):not([type="file"])';
1824
1826
  function tabbables(root) {
1825
1827
  const all = Array.from(root.querySelectorAll(TABBABLE)).filter((element) => element.tabIndex >= 0 && element.closest("[hidden], [inert]") === null);
1826
1828
  const checkedGroups = new Set(all.filter((element) => element instanceof HTMLInputElement && element.type === "radio" && element.checked).map((element) => element.name));
@@ -1904,10 +1906,17 @@ function Sheet({ open, onOpenChange, title, description, footer, size = "md", di
1904
1906
  useIsoLayoutEffect2(() => {
1905
1907
  if (!open || panel.current === null) return;
1906
1908
  const root = panel.current;
1907
- if (root.contains(document.activeElement)) return;
1909
+ const touch = matches(TOUCH);
1910
+ const active = document.activeElement;
1911
+ if (root.contains(active)) {
1912
+ if (touch && active instanceof HTMLElement && active.matches(TEXT_ENTRY)) root.focus({ preventScroll: true });
1913
+ return;
1914
+ }
1908
1915
  const marked = root.querySelector("[data-autofocus]");
1909
1916
  const field = body.current?.querySelector('input:not([disabled]):not([type="hidden"]), textarea:not([disabled]), select:not([disabled]), [role="combobox"]');
1910
- (marked ?? field ?? closeButton.current ?? root).focus({ preventScroll: true });
1917
+ const wanted = marked ?? field;
1918
+ if (touch && wanted?.matches(TEXT_ENTRY)) root.focus({ preventScroll: true });
1919
+ else (wanted ?? closeButton.current ?? root).focus({ preventScroll: true });
1911
1920
  }, [open]);
1912
1921
  useEffect(() => {
1913
1922
  if (!open) return;