events

Stops propagation and prevents the default handler of the given event.

Type signature

(event: {
    preventDefault: () => void;
    stopPropagation: () => void;
}) => boolean

Examples

const event = {
  preventDefault: () =>
    console.log("preventDefault"),
  stopPropagation: () =>
    console.log("stopPropagation"),
};

cancel(event);
Try in REPL

Questions

  • How to stop event propagation and prevent default at once?

TypeScript sourceJavaScript source

Tests if the current event seems like an intent to open a new tab. Useful for client-side navigation handling.

Type signature

({ button, ctrlKey, metaKey, shiftKey }: {
    button?: number;
    ctrlKey?: boolean;
    metaKey?: boolean;
    shiftKey?: boolean;
}) => boolean

Examples

openInNewTabIntent({
  ctrlKey: true,
});
// ⇒ true
Try in REPL

Questions

  • How to check if the user wants to open a new tab using history API?

TypeScript sourceJavaScript source

Prevents the default handler of the given event.

Type signature

(event: {
    preventDefault: () => void;
}) => boolean

Examples

const event = {
  preventDefault: () =>
    console.log("preventDefault"),
  stopPropagation: () =>
    console.log("stopPropagation"),
};

prevent(event);
Try in REPL

Questions

  • How to prevent default event handler?

TypeScript sourceJavaScript source

Stops propagation of the given event.

Type signature

(event: {
    stopPropagation: () => void;
}) => boolean

Examples

const event = {
  preventDefault: () =>
    console.log("preventDefault"),
  stopPropagation: () =>
    console.log("stopPropagation"),
};

stop(event);
Try in REPL

Questions

  • How to stop the propagation of an event?

TypeScript sourceJavaScript source