Skip to main content

Interactive

The Interactive component is a primitive element designed for building clickable and focusable elements.

Import

import { Interactive } from '@vortexlabs/vortex';
import type { InteractiveProps } from '@vortexlabs/vortex';

Display

<Interactive onClick={() => {}}>Click me</Interactive>

Allied components

Other links

Interactive
<Interactive
  disabled={false}
  fullWidth={false}
  insetFocus={false}
  focusRingDisabled={false}
  touchHitbox={false}
>
  Interactive
</Interactive>

Features

  • Supports button, anchor, and custom elements.
  • Supports keyboard, mouse, and touch interactions.
  • Supports disabled, fullWidth, and touchHitbox.
  • Supports insetFocus and focusRingDisabled.
  • Assigns the correct HTML tag.

Role

Interactive can render as a button, link, or custom element. With href, it renders an anchor (<a>). With onClick, it renders a button (<button>) by default.

Interactive Link
Interactive Div
<Interactive href="" attributes={{ target: '_blank' }}>
  Interactive Link
</Interactive>

<Interactive onClick={() => ()}>
Interactive Button
</Interactive>

<Interactive as="div" onClick={() => ()}>
  Interactive Div
</Interactive>

Use href to render a link. Use external to open a link in a new tab. Interactive applies rel="noopener noreferrer" automatically.

<Interactive href="https://example.com">Internal link</Interactive>
<Interactive href="https://example.com" external>External link</Interactive>

Disabled State

Interactive has a disabled state for elements that are not available for interaction. This works for button and link variants.

Disabled link
<Interactive type="button" disabled>Disabled button</Interactive>
<Interactive href="https://example.com" disabled>Disabled link</Interactive>

Full Width

Interactive can be made full width by setting the fullWidth property to true.

<Interactive fullWidth href="/">
  Full Width Interactive
</Interactive>

Focus Ring

Interactive has a focus ring that is visible during keyboard navigation.

Inset Focus

Use insetFocus to place the focus ring inside the element bounds.

<Interactive type="button" insetFocus>Inset focus ring</Interactive>

Disabled Focus Ring

Use focusRingDisabled when another element renders the focus indicator.

<Interactive type="button" focusRingDisabled>No focus ring</Interactive>

Inherited Border Radius

Use borderRadius="inherit" to let the focus ring follow the border radius of the first child.

<Interactive type="button" borderRadius="inherit">
<span style={{ display: 'block', borderRadius: '999px', padding: '8px 16px' }}>
  Rounded child
</span>
</Interactive>

Touch Hitbox

Use touchHitbox to increase the touch target for small controls. The hitbox meets the WCAG AA minimum touch target of 44×44px.

<Interactive type="button" touchHitbox>Small target</Interactive>

Custom Element

Use the as prop to render Interactive as any valid HTML element.

Div element
<Interactive as="label" type="button">Label element</Interactive>
<Interactive as="div" type="button">Div element</Interactive>

Render Slot

Use the render prop for full control over the root element. The function receives the attributes that need to be applied to the rendered element.

<Interactive
  href="https://example.com"
  render={(attributes) => (
      <a {...attributes} data-custom="value" />
  )}>
      Custom anchor
</Interactive>

Accessibility

The Interactive component provides comprehensive accessibility features including keyboard navigation, focus management, and proper ARIA attributes.

Key
Description
EnterSpace
Pressing Enter or Space activates non-native buttons with role="button".
Disabled elements receive aria-disabled="true".
Disabled links remove the href attribute to prevent navigation.
The focus ring is only visible during keyboard navigation.