UNPKG

@base-ui-components/react

Version:

Base UI is a library of headless ('unstyled') React components and low-level hooks. You gain complete control over your app's CSS and accessibility features.

34 lines (32 loc) 955 B
'use client'; import * as React from 'react'; import { useEventCallback } from '@base-ui-components/utils/useEventCallback'; import { useEnhancedClickHandler } from '@base-ui-components/utils/useEnhancedClickHandler'; /** * Determines the interaction type (keyboard, mouse, touch, etc.) that opened the component. * * @param open The open state of the component. */ export function useOpenInteractionType(open) { const [openMethod, setOpenMethod] = React.useState(null); const handleTriggerClick = useEventCallback((_, interactionType) => { if (!open) { setOpenMethod(interactionType); } }); const reset = useEventCallback(() => { setOpenMethod(null); }); const { onClick, onPointerDown } = useEnhancedClickHandler(handleTriggerClick); return React.useMemo(() => ({ openMethod, reset, triggerProps: { onClick, onPointerDown } }), [openMethod, reset, onClick, onPointerDown]); }