Skip to content

Commit 6f0a87a

Browse files
committed
Possible fix for click: require mouse down AND mouse up events
1 parent bc93625 commit 6f0a87a

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

cli/src/components/button.tsx

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { cloneElement, isValidElement, memo, type ReactElement, type ReactNode } from 'react'
1+
import React, { cloneElement, isValidElement, memo, useRef, type ReactElement, type ReactNode } from 'react'
22

33
interface ButtonProps {
44
onClick?: (e?: unknown) => void | Promise<unknown>
@@ -37,13 +37,36 @@ function makeTextUnselectable(node: ReactNode): ReactNode {
3737

3838
export const Button = memo(({ onClick, onMouseOver, onMouseOut, style, children, ...rest }: ButtonProps) => {
3939
const processedChildren = makeTextUnselectable(children)
40+
// Track whether mouse down occurred on this element to implement proper click detection
41+
// This prevents hover from triggering clicks in some terminals
42+
const mouseDownRef = useRef(false)
43+
44+
const handleMouseDown = () => {
45+
mouseDownRef.current = true
46+
}
47+
48+
const handleMouseUp = (e?: unknown) => {
49+
// Only trigger click if mouse down happened on this element
50+
if (mouseDownRef.current && onClick) {
51+
onClick(e)
52+
}
53+
mouseDownRef.current = false
54+
}
55+
56+
const handleMouseOut = () => {
57+
// Reset mouse down state when leaving the element
58+
mouseDownRef.current = false
59+
onMouseOut?.()
60+
}
61+
4062
return (
4163
<box
4264
{...rest}
4365
style={style}
44-
onMouseDown={onClick}
66+
onMouseDown={handleMouseDown}
67+
onMouseUp={handleMouseUp}
4568
onMouseOver={onMouseOver}
46-
onMouseOut={onMouseOut}
69+
onMouseOut={handleMouseOut}
4770
>
4871
{processedChildren}
4972
</box>

0 commit comments

Comments
 (0)