klun-ui 0.1.15 → 0.1.16

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.
@@ -6455,6 +6455,7 @@ function useSelect({ children, value, defaultValue, disabled, rootRef }) {
6455
6455
  const current = controlled ? String(value ?? "") : internal;
6456
6456
  const [open, setOpen] = react.useState(false);
6457
6457
  const [active, setActive] = react.useState(-1);
6458
+ const [placement, setPlacement] = react.useState("down");
6458
6459
  const triggerRef = react.useRef(null);
6459
6460
  const selectRef = react.useRef(null);
6460
6461
  const selected = options.find((o) => o.value === current) ?? null;
@@ -6475,6 +6476,15 @@ function useSelect({ children, value, defaultValue, disabled, rootRef }) {
6475
6476
  if (disabled) return;
6476
6477
  const idx = options.findIndex((o) => o.value === current);
6477
6478
  setActive(idx >= 0 ? idx : options.findIndex((o) => !o.disabled));
6479
+ const trigger = triggerRef.current;
6480
+ if (trigger && typeof window !== "undefined") {
6481
+ const r = trigger.getBoundingClientRect();
6482
+ const estimated = Math.min(options.length * 36 + 12, 280);
6483
+ const below = window.innerHeight - r.bottom;
6484
+ setPlacement(below < estimated + 8 && r.top > below ? "up" : "down");
6485
+ } else {
6486
+ setPlacement("down");
6487
+ }
6478
6488
  setOpen(true);
6479
6489
  };
6480
6490
  const close = (refocus = true) => {
@@ -6551,6 +6561,7 @@ function useSelect({ children, value, defaultValue, disabled, rootRef }) {
6551
6561
  current,
6552
6562
  selected,
6553
6563
  open,
6564
+ placement,
6554
6565
  active,
6555
6566
  setActive,
6556
6567
  triggerRef,
@@ -6711,7 +6722,8 @@ var CompactSelect = react.forwardRef(
6711
6722
  current: s.current,
6712
6723
  active: s.active,
6713
6724
  onActivate: s.setActive,
6714
- onPick: s.pick
6725
+ onPick: s.pick,
6726
+ className: s.placement === "up" ? "klun-select-listbox--up" : void 0
6715
6727
  }
6716
6728
  ) : null
6717
6729
  ]
@@ -6807,7 +6819,8 @@ var CompactSelectForInput = react.forwardRef(function CompactSelectForInput2({
6807
6819
  current: s.current,
6808
6820
  active: s.active,
6809
6821
  onActivate: s.setActive,
6810
- onPick: s.pick
6822
+ onPick: s.pick,
6823
+ className: s.placement === "up" ? "klun-select-listbox--up" : void 0
6811
6824
  }
6812
6825
  ) : null
6813
6826
  ]
@@ -8107,7 +8120,8 @@ var InlineSelect = react.forwardRef(
8107
8120
  current: s.current,
8108
8121
  active: s.active,
8109
8122
  onActivate: s.setActive,
8110
- onPick: s.pick
8123
+ onPick: s.pick,
8124
+ className: s.placement === "up" ? "klun-select-listbox--up" : void 0
8111
8125
  }
8112
8126
  ) : null
8113
8127
  ]
@@ -8453,7 +8467,8 @@ var Select = react.forwardRef(function Select2({
8453
8467
  current: s.current,
8454
8468
  active: s.active,
8455
8469
  onActivate: s.setActive,
8456
- onPick: s.pick
8470
+ onPick: s.pick,
8471
+ className: s.placement === "up" ? "klun-select-listbox--up" : void 0
8457
8472
  }
8458
8473
  ) : null
8459
8474
  ] });
@@ -10972,5 +10987,5 @@ exports.useSize = useSize;
10972
10987
  exports.viVN = viVN;
10973
10988
  exports.zhCN = zhCN;
10974
10989
  exports.zhTW = zhTW;
10975
- //# sourceMappingURL=chunk-PAGCE4QH.cjs.map
10976
- //# sourceMappingURL=chunk-PAGCE4QH.cjs.map
10990
+ //# sourceMappingURL=chunk-6WIXXBXA.cjs.map
10991
+ //# sourceMappingURL=chunk-6WIXXBXA.cjs.map