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 (#539)

* fix: Fixes bug where clicking on the canvas did not remove focus from other elements

* refactor: Prevent blurring of the canvas if the canvas is being clicked
  • Loading branch information
ShrimpCryptid authored Feb 11, 2025
1 parent 55e3766 commit 0fea06b
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 !== canv.domElement) {
document.activeElement.blur();
}

isMouseDragging.current = false;

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

0 comments on commit 0fea06b

Please sign in to comment.