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