-
Notifications
You must be signed in to change notification settings - Fork 1
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
fix: Fixes bug where clicking on the canvas did not remove focus from other elements #539
Changes from all commits
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 |
---|---|---|
|
@@ -489,9 +489,9 @@ export default function CanvasWrapper(inputProps: CanvasWrapperProps): ReactElem | |
|
||
const onMouseClick = useCallback( | ||
(event: MouseEvent): void => { | ||
// Note that click events won't fire until the mouse is released. We need to check | ||
// if the mouse was dragged before treating the click as a track selection; otherwise | ||
// the track selection gets changed unexpectedly. | ||
// Note that click events won't fire until the mouse is released. We need | ||
// to check if the mouse was dragged before treating the click as a track | ||
// selection; otherwise the track selection gets changed unexpectedly. | ||
if (!isMouseDragging.current) { | ||
handleTrackSelection(event); | ||
} | ||
|
@@ -506,7 +506,14 @@ export default function CanvasWrapper(inputProps: CanvasWrapperProps): ReactElem | |
}, []); | ||
|
||
const onMouseDown = useCallback((event: MouseEvent): void => { | ||
event.preventDefault(); // Prevent text selection | ||
// Prevent the default behavior for mouse clicks that would cause text | ||
// selection, but keep the behavior where focus is removed from other | ||
// elements. | ||
event.preventDefault(); | ||
if (document.activeElement instanceof HTMLElement && document.activeElement !== canv.domElement) { | ||
document.activeElement.blur(); | ||
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. will it blur itself too? 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. Ooh, good question. I don't think blurring itself would do anything because it's not an element that has focus behavior or styling, but I'll add a check in and skip blurring if it's the same element. Thank you! |
||
} | ||
|
||
isMouseDragging.current = false; | ||
|
||
if (event.button === MIDDLE_CLICK_BUTTON) { | ||
|
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.
This was what was causing the bug, but
event.preventDefault
is still mostly desired behavior. Simulate the focus behavior by blurring the active element in the document.