Skip to content

Commit d99dfbc

Browse files
committed
fix: modal prevent dimiss when mouse select text
Signed-off-by: Innei <i@innei.in>
1 parent df2ecb6 commit d99dfbc

File tree

1 file changed

+23
-3
lines changed
  • src/renderer/src/components/ui/modal/stacked

1 file changed

+23
-3
lines changed

src/renderer/src/components/ui/modal/stacked/modal.tsx

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,26 @@ export const ModalInternal = memo(
221221
() => ({ ...zIndexStyle, ...resizeableStyle }),
222222
[resizeableStyle, zIndexStyle],
223223
)
224+
const isSelectingRef = useRef(false)
225+
const handleSelectStart = useCallback(() => {
226+
isSelectingRef.current = true
227+
}, [])
228+
const handleDetectSelectEnd = useCallback(() => {
229+
nextFrame(() => {
230+
if (isSelectingRef.current) {
231+
isSelectingRef.current = false
232+
}
233+
})
234+
}, [])
224235

236+
const handleClickOutsideToDismiss = useCallback(
237+
(e: SyntheticEvent) => {
238+
if (isSelectingRef.current) return
239+
const fn = modal ? (clickOutsideToDismiss && canClose ? dismiss : noticeModal) : undefined
240+
fn?.(e)
241+
},
242+
[canClose, clickOutsideToDismiss, dismiss, modal, noticeModal],
243+
)
225244
useImperativeHandle(ref, () => modalElementRef.current!)
226245
if (CustomModalComponent) {
227246
return (
@@ -276,9 +295,8 @@ export const ModalInternal = memo(
276295
modalContainerClassName,
277296
!isResizeable && "center",
278297
)}
279-
onClick={
280-
modal ? (clickOutsideToDismiss && canClose ? dismiss : noticeModal) : undefined
281-
}
298+
onPointerUp={handleDetectSelectEnd}
299+
onClick={handleClickOutsideToDismiss}
282300
>
283301
{DragBar}
284302

@@ -299,6 +317,8 @@ export const ModalInternal = memo(
299317
modalClassName,
300318
)}
301319
onClick={stopPropagation}
320+
onSelect={handleSelectStart}
321+
onKeyUp={handleDetectSelectEnd}
302322
drag
303323
dragControls={dragController}
304324
dragElastic={0}

0 commit comments

Comments
 (0)