UNPKG

@kubit-ui-web/react-components

Version:

Kubit React Components is a customizable, accessible library of React web components, designed to enhance your application's user experience

24 lines 836 B
import React from 'react'; export const useEscPressedV2 = ({ ref, onEscPress, disablePreventDefault = false, disableStopPropagation = false, }) => { React.useEffect(() => { if (!ref.current) { return; } const handleKeyDown = (event) => { if (event.key === 'Escape') { if (!disablePreventDefault) { event.preventDefault(); } if (!disableStopPropagation) { event.stopPropagation(); } onEscPress(event); } }; ref.current.addEventListener('keydown', handleKeyDown); return () => { ref.current?.removeEventListener('keydown', handleKeyDown); }; }, [onEscPress]); }; //# sourceMappingURL=useEscPressedV2.js.map