Comprehensive library of unstyled React hooks providing accessible UI primitives with full WAI-ARIA compliance and internationalization support.
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Low-level interaction hooks for handling user input across different devices and interaction models. These hooks provide normalized event handling for mouse, touch, keyboard, and screen reader interactions.
Provides press interaction handling across mouse, touch, and keyboard.
/**
* Provides press interaction handling
* @param props - Press configuration
* @returns Press result with event handlers
*/
function usePress(props: PressHookProps): PressResult;
interface PressHookProps extends PressProps {
/** Ref to the target element */
ref?: RefObject<Element>;
}
interface PressProps {
/** Handler called when press starts */
onPressStart?: (e: PressEvent) => void;
/** Handler called when press ends */
onPressEnd?: (e: PressEvent) => void;
/** Handler called when press changes */
onPressChange?: (isPressed: boolean) => void;
/** Handler called when press is released over target */
onPressUp?: (e: PressEvent) => void;
/** Handler called when press is completed */
onPress?: (e: PressEvent) => void;
/** Whether press events are disabled */
isDisabled?: boolean;
/** Whether to prevent focus on press (mobile) */
preventFocusOnPress?: boolean;
/** Whether press should cancel when pointer exits */
shouldCancelOnPointerExit?: boolean;
/** Whether text selection should be allowed during press */
allowTextSelectionOnPress?: boolean;
}
interface PressResult {
/** Whether the element is currently pressed */
isPressed: boolean;
/** Props to spread on the target element */
pressProps: DOMAttributes<Element>;
}
interface PressEvent {
/** Type of press event */
type: 'pressstart' | 'pressend' | 'pressup' | 'press';
/** Input type that triggered the event */
pointerType: 'mouse' | 'pen' | 'touch' | 'keyboard' | 'virtual';
/** Target element */
target: Element;
/** Whether shift key was pressed */
shiftKey: boolean;
/** Whether ctrl key was pressed */
ctrlKey: boolean;
/** Whether meta key was pressed */
metaKey: boolean;
/** Whether alt key was pressed */
altKey: boolean;
/** X coordinate relative to target */
x: number;
/** Y coordinate relative to target */
y: number;
/** Continue propagation */
continuePropagation(): void;
}Provides long press interaction handling with customizable delay.
/**
* Provides long press interaction handling
* @param props - Long press configuration
* @returns Long press result with event handlers
*/
function useLongPress(props: LongPressProps): LongPressResult;
interface LongPressProps {
/** Whether long press is disabled */
isDisabled?: boolean;
/** Handler called when long press is triggered */
onLongPressStart?: (e: LongPressEvent) => void;
/** Handler called when long press ends */
onLongPressEnd?: (e: LongPressEvent) => void;
/** Handler called when long press completes */
onLongPress?: (e: LongPressEvent) => void;
/** Long press threshold in milliseconds */
threshold?: number;
/** Accessibility description for long press action */
accessibilityDescription?: string;
}
interface LongPressResult {
/** Props to spread on the target element */
longPressProps: DOMAttributes<Element>;
}
interface LongPressEvent {
/** Type of long press event */
type: 'longpressstart' | 'longpressend' | 'longpress';
/** Input type that triggered the event */
pointerType: 'mouse' | 'pen' | 'touch' | 'keyboard' | 'virtual';
/** Target element */
target: Element;
/** Whether shift key was pressed */
shiftKey: boolean;
/** Whether ctrl key was pressed */
ctrlKey: boolean;
/** Whether meta key was pressed */
metaKey: boolean;
/** Whether alt key was pressed */
altKey: boolean;
}Provides hover interaction handling with proper touch device support.
/**
* Provides hover interaction handling
* @param props - Hover configuration
* @returns Hover result with event handlers
*/
function useHover(props: HoverProps): HoverResult;
interface HoverProps {
/** Handler called when hover starts */
onHoverStart?: (e: HoverEvent) => void;
/** Handler called when hover ends */
onHoverEnd?: (e: HoverEvent) => void;
/** Handler called when hover changes */
onHoverChange?: (isHovering: boolean) => void;
/** Whether hover is disabled */
isDisabled?: boolean;
}
interface HoverResult {
/** Props to spread on the target element */
hoverProps: DOMAttributes<Element>;
/** Whether the element is currently hovered */
isHovered: boolean;
}
interface HoverEvent {
/** Type of hover event */
type: 'hoverstart' | 'hoverend';
/** Input type that triggered the event */
pointerType: 'mouse' | 'pen';
/** Target element */
target: Element;
}Provides focus event handling with proper event normalization.
/**
* Provides focus event handling
* @param props - Focus configuration
* @returns Focus result with event handlers
*/
function useFocus(props: FocusProps): FocusResult;
interface FocusProps {
/** Whether focus events are disabled */
isDisabled?: boolean;
/** Handler called when element receives focus */
onFocus?: (e: FocusEvent) => void;
/** Handler called when element loses focus */
onBlur?: (e: FocusEvent) => void;
/** Handler called when focus changes */
onFocusChange?: (isFocused: boolean) => void;
}
interface FocusResult {
/** Props to spread on the target element */
focusProps: DOMAttributes<Element>;
}Provides focus-visible state management for keyboard navigation styling.
/**
* Provides focus-visible state management
* @param props - Focus visible configuration
* @returns Focus visible result with state
*/
function useFocusVisible(props?: FocusVisibleProps): FocusVisibleResult;
interface FocusVisibleProps {
/** Whether focus visible is disabled */
isDisabled?: boolean;
/** Auto-focus behavior */
autoFocus?: boolean;
}
interface FocusVisibleResult {
/** Whether focus is visible */
isFocusVisible: boolean;
}Provides focus-within state tracking for container elements.
/**
* Provides focus-within state tracking
* @param props - Focus within configuration
* @returns Focus within result with event handlers
*/
function useFocusWithin(props: FocusWithinProps): FocusWithinResult;
interface FocusWithinProps {
/** Whether focus within is disabled */
isDisabled?: boolean;
/** Handler called when focus enters the container */
onFocusWithin?: (e: FocusEvent) => void;
/** Handler called when focus leaves the container */
onBlurWithin?: (e: FocusEvent) => void;
/** Handler called when focus within changes */
onFocusWithinChange?: (isFocusWithin: boolean) => void;
}
interface FocusWithinResult {
/** Props to spread on the container element */
focusWithinProps: DOMAttributes<Element>;
/** Whether focus is within the container */
isFocusWithin: boolean;
}Provides keyboard event handling with normalized key handling.
/**
* Provides keyboard event handling
* @param props - Keyboard configuration
* @returns Keyboard result with event handlers
*/
function useKeyboard(props: KeyboardProps): KeyboardResult;
interface KeyboardProps {
/** Whether keyboard events are disabled */
isDisabled?: boolean;
/** Handler called on key down */
onKeyDown?: (e: KeyboardEvent) => void;
/** Handler called on key up */
onKeyUp?: (e: KeyboardEvent) => void;
}
interface KeyboardResult {
/** Props to spread on the target element */
keyboardProps: DOMAttributes<Element>;
}Provides move/drag interaction handling for pointer events.
/**
* Provides move/drag interaction handling
* @param props - Move configuration
* @returns Move result with event handlers
*/
function useMove(props: MoveEvents): MoveResult;
interface MoveEvents {
/** Handler called when move starts */
onMoveStart?: (e: MoveStartEvent) => void;
/** Handler called during move */
onMove?: (e: MoveMoveEvent) => void;
/** Handler called when move ends */
onMoveEnd?: (e: MoveEndEvent) => void;
}
interface MoveResult {
/** Props to spread on the target element */
moveProps: DOMAttributes<Element>;
}
interface MoveStartEvent {
/** Type of move event */
type: 'movestart';
/** Input type */
pointerType: 'mouse' | 'pen' | 'touch' | 'keyboard' | 'virtual';
/** Whether shift key was pressed */
shiftKey: boolean;
/** Whether ctrl key was pressed */
ctrlKey: boolean;
/** Whether meta key was pressed */
metaKey: boolean;
/** Whether alt key was pressed */
altKey: boolean;
}
interface MoveMoveEvent {
/** Type of move event */
type: 'move';
/** Input type */
pointerType: 'mouse' | 'pen' | 'touch' | 'keyboard' | 'virtual';
/** Delta X movement */
deltaX: number;
/** Delta Y movement */
deltaY: number;
/** Whether shift key was pressed */
shiftKey: boolean;
/** Whether ctrl key was pressed */
ctrlKey: boolean;
/** Whether meta key was pressed */
metaKey: boolean;
/** Whether alt key was pressed */
altKey: boolean;
}
interface MoveEndEvent {
/** Type of move event */
type: 'moveend';
/** Input type */
pointerType: 'mouse' | 'pen' | 'touch' | 'keyboard' | 'virtual';
/** Whether shift key was pressed */
shiftKey: boolean;
/** Whether ctrl key was pressed */
ctrlKey: boolean;
/** Whether meta key was pressed */
metaKey: boolean;
/** Whether alt key was pressed */
altKey: boolean;
}Provides outside interaction detection for dismissing overlays.
/**
* Provides outside interaction detection
* @param props - Interact outside configuration
* @returns Event handlers for outside detection
*/
function useInteractOutside(props: InteractOutsideProps): void;
interface InteractOutsideProps {
/** Ref to the element to monitor */
ref: RefObject<Element>;
/** Handler called when interaction occurs outside */
onInteractOutside?: (e: InteractOutsideEvent) => void;
/** Whether interact outside is disabled */
isDisabled?: boolean;
/** Handler to determine if interaction should be ignored */
onInteractOutsideStart?: (e: InteractOutsideEvent) => void;
}
interface InteractOutsideEvent {
/** Type of interaction */
type: 'pointerdown' | 'pointerup' | 'focusin' | 'focusout';
/** Target element */
target: Element;
}Provides focusable element behavior with keyboard and screen reader support.
/**
* Provides focusable element behavior
* @param props - Focusable configuration
* @param ref - Ref to the focusable element
* @returns Focusable result with props and state
*/
function useFocusable(props: FocusableOptions, ref: RefObject<Element>): FocusableAria;
interface FocusableOptions {
/** Whether the element should exclude from tab order */
excludeFromTabOrder?: boolean;
/** Whether the element is disabled */
isDisabled?: boolean;
/** Auto-focus behavior */
autoFocus?: boolean;
}
interface FocusableAria {
/** Props to spread on the focusable element */
focusableProps: DOMAttributes<Element>;
}Provides comprehensive drag and drop interaction handling.
/**
* Provides drag behavior for elements
* @param options - Drag configuration
* @returns Drag result with props and state
*/
function useDrag(options: DragOptions): DragResult;
/**
* Provides drop behavior for elements
* @param options - Drop configuration
* @returns Drop result with props and state
*/
function useDrop(options: DropOptions): DropResult;
/**
* Provides draggable collection behavior
* @param options - Draggable collection configuration
* @returns Collection drag result
*/
function useDraggableCollection(options: DraggableCollectionOptions): DroppableCollectionResult;
/**
* Provides droppable collection behavior
* @param options - Droppable collection configuration
* @returns Collection drop result
*/
function useDroppableCollection(options: DroppableCollectionOptions): DroppableCollectionResult;
/**
* Provides individual draggable item behavior
* @param props - Draggable item configuration
* @returns Draggable item result
*/
function useDraggableItem(props: DraggableItemProps, ref: RefObject<Element>): DraggableItemResult;
/**
* Provides individual droppable item behavior
* @param options - Droppable item configuration
* @param ref - Ref to the droppable element
* @returns Droppable item result
*/
function useDroppableItem(options: DroppableItemOptions, ref: RefObject<Element>): DroppableItemResult;
/**
* Provides drop indicator behavior
* @param props - Drop indicator configuration
* @param ref - Ref to the indicator element
* @returns Drop indicator result
*/
function useDropIndicator(props: DropIndicatorProps, ref: RefObject<Element>): DropIndicatorAria;
/**
* Component for rendering drag previews
* @param props - Drag preview configuration
* @returns Drag preview component
*/
function DragPreview(props: DragPreviewProps): JSX.Element;
/**
* Drop target delegate for list components
*/
class ListDropTargetDelegate implements DropTargetDelegate {
/** Get drop target for a point */
getDropTarget(target: DropTarget, types: Set<string>): DropTarget | null;
/** Check if drop is allowed */
isValidDropTarget(target: DropTarget, types: Set<string>): boolean;
}
/**
* Constant for directory drag type
*/
const DIRECTORY_DRAG_TYPE: string;
/**
* Type guard to check if drop item is a directory
* @param item - Drop item to check
* @returns Whether item is a directory
*/
function isDirectoryDropItem(item: DropItem): item is DirectoryDropItem;
/**
* Type guard to check if drop item is a file
* @param item - Drop item to check
* @returns Whether item is a file
*/
function isFileDropItem(item: DropItem): item is FileDropItem;
/**
* Type guard to check if drop item is text
* @param item - Drop item to check
* @returns Whether item is text
*/
function isTextDropItem(item: DropItem): item is TextDropItem;
interface DragOptions {
/** Handler called when drag starts */
onDragStart?: (e: DragStartEvent) => void;
/** Handler called during drag */
onDragMove?: (e: DragMoveEvent) => void;
/** Handler called when drag ends */
onDragEnd?: (e: DragEndEvent) => void;
/** Get drag data for the operation */
getItems: () => DragItem[];
/** Preview component */
preview?: DragPreviewRenderer;
/** Whether drag is disabled */
isDisabled?: boolean;
}
interface DragResult {
/** Props for the draggable element */
dragProps: DOMAttributes<Element>;
/** Whether element is currently being dragged */
isDragging: boolean;
}
interface DropOptions {
/** Ref to the drop target element */
ref: RefObject<Element>;
/** Handler called when drop occurs */
onDrop?: (e: DropEvent) => void;
/** Handler called when drag enters */
onDropEnter?: (e: DropEnterEvent) => void;
/** Handler called when drag exits */
onDropExit?: (e: DropExitEvent) => void;
/** Handler called during drag over */
onDropMove?: (e: DropMoveEvent) => void;
/** Get drop operation for items */
getDropOperation?: (target: DropTarget, types: Set<string>, allowedOperations: DropOperation[]) => DropOperation;
/** Accept drop delegate */
acceptedDragTypes?: string[];
/** Whether drop is disabled */
isDisabled?: boolean;
}
interface DropResult {
/** Props for the droppable element */
dropProps: DOMAttributes<Element>;
/** Whether drag is currently over */
isDropTarget: boolean;
}Provides clipboard operations with proper permissions and fallbacks.
/**
* Provides clipboard operations
* @param props - Clipboard configuration
* @returns Clipboard result with operations
*/
function useClipboard(props?: ClipboardProps): ClipboardResult;
interface ClipboardProps {
/** Handler called when copy succeeds */
onCopy?: () => void;
/** Handler called when copy fails */
onError?: () => void;
}
interface ClipboardResult {
/** Copy text to clipboard */
copy(text: string): Promise<void>;
/** Copy data items to clipboard */
copyItems(items: ClipboardItem[]): Promise<void>;
/** Paste from clipboard */
paste(): Promise<string>;
/** Whether clipboard operations are supported */
isSupported: boolean;
}/**
* Component for pressable elements with interaction states
*/
function Pressable(props: PressableProps): JSX.Element;
/**
* Component for focusable elements with proper semantics
*/
function Focusable(props: FocusableProps): JSX.Element;
interface PressableProps extends PressProps {
/** Children render prop */
children: (states: { isPressed: boolean }) => ReactNode;
/** Element type to render */
elementType?: React.ElementType;
}
interface FocusableProps extends FocusableOptions {
/** Children content */
children: ReactNode;
/** Element type to render */
elementType?: React.ElementType;
}type PointerType = 'mouse' | 'pen' | 'touch' | 'keyboard' | 'virtual';
interface KeyboardEvent {
/** Type of keyboard event */
type: 'keydown' | 'keyup';
/** Key that was pressed */
key: string;
/** Key code */
code: string;
/** Whether shift key was pressed */
shiftKey: boolean;
/** Whether ctrl key was pressed */
ctrlKey: boolean;
/** Whether meta key was pressed */
metaKey: boolean;
/** Whether alt key was pressed */
altKey: boolean;
/** Repeat count */
repeat: boolean;
/** Whether event is composing */
isComposing: boolean;
/** Target element */
target: Element;
/** Current target element */
currentTarget: Element;
/** Prevent default behavior */
preventDefault(): void;
/** Stop propagation */
stopPropagation(): void;
/** Continue propagation */
continuePropagation(): void;
}
interface FocusEvent {
/** Type of focus event */
type: 'focus' | 'blur' | 'focusin' | 'focusout';
/** Target element */
target: Element;
/** Related target element */
relatedTarget: Element | null;
}
type DropOperation = 'copy' | 'link' | 'move' | 'cancel';
interface DragItem {
/** MIME types for the item */
[type: string]: string | (() => string);
}
interface DropTarget {
/** Type of drop target */
type: 'item' | 'folder' | 'root';
/** Key of the target */
key?: Key;
/** Drop position relative to target */
dropPosition?: 'before' | 'after' | 'on';
}
interface DragStartEvent {
/** Type of event */
type: 'dragstart';
/** X coordinate */
x: number;
/** Y coordinate */
y: number;
}
interface DragMoveEvent {
/** Type of event */
type: 'dragmove';
/** X coordinate */
x: number;
/** Y coordinate */
y: number;
/** Delta X */
deltaX: number;
/** Delta Y */
deltaY: number;
}
interface DragEndEvent {
/** Type of event */
type: 'dragend';
/** X coordinate */
x: number;
/** Y coordinate */
y: number;
/** Drop operation performed */
dropOperation: DropOperation;
/** Whether operation was successful */
isInternal: boolean;
}
interface DropEvent {
/** Type of event */
type: 'drop';
/** X coordinate */
x: number;
/** Y coordinate */
y: number;
/** Drop operation */
dropOperation: DropOperation;
/** Dropped items */
items: DropItem[];
/** Drop target */
target: DropTarget;
}Install with Tessl CLI
npx tessl i tessl/npm-react-aria