@rc-component/trigger 3.6.2 → 3.6.3

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.
@@ -31,8 +31,13 @@ const UniqueProvider = ({
31
31
 
32
32
  // ========================== Register ==========================
33
33
  const [popupId, setPopupId] = React.useState(0);
34
+
35
+ // Store the isOpen function from the latest show call
36
+ const isOpenRef = React.useRef(null);
34
37
  const delayInvoke = useDelay();
35
- const show = useEvent(showOptions => {
38
+ const show = useEvent((showOptions, isOpen) => {
39
+ // Store the isOpen function for later use in hide
40
+ isOpenRef.current = isOpen;
36
41
  delayInvoke(() => {
37
42
  if (showOptions.id !== options?.id) {
38
43
  setPopupId(i => i + 1);
@@ -42,6 +47,11 @@ const UniqueProvider = ({
42
47
  });
43
48
  const hide = delay => {
44
49
  delayInvoke(() => {
50
+ // Check if we should still hide by calling the isOpen function
51
+ // If isOpen returns true, it means another trigger wants to keep it open
52
+ if (isOpenRef.current?.()) {
53
+ return; // Don't hide if something else wants it open
54
+ }
45
55
  trigger(false);
46
56
  // Don't clear target, currentNode, options immediately, wait until animation completes
47
57
  }, delay);
package/es/context.d.ts CHANGED
@@ -28,7 +28,7 @@ export interface UniqueShowOptions {
28
28
  getPopupClassNameFromAlign?: (align: AlignType) => string;
29
29
  }
30
30
  export interface UniqueContextProps {
31
- show: (options: UniqueShowOptions) => void;
31
+ show: (options: UniqueShowOptions, isOpen: () => boolean) => void;
32
32
  hide: (delay: number) => void;
33
33
  }
34
34
  export declare const UniqueContext: React.Context<UniqueContextProps>;
package/es/index.js CHANGED
@@ -150,6 +150,9 @@ export function generateTrigger(PortalComponent = Portal) {
150
150
  setInternalOpen(nextOpen);
151
151
  }
152
152
  });
153
+
154
+ // Support ref
155
+ const isOpen = useEvent(() => mergedOpen);
153
156
  useLayoutEffect(() => {
154
157
  setInternalOpen(popupVisible || false);
155
158
  }, [popupVisible]);
@@ -182,9 +185,7 @@ export function generateTrigger(PortalComponent = Portal) {
182
185
  useLayoutEffect(() => {
183
186
  if (uniqueContext && unique && targetEle && !openUncontrolled && !parentContext) {
184
187
  if (mergedOpen) {
185
- Promise.resolve().then(() => {
186
- uniqueContext.show(getUniqueOptions(0));
187
- });
188
+ uniqueContext.show(getUniqueOptions(0), isOpen);
188
189
  } else {
189
190
  uniqueContext.hide(0);
190
191
  }
@@ -223,7 +224,7 @@ export function generateTrigger(PortalComponent = Portal) {
223
224
  // If there is a parentContext, don't call uniqueContext methods
224
225
  if (uniqueContext && unique && openUncontrolled && !parentContext) {
225
226
  if (nextOpen) {
226
- uniqueContext.show(getUniqueOptions(delay));
227
+ uniqueContext.show(getUniqueOptions(delay), isOpen);
227
228
  } else {
228
229
  uniqueContext.hide(delay);
229
230
  }
@@ -40,8 +40,13 @@ const UniqueProvider = ({
40
40
 
41
41
  // ========================== Register ==========================
42
42
  const [popupId, setPopupId] = React.useState(0);
43
+
44
+ // Store the isOpen function from the latest show call
45
+ const isOpenRef = React.useRef(null);
43
46
  const delayInvoke = (0, _useDelay.default)();
44
- const show = (0, _util.useEvent)(showOptions => {
47
+ const show = (0, _util.useEvent)((showOptions, isOpen) => {
48
+ // Store the isOpen function for later use in hide
49
+ isOpenRef.current = isOpen;
45
50
  delayInvoke(() => {
46
51
  if (showOptions.id !== options?.id) {
47
52
  setPopupId(i => i + 1);
@@ -51,6 +56,11 @@ const UniqueProvider = ({
51
56
  });
52
57
  const hide = delay => {
53
58
  delayInvoke(() => {
59
+ // Check if we should still hide by calling the isOpen function
60
+ // If isOpen returns true, it means another trigger wants to keep it open
61
+ if (isOpenRef.current?.()) {
62
+ return; // Don't hide if something else wants it open
63
+ }
54
64
  trigger(false);
55
65
  // Don't clear target, currentNode, options immediately, wait until animation completes
56
66
  }, delay);
package/lib/context.d.ts CHANGED
@@ -28,7 +28,7 @@ export interface UniqueShowOptions {
28
28
  getPopupClassNameFromAlign?: (align: AlignType) => string;
29
29
  }
30
30
  export interface UniqueContextProps {
31
- show: (options: UniqueShowOptions) => void;
31
+ show: (options: UniqueShowOptions, isOpen: () => boolean) => void;
32
32
  hide: (delay: number) => void;
33
33
  }
34
34
  export declare const UniqueContext: React.Context<UniqueContextProps>;
package/lib/index.js CHANGED
@@ -165,6 +165,9 @@ function generateTrigger(PortalComponent = _portal.default) {
165
165
  setInternalOpen(nextOpen);
166
166
  }
167
167
  });
168
+
169
+ // Support ref
170
+ const isOpen = (0, _useEvent.default)(() => mergedOpen);
168
171
  (0, _useLayoutEffect.default)(() => {
169
172
  setInternalOpen(popupVisible || false);
170
173
  }, [popupVisible]);
@@ -197,9 +200,7 @@ function generateTrigger(PortalComponent = _portal.default) {
197
200
  (0, _useLayoutEffect.default)(() => {
198
201
  if (uniqueContext && unique && targetEle && !openUncontrolled && !parentContext) {
199
202
  if (mergedOpen) {
200
- Promise.resolve().then(() => {
201
- uniqueContext.show(getUniqueOptions(0));
202
- });
203
+ uniqueContext.show(getUniqueOptions(0), isOpen);
203
204
  } else {
204
205
  uniqueContext.hide(0);
205
206
  }
@@ -238,7 +239,7 @@ function generateTrigger(PortalComponent = _portal.default) {
238
239
  // If there is a parentContext, don't call uniqueContext methods
239
240
  if (uniqueContext && unique && openUncontrolled && !parentContext) {
240
241
  if (nextOpen) {
241
- uniqueContext.show(getUniqueOptions(delay));
242
+ uniqueContext.show(getUniqueOptions(delay), isOpen);
242
243
  } else {
243
244
  uniqueContext.hide(delay);
244
245
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rc-component/trigger",
3
- "version": "3.6.2",
3
+ "version": "3.6.3",
4
4
  "description": "base abstract trigger component for react",
5
5
  "engines": {
6
6
  "node": ">=8.x"