@base-ui/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.
40 lines (39 loc) • 1.57 kB
JavaScript
import { isAndroid, isJSDOM } from '@base-ui/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/main/packages/@react-aria/utils/src/isVirtualEvent.ts
export function isVirtualClick(event) {
if (event.pointerType === '' && 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);
}
export function isClickLikeEvent(event) {
const type = event.type;
return type === 'click' || type === 'mousedown' || type === 'keydown' || type === 'keyup';
}