Skip to content

Commit

Permalink
Add rudamentary Pointer Event polyfill
Browse files Browse the repository at this point in the history
  • Loading branch information
seancolsen committed Mar 24, 2022
1 parent 449a244 commit c7c83a2
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions mathesar_ui/src/component-library/common/actions/clickOffBounds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,30 @@ export default function clickOffBounds(
}
}

document.body.addEventListener('pointerdown', outOfBoundsListener, true);
/**
* When the browser supports pointer events, we use the pointerdown event
* which is fired for all mouse buttons and touches. However, older Safari
* versions don't have pointer events, so we fallback to mouse events. Touches
* should fire a mousedown event too.
*/
const events =
'onpointerdown' in document.body
? ['pointerdown']
: ['mousedown', 'contextmenu'];

events.forEach((event) => {
document.body.addEventListener(event, outOfBoundsListener, true);
});

function update(opts: Options) {
callback = opts.callback;
references = opts.references;
}

function destroy() {
document.body.removeEventListener('pointerdown', outOfBoundsListener, true);
events.forEach((event) => {
document.body.removeEventListener(event, outOfBoundsListener, true);
});
}

return {
Expand Down

0 comments on commit c7c83a2

Please sign in to comment.