Implementing a MouseLeaveHandler.

This commit is contained in:
Eric van der Vlist 2022-09-08 15:35:39 +02:00
parent 0fb7f47207
commit c409633017
1 changed files with 11 additions and 1 deletions

View File

@ -25,7 +25,7 @@ const Viewport: react.FC<{}> = (props: {}) => {
console.log('mouseState: ' + JSON.stringify(mouseState)); console.log('mouseState: ' + JSON.stringify(mouseState));
}; };
// TODO: implement resize and focusout or blur events // TODO: implement resize event
// TODO: check boundaries // TODO: check boundaries
const mouseDownHandler = (event: any) => { const mouseDownHandler = (event: any) => {
@ -37,6 +37,15 @@ const Viewport: react.FC<{}> = (props: {}) => {
}); });
}; };
const mouseLeaveHandler = (event: any) => {
genericHandler(event);
event.preventDefault();
throtteledMouseMoveHandler.cancel();
setMouseState(initialMouseState);
};
const mouseUpHandler = (event: any) => { const mouseUpHandler = (event: any) => {
genericHandler(event); genericHandler(event);
event.preventDefault(); event.preventDefault();
@ -83,6 +92,7 @@ const Viewport: react.FC<{}> = (props: {}) => {
onMouseDown={mouseDownHandler} onMouseDown={mouseDownHandler}
onMouseMove={throtteledMouseMoveHandler} onMouseMove={throtteledMouseMoveHandler}
onMouseUp={mouseUpHandler} onMouseUp={mouseUpHandler}
onMouseLeave={mouseLeaveHandler}
> >
<Background shift={shift} /> <Background shift={shift} />
</div> </div>