Skip to content

Commit

Permalink
fix: Fixes bug where clicking on the canvas did not remove focus from…
Browse files Browse the repository at this point in the history
… other elements
  • Loading branch information
ShrimpCryptid committed Feb 4, 2025
1 parent c30f799 commit 5c590dd
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/components/CanvasWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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.blur();
}

isMouseDragging.current = false;

if (event.button === MIDDLE_CLICK_BUTTON) {
Expand Down

0 comments on commit 5c590dd

Please sign in to comment.