-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bugs when close & unmount multiple overlays #108
Comments
I was curious about this issue too, so I tried to find out what was causing it. 🧐 Problem situationAs you said, the problem is that we only use In this comment, I'm going to talk about the following flow. open `modal with close` -> close `modal with close` -> open `modal with unmount` -> unmount `modal with unmount` Problem with logic related to
|
if (prevCurrent.current !== current) { | |
prevCurrent.current = current; | |
if (current === overlayId) { | |
onMountedRef.current(); | |
} | |
} |
close.unmount.current.mov
Is it necessary to have different current
logic in close
and remove
?
When I thought about the problem, I realized that the current
in close
is configured correctly.
The logic current
in the close
event is as follows.
overlay-kit/packages/src/context/reducer.ts
Lines 47 to 65 in 9945f49
const openedOverlayOrderList = state.overlayOrderList.filter( | |
(orderedOverlayId) => state.overlayData[orderedOverlayId].isOpen === true | |
); | |
const targetIndexInOpenedList = openedOverlayOrderList.findIndex((item) => item === action.overlayId); | |
/** | |
* @description If closing the last overlay, specify the overlay before it. | |
* @description If closing intermediate overlays, specifies the last overlay. | |
* | |
* @example open - [1, 2, 3, 4] | |
* close 2 => current: 4 | |
* close 4 => current: 3 | |
* close 3 => current: 1 | |
* close 1 => current: null | |
*/ | |
const currentOverlayId = | |
targetIndexInOpenedList === openedOverlayOrderList.length - 1 | |
? openedOverlayOrderList[targetIndexInOpenedList - 1] ?? null | |
: openedOverlayOrderList.at(-1) ?? null; |
When I saw that code, I wondered if I could replace the close
part with unmount
and use it as is.
/**
* @description If unmounting the last overlay, specify the overlay before it.
* @description If unmounting intermediate overlays, specifies the last overlay.
*
* @example open - [1, 2, 3, 4]
* unmount 2 => current: 4
* unmount 4 => current: 3
* unmount 3 => current: 1
* unmount 1 => current: null
*/
close.current.unmount.mov
Test branch related to the issue
If you find anything wrong, please feel free to comment. 🙇♂️
Issue Description:
There is an error in the example below of docs.
After closing the overlay using the close method,
If you open a new overlay and close the overlay using the unmount method,
the overlay that you opened with the close method will reopen.
Example:
Video
2025-02-05.6.12.28.mov
Code
The text was updated successfully, but these errors were encountered: