Skip to Content
⭐️ Leave a star →
HooksuseInteractiveState

useInteractiveState

Tracks hover, keyboard focus, and press state for any element. Returns event handlers to spread onto the element along with matching data-* attributes so consumers can style state transitions with CSS selectors.

This is the same primitive used internally by Button, Accordion.Trigger, Modal.Close, and Drawer.Close — exported so your own interactive components can opt into identical state tracking.

Unlike libraries that expose data-focus for any focus event, Wire UI uses data-focus-visible, which only applies when focus arrives from keyboard navigation — mirroring the CSS :focus-visible pseudo-class detected via element.matches(':focus-visible').

import { useInteractiveState } from '@wire-ui/react' function Card({ disabled }: { disabled?: boolean }) { const { handlers, dataAttributes } = useInteractiveState({ disabled }) return ( <div tabIndex={0} role="button" {...handlers} {...dataAttributes} className=" rounded-lg border p-4 cursor-pointer transition-all data-[hover]:bg-gray-50 data-[active]:scale-95 data-[focus-visible]:ring-2 data-[disabled]:opacity-50 data-[disabled]:pointer-events-none " > Card content </div> ) }

Options

OptionTypeDescription
disabledbooleanWhen true, suppresses hover and active state and applies data-disabled.

Returns

KeyTypeDescription
handlersobjectEvent handlers to spread onto the element.
dataAttributesobjectdata-hover, data-focus-visible, data-active, data-disabled (each present-or-absent).
isHoveredbooleanRaw hover state.
isFocusVisiblebooleanRaw keyboard-focus state.
isActivebooleanRaw press state.

Data attributes

AttributePresent when
data-hoverThe pointer is hovering the element (suppressed while disabled).
data-focus-visibleThe element has keyboard focus.
data-activeThe element is being pressed (pointer or Enter / Space).
data-disableddisabled option is truthy.
Last updated on

MIT License © 2026 wire-ui

useInteractiveState – Wire UI