Dice UI

Visually Hidden Input

A hidden input that remains accessible to assistive technology and maintains form functionality.

API

Installation

pnpm dlx shadcn@latest add @diceui/visually-hidden-input

Usage

import { VisuallyHiddenInput } from "@diceui/visually-hidden-input"
 
export function CustomForm() {
  const [checked, setChecked] = React.useState(false)
  const controlRef = React.useRef(null)
  
  return (
    <form>
      <button 
        ref={controlRef}
        onClick={() => setChecked(!checked)}
        aria-checked={checked}
        role="checkbox"
      >
        {checked ? "✓" : ""}
      </button>
      <VisuallyHiddenInput
        type="checkbox"
        checked={checked}
        control={controlRef.current}
      />
    </form>
  )
}

API Reference

VisuallyHiddenInput

A hidden input that maintains form functionality while being visually hidden.

Prop

Type

Credits

On this page