@dloizides/ui-forms 1.34.0 → 1.34.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
@@ -2723,12 +2723,6 @@ var styles22 = StyleSheet.create({
2723
2723
  sheetList: { maxHeight: SHEET_MAX_HEIGHT },
2724
2724
  empty: { padding: PANEL_PAD }
2725
2725
  });
2726
- var AFTER_SURFACE_UNMOUNT_MS = 0;
2727
- function useDeferredFocus(ref) {
2728
- return useCallback(() => {
2729
- setTimeout(() => ref.current?.focus(), AFTER_SURFACE_UNMOUNT_MS);
2730
- }, [ref]);
2731
- }
2732
2726
  function useReducedMotion() {
2733
2727
  const [reduced, setReduced] = useState(false);
2734
2728
  useEffect(() => {
@@ -2744,6 +2738,13 @@ function useReducedMotion() {
2744
2738
  }, []);
2745
2739
  return reduced;
2746
2740
  }
2741
+ function useRefocusOnClose(open, ref) {
2742
+ const wasOpen = useRef(false);
2743
+ useEffect(() => {
2744
+ if (wasOpen.current && !open) ref.current?.focus();
2745
+ wasOpen.current = open;
2746
+ }, [open, ref]);
2747
+ }
2747
2748
 
2748
2749
  // src/SearchSelect/utils/searchSelectModel.ts
2749
2750
  var MIN_QUERY = 1;
@@ -2821,6 +2822,7 @@ function resolveSelectMotion(width, reducedMotion) {
2821
2822
  }
2822
2823
  var CHEVRON = "\u25BE";
2823
2824
  var VALUE_GAP = 8;
2825
+ var NOTHING_ON_CLOSE = () => void 0;
2824
2826
  function SearchSelect(props) {
2825
2827
  const { options, value, onChange, accessibilityLabel, accessibilityHint, labels, testID, recentKey, renderLeading, renderDetail } = props;
2826
2828
  const { theme } = useUi();
@@ -2830,8 +2832,8 @@ function SearchSelect(props) {
2830
2832
  const { width } = useWindowDimensions();
2831
2833
  const motion = resolveSelectMotion(width, useReducedMotion());
2832
2834
  const recents = useRecentValues(recentKey ?? `search-select:${testID}`);
2833
- const refocus = useDeferredFocus(triggerRef);
2834
- const state = useSearchSelectState(options, recents, onChange, refocus);
2835
+ const state = useSearchSelectState(options, recents, onChange, NOTHING_ON_CLOSE);
2836
+ useRefocusOnClose(state.open, triggerRef);
2835
2837
  const selected = findOption(options, value);
2836
2838
  return /* @__PURE__ */ jsxs(View, { ref: anchorRef, style: styles23.anchor, children: [
2837
2839
  /* @__PURE__ */ jsxs(
@@ -2884,6 +2886,12 @@ function useOutsidePress(ref, onOutside) {
2884
2886
  return () => document.removeEventListener("pointerdown", onPointerDown, true);
2885
2887
  }, [ref, onOutside]);
2886
2888
  }
2889
+ var AFTER_SURFACE_UNMOUNT_MS = 0;
2890
+ function useDeferredFocus(ref) {
2891
+ return useCallback(() => {
2892
+ setTimeout(() => ref.current?.focus(), AFTER_SURFACE_UNMOUNT_MS);
2893
+ }, [ref]);
2894
+ }
2887
2895
 
2888
2896
  // src/CountryFlag/data/flagPalette.ts
2889
2897
  var FLAG_PALETTE = {