Dice UI

Visually Hidden Input

Forms

About

A visually hidden native input that mirrors a custom control's value/checked state so forms submit correctly while keeping the styled UI clean.

Built with React and Tailwind. Copy the prompt and paste it into Claude Code, Cursor or Lovable: your agent adds Visually Hidden Input to your project and fits it to your theme.

Code

How Visually Hidden Input is used: the demo's code. The component's own source comes with a free account.

Usage.tsx

"use client";

import * as React from "react";
import VisuallyHiddenInput from "@/components/ui/visually-hidden-input";

export default function VisuallyHiddenInputDemo() {
  const [checked, setChecked] = React.useState(false);
  const controlRef = React.useRef<HTMLButtonElement>(null);

  return (
    <form className="flex items-center gap-3">
      <button
        type="button"
        ref={controlRef}
        onClick={() => setChecked((prev) => !prev)}
        aria-checked={checked}
        role="checkbox"
        className="flex h-6 w-6 items-center justify-center rounded-md border border-input bg-background text-sm text-primary shadow-sm transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
      >
        {checked ? "\u2713" : ""}
      </button>
      <span className="text-sm text-foreground">Accept terms</span>
      <VisuallyHiddenInput
        type="checkbox"
        checked={checked}
        control={controlRef.current}
        name="terms"
      />
    </form>
  );
}

More by Dice UI

View all
  • Compare Slider

    Compare Slider

    84
  • Sortable

    Sortable

    53
  • Circular Progress

    Circular Progress

    43
  • Status

    Status

    37
  • Pending

    Pending

    30
  • Banner

    Banner

    22
  • Stack

    Stack

    12
  • Kanban Board

    Kanban Board

    11

More in Forms

View all
  • Contact Card

    Contact Card

    1.1K
  • Form

    Form

    17
  • Premium Auth

    Premium Auth

    555
  • Authentication Card

    Authentication Card

    51
  • Book A Demo 1

    Book A Demo 1

    87
  • Login 1

    Login 1

    61
  • SignInPage

    SignInPage

    736
  • Form

    Form

    12

Explore more

Part of Dice UI — browse the full library on 21st.dev.