FileSizeInput
Emits bytes. MB is 1000² and MiB is 1024², a 4.9% gap — which is exactly the difference between “a 100 MB limit” and a user’s file being rejected. The field keeps them distinct rather than quietly converting, and the byte count is grouped with an explicit locale so it does not render as 2,50,00,000 on a machine set to en-IN.
$ npx shadcn@latest add https://input-cn.vercel.app/r/filesize-input.jsonHand this to Claude Code
Most people reach this component through an agent rather than by reading the page. Pick how you want it wired and take a prompt that already carries the canonical value, the real prop names and the mistakes worth avoiding.
Nothing runs on its own. The link opens the tool with the prompt typed into the box; you read it and press Enter. If the button does nothing, Claude Code is not installed on this machine — use Copy prompt instead.
Live demo
1 MB and 1 MiB differ by 4.9%. Try both.
value = 0 · bytes
Constraints
Validation rules, declared as props. Each one produces its own message and its own data-rule value, so a test can assert the rule rather than the sentence.
Props
Shared props
Implemented identically by all eleven components. These tables are generated from the source interfaces at build time, so a renamed prop changes this page rather than quietly making it wrong.
With react-hook-form
import { useForm, Controller } from "react-hook-form"
import { zodResolver } from "@hookform/resolvers/zod"
import { fileSizeSchema } from "@inputcn/filesize/schema"
import { FileSizeInput } from "@/components/ui/filesize-input"
import { z } from "zod"
// The companion schema validates the CANONICAL value, so the resolver and the
// field can never disagree about what "valid" means.
const schema = z.object({ limit: fileSizeSchema() })
export function Example() {
const { control } = useForm({ resolver: zodResolver(schema) })
return (
<Controller
name="limit"
control={control}
render={({ field, fieldState }) => (
<FileSizeInput
label="Upload limit"
{...field}
aria-invalid={fieldState.invalid}
/>
)}
/>
)
}With a Server Action
import { FileSizeInput } from "@/components/ui/filesize-input"
export default function Page() {
return (
<form action={save}>
<FileSizeInput name="limit" label="Upload limit" />
<button>Save</button>
</form>
)
}
async function save(data: FormData) {
"use server"
// The hidden canonical input carries the real value, not the display text.
const limit = Number(data.get("limit")) // 1048576
}Emits number, for example 1048576. Keyboard operation is covered by automated tests; screen readers have not been verified yet.