@dloizides/ui-forms 1.23.0 → 1.23.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.js CHANGED
@@ -571,12 +571,16 @@ function listboxDomId(testID) {
571
571
  function isDetailBesideTitle(menuWidth) {
572
572
  return menuWidth >= DETAIL_BESIDE_MIN_MENU_WIDTH;
573
573
  }
574
+ function rowInk(colors, isActive, isHighlighted) {
575
+ if (isHighlighted) return { title: colors.surface, detail: colors.surface };
576
+ return { title: isActive ? colors.brand : colors.text, detail: colors.textSecondary ?? colors.text };
577
+ }
574
578
  function OptionRow({ option, isActive, isHighlighted, isListboxRow, menuWidth, hint, colors, testID, onSelect }) {
575
579
  const hasDetail = option.detail !== void 0 && option.detail !== "";
576
580
  const label = hasDetail ? `${option.label}, ${option.detail}` : option.label;
577
581
  const roleProps = isListboxRow ? { role: "option", tabIndex: -1, id: optionDomId(testID, option.value), "aria-selected": isHighlighted } : { accessibilityRole: "menuitem", "aria-selected": isActive };
578
582
  const isBold = isActive || isHighlighted;
579
- const titleColor = isActive ? colors.brand : colors.text;
583
+ const ink = rowInk(colors, isActive, isHighlighted);
580
584
  return /* @__PURE__ */ jsxRuntime.jsx(
581
585
  reactNative.Pressable,
582
586
  {
@@ -585,11 +589,11 @@ function OptionRow({ option, isActive, isHighlighted, isListboxRow, menuWidth, h
585
589
  accessibilityHint: hint,
586
590
  accessibilityState: { selected: isActive },
587
591
  onPress: () => onSelect(option.value),
588
- style: [controlStyles.option, isHighlighted ? { backgroundColor: colors.border } : null],
592
+ style: [controlStyles.option, isHighlighted ? { backgroundColor: colors.text } : null],
589
593
  testID: `${testID}-option-${option.value}`,
590
594
  children: /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: isDetailBesideTitle(menuWidth) ? styles7.beside : styles7.stacked, children: [
591
- /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [controlStyles.optionText, styles7.shrink, { color: titleColor, fontWeight: isBold ? ACTIVE_WEIGHT : IDLE_WEIGHT }], children: option.label }),
592
- hasDetail ? /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [styles7.detail, { color: colors.textSecondary ?? colors.text }], children: option.detail }) : null
595
+ /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [controlStyles.optionText, styles7.shrink, { color: ink.title, fontWeight: isBold ? ACTIVE_WEIGHT : IDLE_WEIGHT }], children: option.label }),
596
+ hasDetail ? /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [styles7.detail, { color: ink.detail }], children: option.detail }) : null
593
597
  ] })
594
598
  }
595
599
  );
@@ -1761,6 +1765,24 @@ function SelectControl({
1761
1765
  ) : null
1762
1766
  ] });
1763
1767
  }
1768
+ var CLOSE_DELAY_MS2 = 140;
1769
+ function useDelayedBlurClose(open, close) {
1770
+ const timerRef = React2.useRef(null);
1771
+ const cancelClose = React2.useCallback(() => {
1772
+ if (timerRef.current !== null) clearTimeout(timerRef.current);
1773
+ timerRef.current = null;
1774
+ }, []);
1775
+ React2.useEffect(() => cancelClose, [cancelClose]);
1776
+ const handleFocus = React2.useCallback(() => {
1777
+ cancelClose();
1778
+ open();
1779
+ }, [cancelClose, open]);
1780
+ const handleBlur = React2.useCallback(() => {
1781
+ cancelClose();
1782
+ timerRef.current = setTimeout(close, CLOSE_DELAY_MS2);
1783
+ }, [cancelClose, close]);
1784
+ return { handleFocus, handleBlur };
1785
+ }
1764
1786
 
1765
1787
  // src/controls/suggestOptions.ts
1766
1788
  var RANK_VALUE_EXACT = 0;
@@ -1926,7 +1948,6 @@ function useTypeaheadKeys(input) {
1926
1948
  [rowCount, isOpen, highlighted, setIsOpen, setHighlightIndex, close, pick]
1927
1949
  );
1928
1950
  }
1929
- var CLOSE_DELAY_MS2 = 140;
1930
1951
  var DEFAULT_TYPEAHEAD_MIN_CHARS = 1;
1931
1952
  var DEFAULT_TYPEAHEAD_MAX_SUGGESTIONS = 8;
1932
1953
  function comboboxAria(testID, isExpanded, highlighted) {
@@ -1948,6 +1969,7 @@ function TypeaheadControlImpl(props, ref) {
1948
1969
  const { colors, palette } = theme;
1949
1970
  const anchorRef = React2.useRef(null);
1950
1971
  const state = useTypeaheadState({ options, search, value, minChars, maxSuggestions, onChange, onSubmit });
1972
+ const { handleFocus, handleBlur } = useDelayedBlurClose(state.open, state.close);
1951
1973
  const showMenu = state.isOpen && (state.rows.length > 0 || state.statusText !== void 0);
1952
1974
  const isExpanded = state.isOpen && state.rows.length > 0;
1953
1975
  const hasError = error !== void 0 && error !== "";
@@ -1971,8 +1993,8 @@ function TypeaheadControlImpl(props, ref) {
1971
1993
  spellCheck: false,
1972
1994
  value,
1973
1995
  onChangeText: state.handleChange,
1974
- onFocus: state.open,
1975
- onBlur: () => setTimeout(state.close, CLOSE_DELAY_MS2),
1996
+ onFocus: handleFocus,
1997
+ onBlur: handleBlur,
1976
1998
  onKeyPress: state.handleKeyPress,
1977
1999
  onSubmitEditing: state.handleSubmit,
1978
2000
  style: [controlStyles.input, { borderColor: hasError ? fieldErrorInk(theme) : colors.border, backgroundColor: colors.surface, color: colors.text }],