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.

38 lines (37 loc) 1.62 kB
import { isAndroid, isJSDOM } from '@base-ui-components/utils/detectBrowser'; export function stopEvent(event) { event.preventDefault(); event.stopPropagation(); } export function isReactEvent(event) { return 'nativeEvent' in event; } // License: https://github.com/adobe/react-spectrum/blob/b35d5c02fe900badccd0cf1a8f23bb593419f238/packages/@react-aria/utils/src/isVirtualEvent.ts export function isVirtualClick(event) { // FIXME: Firefox is now emitting a deprecation warning for `mozInputSource`. // Try to find a workaround for this. `react-aria` source still has the check. if (event.mozInputSource === 0 && event.isTrusted) { return true; } if (isAndroid && event.pointerType) { return event.type === 'click' && event.buttons === 1; } return event.detail === 0 && !event.pointerType; } export function isVirtualPointerEvent(event) { if (isJSDOM) { return false; } return !isAndroid && event.width === 0 && event.height === 0 || isAndroid && event.width === 1 && event.height === 1 && event.pressure === 0 && event.detail === 0 && event.pointerType === 'mouse' || // iOS VoiceOver returns 0.333• for width/height. event.width < 1 && event.height < 1 && event.pressure === 0 && event.detail === 0 && event.pointerType === 'touch'; } export function isMouseLikePointerType(pointerType, strict) { // On some Linux machines with Chromium, mouse inputs return a `pointerType` // of "pen": https://github.com/floating-ui/floating-ui/issues/2015 const values = ['mouse', 'pen']; if (!strict) { values.push('', undefined); } return values.includes(pointerType); }