@dloizides/ui-forms 1.27.0 → 1.28.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/CHANGELOG.md +14 -0
- package/dist/index.d.mts +18 -4
- package/dist/index.d.ts +18 -4
- package/dist/index.js +73 -19
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +73 -20
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -609,18 +609,23 @@ function readAnchorRect(ref) {
|
|
|
609
609
|
const r = node.getBoundingClientRect();
|
|
610
610
|
return { top: r.top, left: r.left, width: r.width, bottom: r.bottom };
|
|
611
611
|
}
|
|
612
|
-
function buildPortalPopoverStyle(rect, viewportBottom) {
|
|
612
|
+
function buildPortalPopoverStyle(rect, viewportBottom, viewportWidth) {
|
|
613
613
|
return {
|
|
614
614
|
...viewportBottom !== void 0 ? { maxHeight: menuMaxHeight(rect.bottom, viewportBottom) } : null,
|
|
615
615
|
// RN's ViewStyle union omits 'fixed', but react-native-web honours it at runtime.
|
|
616
616
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- web-only position value
|
|
617
617
|
position: "fixed",
|
|
618
618
|
top: rect.bottom + MENU_TOP_GAP2,
|
|
619
|
-
|
|
620
|
-
width: rect.width,
|
|
619
|
+
...horizontalPlacement(rect, viewportWidth),
|
|
621
620
|
zIndex: MENU_PORTAL_Z_INDEX
|
|
622
621
|
};
|
|
623
622
|
}
|
|
623
|
+
function horizontalPlacement(rect, viewportWidth) {
|
|
624
|
+
if (viewportWidth === void 0) return { left: rect.left, width: rect.width };
|
|
625
|
+
const width = Math.min(Math.max(rect.width, MENU_MIN_WIDTH), viewportWidth - 2 * VIEWPORT_MARGIN);
|
|
626
|
+
const left = Math.max(VIEWPORT_MARGIN, Math.min(rect.left, viewportWidth - VIEWPORT_MARGIN - width));
|
|
627
|
+
return { left, width };
|
|
628
|
+
}
|
|
624
629
|
function useAnchorRect(ref, enabled) {
|
|
625
630
|
const [rect, setRect] = useState(null);
|
|
626
631
|
useLayoutEffect(() => {
|
|
@@ -755,15 +760,16 @@ function AnchoredMenu({
|
|
|
755
760
|
testID,
|
|
756
761
|
anchorRef,
|
|
757
762
|
usePortal = true,
|
|
758
|
-
listbox
|
|
763
|
+
listbox,
|
|
764
|
+
placement
|
|
759
765
|
}) {
|
|
760
766
|
const menuRef = React2.useRef(null);
|
|
761
767
|
useDismiss(anchorRef, menuRef, onDismiss);
|
|
762
768
|
useKeepHighlightInView(testID, listbox?.highlightedValue);
|
|
763
|
-
const rect = useAnchorRect(anchorRef, usePortal);
|
|
769
|
+
const rect = useAnchorRect(placement?.positionRef ?? anchorRef, usePortal);
|
|
764
770
|
const viewportBottom = useVisualViewportBottom(usePortal);
|
|
765
|
-
const portalStyle = rect !== null ? buildPortalPopoverStyle(rect, viewportBottom ?? void 0) : null;
|
|
766
771
|
const { width: windowWidth } = useWindowDimensions();
|
|
772
|
+
const portalStyle = rect !== null ? buildPortalPopoverStyle(rect, viewportBottom ?? void 0, placement !== void 0 ? windowWidth : void 0) : null;
|
|
767
773
|
const menuWidth = rect?.width ?? windowWidth;
|
|
768
774
|
const isListbox = listbox !== void 0;
|
|
769
775
|
const statusText = listbox?.statusText;
|
|
@@ -1691,8 +1697,47 @@ var FormCheckbox = ({
|
|
|
1691
1697
|
}
|
|
1692
1698
|
);
|
|
1693
1699
|
};
|
|
1700
|
+
|
|
1701
|
+
// src/controls/nextHighlight.ts
|
|
1702
|
+
var NO_HIGHLIGHT = -1;
|
|
1703
|
+
function nextHighlight(current, count, delta) {
|
|
1704
|
+
if (count === 0) return NO_HIGHLIGHT;
|
|
1705
|
+
if (current === NO_HIGHLIGHT) return delta > 0 ? 0 : count - 1;
|
|
1706
|
+
return (current + delta + count) % count;
|
|
1707
|
+
}
|
|
1708
|
+
|
|
1709
|
+
// src/SelectControl/useSelectListbox.ts
|
|
1710
|
+
var FORWARD = 1;
|
|
1711
|
+
var BACKWARD = -1;
|
|
1712
|
+
function useSelectListbox({ options, isOpen, open, toggle, select }) {
|
|
1713
|
+
const [row, setRow] = useState(NO_HIGHLIGHT);
|
|
1714
|
+
const highlighted = isOpen ? options[row] : void 0;
|
|
1715
|
+
useEffect(() => {
|
|
1716
|
+
if (!isOpen) setRow(NO_HIGHLIGHT);
|
|
1717
|
+
}, [isOpen]);
|
|
1718
|
+
const onKeyDown = (event) => {
|
|
1719
|
+
const { key } = event;
|
|
1720
|
+
const isArrow = key === "ArrowDown" || key === "ArrowUp";
|
|
1721
|
+
if (!isArrow && key !== "Enter" && key !== " ") return;
|
|
1722
|
+
event.preventDefault();
|
|
1723
|
+
event.stopPropagation();
|
|
1724
|
+
if (isArrow) {
|
|
1725
|
+
open();
|
|
1726
|
+
setRow((current) => nextHighlight(current, options.length, key === "ArrowDown" ? FORWARD : BACKWARD));
|
|
1727
|
+
} else if (highlighted !== void 0) select(highlighted.value);
|
|
1728
|
+
else toggle();
|
|
1729
|
+
};
|
|
1730
|
+
return { highlighted, onKeyDown };
|
|
1731
|
+
}
|
|
1694
1732
|
var CHEVRON_DOWN = "\u25BE";
|
|
1695
1733
|
var CHEVRON_UP = "\u25B4";
|
|
1734
|
+
function listboxTriggerAria(testID, hasList, highlighted) {
|
|
1735
|
+
return {
|
|
1736
|
+
role: "combobox",
|
|
1737
|
+
"aria-controls": hasList ? listboxDomId(testID) : void 0,
|
|
1738
|
+
"aria-activedescendant": highlighted !== void 0 ? optionDomId(testID, highlighted.value) : void 0
|
|
1739
|
+
};
|
|
1740
|
+
}
|
|
1696
1741
|
function SelectControl({
|
|
1697
1742
|
options,
|
|
1698
1743
|
value,
|
|
@@ -1702,6 +1747,7 @@ function SelectControl({
|
|
|
1702
1747
|
accessibilityHint,
|
|
1703
1748
|
labelledById,
|
|
1704
1749
|
optionHint = "",
|
|
1750
|
+
menuAnchor,
|
|
1705
1751
|
style,
|
|
1706
1752
|
testID
|
|
1707
1753
|
}) {
|
|
@@ -1716,6 +1762,9 @@ function SelectControl({
|
|
|
1716
1762
|
const close = useCallback(() => {
|
|
1717
1763
|
setIsOpen(false);
|
|
1718
1764
|
}, []);
|
|
1765
|
+
const open = useCallback(() => {
|
|
1766
|
+
setIsOpen(true);
|
|
1767
|
+
}, []);
|
|
1719
1768
|
const toggle = useCallback(() => {
|
|
1720
1769
|
setIsOpen((prev) => !prev);
|
|
1721
1770
|
}, []);
|
|
@@ -1726,16 +1775,23 @@ function SelectControl({
|
|
|
1726
1775
|
},
|
|
1727
1776
|
[onChange]
|
|
1728
1777
|
);
|
|
1729
|
-
|
|
1778
|
+
const listbox = useSelectListbox({ options, isOpen, open, toggle, select });
|
|
1779
|
+
const isListbox = menuAnchor !== void 0;
|
|
1780
|
+
const captureKeys = isListbox ? { onKeyDownCapture: listbox.onKeyDown } : {};
|
|
1781
|
+
const triggerAria = isListbox ? listboxTriggerAria(testID, isOpen && options.length > 0, listbox.highlighted) : {};
|
|
1782
|
+
return /* @__PURE__ */ jsxs(View, { ref: anchorRef, style: [controlStyles.anchor, style], ...captureKeys, children: [
|
|
1730
1783
|
/* @__PURE__ */ jsxs(
|
|
1731
1784
|
Pressable,
|
|
1732
1785
|
{
|
|
1733
|
-
|
|
1786
|
+
...triggerAria,
|
|
1787
|
+
accessibilityRole: isListbox ? void 0 : "button",
|
|
1734
1788
|
accessibilityLabel,
|
|
1735
1789
|
accessibilityHint,
|
|
1736
1790
|
accessibilityState: { expanded: isOpen },
|
|
1737
1791
|
"aria-expanded": isOpen,
|
|
1792
|
+
"aria-haspopup": "listbox",
|
|
1738
1793
|
"aria-labelledby": labelledById,
|
|
1794
|
+
onBlur: isListbox ? close : void 0,
|
|
1739
1795
|
onPress: toggle,
|
|
1740
1796
|
style: [controlStyles.selectTrigger, { borderColor: colors.border, backgroundColor: colors.surfaceElevated }],
|
|
1741
1797
|
testID: `${testID}-trigger`,
|
|
@@ -1752,10 +1808,13 @@ function SelectControl({
|
|
|
1752
1808
|
selectedValue: value,
|
|
1753
1809
|
onSelect: select,
|
|
1754
1810
|
onDismiss: close,
|
|
1755
|
-
colors: { text: colors.text, border: colors.border, surface: colors.surface, brand: palette.primary["500"] },
|
|
1811
|
+
colors: { text: colors.text, ...isListbox ? { textSecondary: colors.textSecondary } : null, border: colors.border, surface: colors.surface, brand: palette.primary["500"] },
|
|
1756
1812
|
optionHint,
|
|
1757
1813
|
testID,
|
|
1758
|
-
anchorRef
|
|
1814
|
+
anchorRef,
|
|
1815
|
+
accessibilityLabel: menuAnchor?.listboxLabel,
|
|
1816
|
+
listbox: isListbox ? { highlightedValue: listbox.highlighted?.value } : void 0,
|
|
1817
|
+
placement: isListbox ? { positionRef: menuAnchor.anchorRef } : void 0
|
|
1759
1818
|
}
|
|
1760
1819
|
) : null
|
|
1761
1820
|
] });
|
|
@@ -1863,15 +1922,9 @@ function useTypeaheadSearch(load, query, enabled, debounceMs) {
|
|
|
1863
1922
|
}
|
|
1864
1923
|
|
|
1865
1924
|
// src/TypeaheadControl/hooks/useTypeaheadState.ts
|
|
1866
|
-
var
|
|
1867
|
-
var
|
|
1868
|
-
var BACKWARD = -1;
|
|
1925
|
+
var FORWARD2 = 1;
|
|
1926
|
+
var BACKWARD2 = -1;
|
|
1869
1927
|
var NO_ROWS = [];
|
|
1870
|
-
function nextHighlight(current, count, delta) {
|
|
1871
|
-
if (count === 0) return NO_HIGHLIGHT;
|
|
1872
|
-
if (current === NO_HIGHLIGHT) return delta > 0 ? 0 : count - 1;
|
|
1873
|
-
return (current + delta + count) % count;
|
|
1874
|
-
}
|
|
1875
1928
|
function searchStatusText(found, search) {
|
|
1876
1929
|
if (found.hasFailed) return search.errorText;
|
|
1877
1930
|
if (found.results.length > 0) return void 0;
|
|
@@ -1953,7 +2006,7 @@ function useTypeaheadKeys(input) {
|
|
|
1953
2006
|
if (key === "ArrowDown" || key === "ArrowUp") {
|
|
1954
2007
|
event.preventDefault();
|
|
1955
2008
|
setIsOpen(true);
|
|
1956
|
-
setHighlightIndex((current) => nextHighlight(current, rowCount, key === "ArrowDown" ?
|
|
2009
|
+
setHighlightIndex((current) => nextHighlight(current, rowCount, key === "ArrowDown" ? FORWARD2 : BACKWARD2));
|
|
1957
2010
|
} else if (key === "Escape" && isOpen) {
|
|
1958
2011
|
event.preventDefault();
|
|
1959
2012
|
close();
|
|
@@ -2430,6 +2483,6 @@ var UploadWithLinkField = ({
|
|
|
2430
2483
|
] });
|
|
2431
2484
|
};
|
|
2432
2485
|
|
|
2433
|
-
export { AlignToControl, AnchoredMenu, ChipSelector, DEFAULT_MAX_RECENTS, DEFAULT_OPTIONAL_LABEL, DEFAULT_TYPEAHEAD_MAX_SUGGESTIONS, DEFAULT_TYPEAHEAD_MIN_CHARS, DateField, DateRangeControl, DateTimeField, Field, FormActions, FormCell, FormCheckbox, FormField, FormGrid, FormSection, FormStatusLine, FormSwitch, INLINE_FIELD_ROW_MIN_WIDTH, InlineFieldRow, SelectControl, SelectField, StepperNav, StepperTabs, ThemedTextInput, TypeaheadControl, UploadWithLinkField, controlStyles, groupAriaChecked, inlineFieldRowLayout, isUnmatched, resolveGroupSelection, resolveStepNeighbours, suggestOptions, toggleGroupSelection, useFocusFirstInvalid, useKeepInView, useRecentValues, useThemedInput };
|
|
2486
|
+
export { AlignToControl, AnchoredMenu, ChipSelector, DEFAULT_MAX_RECENTS, DEFAULT_OPTIONAL_LABEL, DEFAULT_TYPEAHEAD_MAX_SUGGESTIONS, DEFAULT_TYPEAHEAD_MIN_CHARS, DateField, DateRangeControl, DateTimeField, Field, FormActions, FormCell, FormCheckbox, FormField, FormGrid, FormSection, FormStatusLine, FormSwitch, INLINE_FIELD_ROW_MIN_WIDTH, InlineFieldRow, SelectControl, SelectField, StepperNav, StepperTabs, ThemedTextInput, TypeaheadControl, UploadWithLinkField, controlStyles, groupAriaChecked, inlineFieldRowLayout, isUnmatched, nextHighlight, resolveGroupSelection, resolveStepNeighbours, suggestOptions, toggleGroupSelection, useFocusFirstInvalid, useKeepInView, useRecentValues, useThemedInput };
|
|
2434
2487
|
//# sourceMappingURL=index.mjs.map
|
|
2435
2488
|
//# sourceMappingURL=index.mjs.map
|