@atlaskit/button
Version:
A button triggers an event or action. They let users know what will happen next.
33 lines • 833 B
JavaScript
function abort(event) {
event.preventDefault();
event.stopPropagation();
}
const tabKeyCode = 9;
function onKey(event) {
// Allowing tab so that a user can move focus away
if (event.keyCode === tabKeyCode) {
return;
}
abort(event);
}
const block = {
onMouseDownCapture: abort,
onMouseUpCapture: abort,
// because we have tabIndex = -1 when disabled,
// keyboard events can only occur when there is an overlay
onKeyDownCapture: onKey,
onKeyUpCapture: onKey,
onTouchStartCapture: abort,
onTouchEndCapture: abort,
onPointerDownCapture: abort,
onPointerUpCapture: abort,
onClickCapture: abort,
// Just smashing the existing onClick for good measure
onClick: abort
};
const doNotBlock = {};
export default function blockEvents({
isInteractive
}) {
return isInteractive ? doNotBlock : block;
}