UNPKG

@carbon/react

Version:

React components for the Carbon Design System

26 lines (24 loc) 828 B
/** * Copyright IBM Corp. 2016, 2026 * * This source code is licensed under the Apache-2.0 license found in the * LICENSE file in the root directory of this source tree. */ //#region src/tools/events.ts /** * Composes multiple event handler functions into a single event handler. The * composed handler calls each provided function sequentially with the event and * any additional arguments. If any handler calls `event.preventDefault()`, * further handlers are skipped. * * @param handlers - An array of event handler functions. * @returns A composite event handler. */ const composeEventHandlers = (handlers) => (event, ...args) => { for (const handler of handlers) { if (event.defaultPrevented) break; if (typeof handler === "function") handler(event, ...args); } }; //#endregion export { composeEventHandlers };