x-ui-design 0.9.80 → 0.9.81

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.esm.js CHANGED
@@ -5549,11 +5549,24 @@ const Dropdown = ({
5549
5549
  }
5550
5550
  }, [controlledOpen]);
5551
5551
  useEffect(() => {
5552
- if (open && autoFocus) {
5553
- requestAnimationFrame(() => {
5554
- const first = menuRef.current?.querySelector("[role='menuitem']:not([aria-disabled='true'])");
5555
- first?.focus();
5556
- });
5552
+ const handleClickOutside = e => {
5553
+ if (popupRef.current && !popupRef.current.contains(e.target) && targetRef.current && !targetRef.current.contains(e.target)) {
5554
+ setOpenInternal(false);
5555
+ onVisibleChange?.(false);
5556
+ }
5557
+ };
5558
+ if (open) {
5559
+ if (autoFocus) {
5560
+ requestAnimationFrame(() => {
5561
+ const first = menuRef.current?.querySelector("[role='menuitem']:not([aria-disabled='true'])");
5562
+ first?.focus();
5563
+ });
5564
+ }
5565
+ document.addEventListener('mousedown', handleClickOutside);
5566
+ } else {
5567
+ return () => {
5568
+ document.removeEventListener('mousedown', handleClickOutside);
5569
+ };
5557
5570
  }
5558
5571
  }, [open]);
5559
5572
  const setOpenInternal = next => {
@@ -5566,18 +5579,6 @@ const Dropdown = ({
5566
5579
  onVisibleChange?.(next);
5567
5580
  onVisibleChange?.(next);
5568
5581
  };
5569
- useEffect(() => {
5570
- const handleClickOutside = e => {
5571
- if (popupRef.current && !popupRef.current.contains(e.target) && targetRef.current && !targetRef.current.contains(e.target)) {
5572
- setOpenInternal(false);
5573
- onVisibleChange?.(false);
5574
- }
5575
- };
5576
- document.addEventListener('mousedown', handleClickOutside);
5577
- return () => {
5578
- document.removeEventListener('mousedown', handleClickOutside);
5579
- };
5580
- }, []);
5581
5582
  const triggers = Array.isArray(trigger) ? trigger : [trigger];
5582
5583
  const onTriggerClick = e => {
5583
5584
  e.preventDefault();