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.
@@ -60,14 +60,34 @@ const Dropdown = ({
60
60
  }, [controlledOpen]);
61
61
 
62
62
  useEffect(() => {
63
- if (open && autoFocus) {
64
- requestAnimationFrame(() => {
65
- const first = menuRef.current?.querySelector(
66
- "[role='menuitem']:not([aria-disabled='true'])"
67
- ) as HTMLElement | null;
68
-
69
- first?.focus();
70
- });
63
+ const handleClickOutside = (e: MouseEvent) => {
64
+ if (
65
+ popupRef.current &&
66
+ !popupRef.current.contains(e.target as Node) &&
67
+ targetRef.current &&
68
+ !targetRef.current.contains(e.target as Node)
69
+ ) {
70
+ setOpenInternal(false);
71
+ onVisibleChange?.(false);
72
+ }
73
+ };
74
+
75
+ if (open) {
76
+ if (autoFocus) {
77
+ requestAnimationFrame(() => {
78
+ const first = menuRef.current?.querySelector(
79
+ "[role='menuitem']:not([aria-disabled='true'])"
80
+ ) as HTMLElement | null;
81
+
82
+ first?.focus();
83
+ });
84
+ }
85
+
86
+ document.addEventListener('mousedown', handleClickOutside);
87
+ } else {
88
+ return () => {
89
+ document.removeEventListener('mousedown', handleClickOutside);
90
+ };
71
91
  }
72
92
  }, [open]);
73
93
 
@@ -84,26 +104,6 @@ const Dropdown = ({
84
104
  onVisibleChange?.(next)
85
105
  };
86
106
 
87
- useEffect(() => {
88
- const handleClickOutside = (e: MouseEvent) => {
89
- if (
90
- popupRef.current &&
91
- !popupRef.current.contains(e.target as Node) &&
92
- targetRef.current &&
93
- !targetRef.current.contains(e.target as Node)
94
- ) {
95
- setOpenInternal(false);
96
- onVisibleChange?.(false);
97
- }
98
- };
99
-
100
- document.addEventListener('mousedown', handleClickOutside);
101
-
102
- return () => {
103
- document.removeEventListener('mousedown', handleClickOutside);
104
- };
105
- }, []);
106
-
107
107
  const triggers = Array.isArray(trigger) ? trigger : [trigger];
108
108
 
109
109
  const onTriggerClick = (e: SyntheticEvent) => {
@@ -208,7 +208,7 @@ function MenuInner({
208
208
  aria-disabled={it.disabled ?? false}
209
209
  onClick={(e) => {
210
210
  console.log(1);
211
-
211
+
212
212
  if (it.disabled) {
213
213
  return;
214
214
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "x-ui-design",
3
- "version": "0.9.80",
3
+ "version": "0.9.81",
4
4
  "license": "ISC",
5
5
  "author": "Gabriel Boyajyan",
6
6
  "main": "dist/index.js",
package/src/app/page.tsx CHANGED
@@ -1,18 +1,16 @@
1
1
  'use client'
2
2
 
3
- import { Popover } from '../../lib/components/Popover';
3
+ import { Dropdown } from '../../lib/components/Dropdown';
4
4
 
5
5
  export default function Home() {
6
6
  return (
7
- <Popover
8
- trigger={'hover'}
7
+ <Dropdown
8
+ trigger={['click']}
9
9
  placement='bottomRight'
10
- content={
11
- <div>Popover</div>
12
- }
10
+ getPopupContainer={() => document.body}
13
11
  >
14
12
  Menu
15
- </Popover>
13
+ </Dropdown>
16
14
  )
17
15
  }
18
16