@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.mjs CHANGED
@@ -565,12 +565,16 @@ function listboxDomId(testID) {
565
565
  function isDetailBesideTitle(menuWidth) {
566
566
  return menuWidth >= DETAIL_BESIDE_MIN_MENU_WIDTH;
567
567
  }
568
+ function rowInk(colors, isActive, isHighlighted) {
569
+ if (isHighlighted) return { title: colors.surface, detail: colors.surface };
570
+ return { title: isActive ? colors.brand : colors.text, detail: colors.textSecondary ?? colors.text };
571
+ }
568
572
  function OptionRow({ option, isActive, isHighlighted, isListboxRow, menuWidth, hint, colors, testID, onSelect }) {
569
573
  const hasDetail = option.detail !== void 0 && option.detail !== "";
570
574
  const label = hasDetail ? `${option.label}, ${option.detail}` : option.label;
571
575
  const roleProps = isListboxRow ? { role: "option", tabIndex: -1, id: optionDomId(testID, option.value), "aria-selected": isHighlighted } : { accessibilityRole: "menuitem", "aria-selected": isActive };
572
576
  const isBold = isActive || isHighlighted;
573
- const titleColor = isActive ? colors.brand : colors.text;
577
+ const ink = rowInk(colors, isActive, isHighlighted);
574
578
  return /* @__PURE__ */ jsx(
575
579
  Pressable,
576
580
  {
@@ -579,11 +583,11 @@ function OptionRow({ option, isActive, isHighlighted, isListboxRow, menuWidth, h
579
583
  accessibilityHint: hint,
580
584
  accessibilityState: { selected: isActive },
581
585
  onPress: () => onSelect(option.value),
582
- style: [controlStyles.option, isHighlighted ? { backgroundColor: colors.border } : null],
586
+ style: [controlStyles.option, isHighlighted ? { backgroundColor: colors.text } : null],
583
587
  testID: `${testID}-option-${option.value}`,
584
588
  children: /* @__PURE__ */ jsxs(View, { style: isDetailBesideTitle(menuWidth) ? styles7.beside : styles7.stacked, children: [
585
- /* @__PURE__ */ jsx(Text, { style: [controlStyles.optionText, styles7.shrink, { color: titleColor, fontWeight: isBold ? ACTIVE_WEIGHT : IDLE_WEIGHT }], children: option.label }),
586
- hasDetail ? /* @__PURE__ */ jsx(Text, { style: [styles7.detail, { color: colors.textSecondary ?? colors.text }], children: option.detail }) : null
589
+ /* @__PURE__ */ jsx(Text, { style: [controlStyles.optionText, styles7.shrink, { color: ink.title, fontWeight: isBold ? ACTIVE_WEIGHT : IDLE_WEIGHT }], children: option.label }),
590
+ hasDetail ? /* @__PURE__ */ jsx(Text, { style: [styles7.detail, { color: ink.detail }], children: option.detail }) : null
587
591
  ] })
588
592
  }
589
593
  );
@@ -1755,6 +1759,24 @@ function SelectControl({
1755
1759
  ) : null
1756
1760
  ] });
1757
1761
  }
1762
+ var CLOSE_DELAY_MS2 = 140;
1763
+ function useDelayedBlurClose(open, close) {
1764
+ const timerRef = useRef(null);
1765
+ const cancelClose = useCallback(() => {
1766
+ if (timerRef.current !== null) clearTimeout(timerRef.current);
1767
+ timerRef.current = null;
1768
+ }, []);
1769
+ useEffect(() => cancelClose, [cancelClose]);
1770
+ const handleFocus = useCallback(() => {
1771
+ cancelClose();
1772
+ open();
1773
+ }, [cancelClose, open]);
1774
+ const handleBlur = useCallback(() => {
1775
+ cancelClose();
1776
+ timerRef.current = setTimeout(close, CLOSE_DELAY_MS2);
1777
+ }, [cancelClose, close]);
1778
+ return { handleFocus, handleBlur };
1779
+ }
1758
1780
 
1759
1781
  // src/controls/suggestOptions.ts
1760
1782
  var RANK_VALUE_EXACT = 0;
@@ -1920,7 +1942,6 @@ function useTypeaheadKeys(input) {
1920
1942
  [rowCount, isOpen, highlighted, setIsOpen, setHighlightIndex, close, pick]
1921
1943
  );
1922
1944
  }
1923
- var CLOSE_DELAY_MS2 = 140;
1924
1945
  var DEFAULT_TYPEAHEAD_MIN_CHARS = 1;
1925
1946
  var DEFAULT_TYPEAHEAD_MAX_SUGGESTIONS = 8;
1926
1947
  function comboboxAria(testID, isExpanded, highlighted) {
@@ -1942,6 +1963,7 @@ function TypeaheadControlImpl(props, ref) {
1942
1963
  const { colors, palette } = theme;
1943
1964
  const anchorRef = useRef(null);
1944
1965
  const state = useTypeaheadState({ options, search, value, minChars, maxSuggestions, onChange, onSubmit });
1966
+ const { handleFocus, handleBlur } = useDelayedBlurClose(state.open, state.close);
1945
1967
  const showMenu = state.isOpen && (state.rows.length > 0 || state.statusText !== void 0);
1946
1968
  const isExpanded = state.isOpen && state.rows.length > 0;
1947
1969
  const hasError = error !== void 0 && error !== "";
@@ -1965,8 +1987,8 @@ function TypeaheadControlImpl(props, ref) {
1965
1987
  spellCheck: false,
1966
1988
  value,
1967
1989
  onChangeText: state.handleChange,
1968
- onFocus: state.open,
1969
- onBlur: () => setTimeout(state.close, CLOSE_DELAY_MS2),
1990
+ onFocus: handleFocus,
1991
+ onBlur: handleBlur,
1970
1992
  onKeyPress: state.handleKeyPress,
1971
1993
  onSubmitEditing: state.handleSubmit,
1972
1994
  style: [controlStyles.input, { borderColor: hasError ? fieldErrorInk(theme) : colors.border, backgroundColor: colors.surface, color: colors.text }],