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

    75
  • Sortable

    Sortable

    49
  • Circular Progress

    Circular Progress

    41
  • Status

    Status

    28
  • Pending

    Pending

    27
  • Banner

    Banner

    19
  • Stack

    Stack

    8
  • Scroller

    Scroller

    5

More in Forms

View all
  • Premium Auth

    Premium Auth

    500
  • Login 1

    Login 1

    52
  • Book A Demo 3

    Book A Demo 3

    83
  • Authentication Card

    Authentication Card

    47
  • Book A Demo 1

    Book A Demo 1

    69
  • Contact Card

    Contact Card

    1K
  • Login Card

    Login Card

    32
  • Login 2

    Login 2

    7

Explore more

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