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
do not propagate events through portal #1840
Changes from all commits
072a502
02f3698
cf8bb59
86a806e
a802ded
6f6887a
7bf4868
2d851fd
5b2ded5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -210,11 +210,10 @@ export function usePress(props: PressHookProps): PressResult { | |
|
||
let pressProps: HTMLAttributes<HTMLElement> = { | ||
onKeyDown(e) { | ||
if (isValidKeyboardEvent(e.nativeEvent)) { | ||
if (isValidKeyboardEvent(e.nativeEvent) && e.currentTarget.contains(e.target as HTMLElement)) { | ||
e.preventDefault(); | ||
e.stopPropagation(); | ||
|
||
|
||
// If the event is repeating, it may have started on a different element | ||
// after which focus moved to the current element. Ignore these events and | ||
// only handle the first key down event. | ||
|
@@ -230,11 +229,15 @@ export function usePress(props: PressHookProps): PressResult { | |
} | ||
}, | ||
onKeyUp(e) { | ||
if (isValidKeyboardEvent(e.nativeEvent) && !e.repeat) { | ||
if (isValidKeyboardEvent(e.nativeEvent) && !e.repeat && e.currentTarget.contains(e.target as HTMLElement)) { | ||
triggerPressUp(createEvent(state.target, e), 'keyboard'); | ||
} | ||
}, | ||
onClick(e) { | ||
if (e && !e.currentTarget.contains(e.target as HTMLElement)) { | ||
return; | ||
} | ||
|
||
if (e && e.button === 0) { | ||
e.stopPropagation(); | ||
if (isDisabled) { | ||
|
@@ -279,8 +282,8 @@ export function usePress(props: PressHookProps): PressResult { | |
|
||
if (typeof PointerEvent !== 'undefined') { | ||
pressProps.onPointerDown = (e) => { | ||
// Only handle left clicks | ||
if (e.button !== 0) { | ||
// Only handle left clicks, and ignore events that bubbled through portals. | ||
if (e.button !== 0 || !e.currentTarget.contains(e.target as HTMLElement)) { | ||
return; | ||
} | ||
|
||
|
@@ -315,6 +318,10 @@ export function usePress(props: PressHookProps): PressResult { | |
}; | ||
|
||
pressProps.onMouseDown = (e) => { | ||
if (!e.currentTarget.contains(e.target as HTMLElement)) { | ||
return; | ||
} | ||
|
||
if (e.button === 0) { | ||
// Chrome and Firefox on touch Windows devices require mouse down events | ||
// to be canceled in addition to pointer events, or an extra asynchronous | ||
|
@@ -328,6 +335,10 @@ export function usePress(props: PressHookProps): PressResult { | |
}; | ||
|
||
pressProps.onPointerUp = (e) => { | ||
if (!e.currentTarget.contains(e.target as HTMLElement)) { | ||
return; | ||
} | ||
|
||
// Only handle left clicks | ||
// Safari on iOS sometimes fires pointerup events, even | ||
// when the touch isn't over the target, so double check. | ||
|
@@ -377,13 +388,17 @@ export function usePress(props: PressHookProps): PressResult { | |
}; | ||
|
||
pressProps.onDragStart = (e) => { | ||
if (!e.currentTarget.contains(e.target as HTMLElement)) { | ||
return; | ||
} | ||
|
||
// Safari does not call onPointerCancel when a drag starts, whereas Chrome and Firefox do. | ||
cancel(e); | ||
}; | ||
} else { | ||
pressProps.onMouseDown = (e) => { | ||
// Only handle left clicks | ||
if (e.button !== 0) { | ||
if (e.button !== 0 || !e.currentTarget.contains(e.target as HTMLElement)) { | ||
return; | ||
} | ||
|
||
|
@@ -413,6 +428,10 @@ export function usePress(props: PressHookProps): PressResult { | |
}; | ||
|
||
pressProps.onMouseEnter = (e) => { | ||
if (!e.currentTarget.contains(e.target as HTMLElement)) { | ||
return; | ||
} | ||
|
||
e.stopPropagation(); | ||
if (state.isPressed && !state.ignoreEmulatedMouseEvents) { | ||
state.isOverTarget = true; | ||
|
@@ -421,6 +440,10 @@ export function usePress(props: PressHookProps): PressResult { | |
}; | ||
|
||
pressProps.onMouseLeave = (e) => { | ||
if (!e.currentTarget.contains(e.target as HTMLElement)) { | ||
return; | ||
} | ||
|
||
e.stopPropagation(); | ||
if (state.isPressed && !state.ignoreEmulatedMouseEvents) { | ||
state.isOverTarget = false; | ||
|
@@ -429,6 +452,10 @@ export function usePress(props: PressHookProps): PressResult { | |
}; | ||
|
||
pressProps.onMouseUp = (e) => { | ||
if (!e.currentTarget.contains(e.target as HTMLElement)) { | ||
return; | ||
} | ||
|
||
if (!state.ignoreEmulatedMouseEvents && e.button === 0) { | ||
triggerPressUp(e, state.pointerType); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make sure we get all of the events assigned to pressProps. I think maybe touch events are missing? Is there a reason they were not included? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think i had placed them all the functions with an event, but i couldn't tell if they were doing anything or not. should i go ahead and place them in all the pressProps events? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah all of the ones that are on pressProps, not global listeners. |
||
|
@@ -458,6 +485,10 @@ export function usePress(props: PressHookProps): PressResult { | |
}; | ||
|
||
pressProps.onTouchStart = (e) => { | ||
if (!e.currentTarget.contains(e.target as HTMLElement)) { | ||
return; | ||
} | ||
|
||
e.stopPropagation(); | ||
let touch = getTouchFromEvent(e.nativeEvent); | ||
if (!touch) { | ||
|
@@ -483,6 +514,10 @@ export function usePress(props: PressHookProps): PressResult { | |
}; | ||
|
||
pressProps.onTouchMove = (e) => { | ||
if (!e.currentTarget.contains(e.target as HTMLElement)) { | ||
return; | ||
} | ||
|
||
e.stopPropagation(); | ||
if (!state.isPressed) { | ||
return; | ||
|
@@ -501,6 +536,10 @@ export function usePress(props: PressHookProps): PressResult { | |
}; | ||
|
||
pressProps.onTouchEnd = (e) => { | ||
if (!e.currentTarget.contains(e.target as HTMLElement)) { | ||
return; | ||
} | ||
|
||
e.stopPropagation(); | ||
if (!state.isPressed) { | ||
return; | ||
|
@@ -523,6 +562,10 @@ export function usePress(props: PressHookProps): PressResult { | |
}; | ||
|
||
pressProps.onTouchCancel = (e) => { | ||
if (!e.currentTarget.contains(e.target as HTMLElement)) { | ||
return; | ||
} | ||
|
||
e.stopPropagation(); | ||
if (state.isPressed) { | ||
cancel(e); | ||
|
@@ -541,6 +584,10 @@ export function usePress(props: PressHookProps): PressResult { | |
}; | ||
|
||
pressProps.onDragStart = (e) => { | ||
if (!e.currentTarget.contains(e.target as HTMLElement)) { | ||
return; | ||
} | ||
|
||
cancel(e); | ||
}; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to do the check for keyboard events as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah most likely. i'll see if i can add a good test for that