UNPKG

@ark-ui/react

Version:

A collection of unstyled, accessible UI components for React, utilizing state machines for seamless interaction.

27 lines (23 loc) 703 B
'use client'; 'use strict'; Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); function waitForEvent(target, event, options) { let cleanup; const { predicate, ...listenerOptions } = options ?? {}; const promise = new Promise((resolve) => { const element = target?.(); if (!element) { return; } const handler = (e) => { if (!predicate || predicate(element)) { resolve(e); cleanup?.(); } }; element.addEventListener(event, handler, listenerOptions); cleanup = () => element.removeEventListener(event, handler, listenerOptions); }); return [promise, () => cleanup?.()]; } exports.waitForEvent = waitForEvent;