UNPKG

perlite

Version:

[![perlite logo](/docs/logo.svg)]()

18 lines (14 loc) 483 B
import { directive, EventPart } from 'lit-html'; export const prevent = directive((handler) => (part) => { if (!(part instanceof EventPart)) { throw new Error('"prevent" directive can only be used in event listeners'); } const { handleEvent, ...options } = handler; part.setValue({ handleEvent: function (event) { event.preventDefault(); (handleEvent || handler).call(this, event); }, ...options }); });