utils/react: add preventDefault helpers

These can be used instead of always having to add a comment explaining
what preventDefault does in a given context.
This commit is contained in:
David Lechner
2022-03-12 14:57:30 -06:00
parent d8f958d18e
commit c229d407cf
8 changed files with 36 additions and 20 deletions
+16
View File
@@ -0,0 +1,16 @@
// helper functions for React components
import React from 'react';
/**
* Callback that can be passed to onMouseDown event handlers to prevent
* an element from becoming focused when clicked.
*/
export const preventFocusOnClick: React.MouseEventHandler = (e) => e.preventDefault();
/**
* Callback that can be passed to onContextMenu event handlers to prevent
* the native browser context menu from being shown.
*/
export const preventBrowserNativeContextMenu: React.MouseEventHandler = (e) =>
e.preventDefault();