Files
react/packages/react-events/docs/Hover.md
Nicolas Gallagher e276a5e850 [Flare] Remove delay props from Hover (#16248)
Moving working with delays into user-space.
2019-07-30 09:29:43 -07:00

1.3 KiB

Hover

The Hover module responds to hover events on the element it wraps. Hover events are only dispatched for mouse and pen pointer types. Hover begins when the pointer enters the element's bounds and ends when the pointer leaves.

Hover events do not propagate between Hover event responders.

// Example
const Link = (props) => (
  const [ hovered, setHovered ] = useState(false);
  return (
    <Hover onHoverChange={setHovered}>
      <a
        {...props}
        href={props.href}
        style={{
          ...props.style,
          textDecoration: hovered ? 'underline': 'none'
        }}
      />
    </Hover>
  );
);

Types

type HoverEvent = {
  pointerType: 'mouse' | 'pen',
  target: Element,
  type: 'hoverstart' | 'hoverend' | 'hovermove' | 'hoverchange'
}

Props

disabled: boolean

Disables all Hover events.

onHoverChange: boolean => void

Called when the element changes hover state (i.e., after onHoverStart and onHoverEnd).

onHoverEnd: (e: HoverEvent) => void

Called once the element is no longer hovered.

onHoverMove: (e: HoverEvent) => void

Called when the pointer moves within the hit bounds of the element.

onHoverStart: (e: HoverEvent) => void

Called once the element is hovered.

preventDefault: boolean = true

Whether to preventDefault() native events.