File Model
The rules a file picker applies before anything is uploaded: does the file match what the field accepts, is it small enough, and is there room for another. Pure, so a server can apply the same rules to the same files and a reader is never told "yes" in the…
Install
Two equivalent paths — the URL works in any shadcn-CLI setup; the alias works once you've registered @interlace in your components.json.
npx shadcn@latest add https://ds.interlace.tools/r/file-model.jsonnpx shadcn@latest add @interlace/file-modelHistory
This component is at v1.0.0. The version is stamped as a banner into the file the install writes, so the copy in your tree says which one you have — compare it with the number above before deciding whether to re-run the install.
Unreleased1 entry
- Addedminor
New FileDrop and AvatarUpload, for handing over files.
FileDropis a real file field drawn as a drop area: press it or drop files on it, see each file with its size, and take one back out.accept,maxSizeandmaxFilesare checked again on every pick and drop (the picker's filter only suggests, and a drop skips it), and a file that breaks a rule is turned away with the reason said in a polite live region, in wordsmessagescan replace. Removing a file moves focus to the next Remove button, or back to the field.AvatarUploadis a profile photo the reader can choose, change or remove, with a live preview; its value tells "new photo", "no photo" and "unchanged" apart for the save. The rules live infile-model(acceptsFile,checkFiles,formatBytes), pure, so a server can apply the same ones.
Import
4 named exports — pull the parts you need.
import { FileRejectionReason, acceptsFile, checkFiles, formatBytes } from '@/components/ui/file-model';Accessibility
Every story for this component is rendered headlessly and checked with axe-core (wcag2aa, wcag22aa, best-practice, ACT) on every PR. That gate has no continue-on-error, so what ships has zero known violations.
What follows is what static analysis can see. Axe cannot press a key and never sees an overlay open, so the operable-without-a-mouse claim lives in Behavior instead, where the keyboard path is replayed step by step.
- Focus + keyboard behaviour
- Native element semantics — no interaction layer to get wrong.
- Focus ring (WCAG 2.2 SC 2.4.13)
- Not focusable — no focus indicator required.
- Reduced motion
- No animation to gate.
- ARIA in the source
- None — semantics come from the element or the Base UI primitive rather than hand-written ARIA.
Dependencies
- Base UI primitive
- Native / no Base UI dependency
- Lucide icons
- none
- NPM dependencies
- none
- Registry dependencies
Source
The full implementation — components/ui/file-model.ts once installed.
export interface FileLike {
name: string;
size: number;
type: string;
}
export type FileRejectionReason = 'type' | 'size' | 'count';
export interface FileRejection<F extends FileLike = FileLike> {
file: F;
reason: FileRejectionReason;
}
export interface FileRules {
/** The `accept` attribute's value. Empty or missing takes every file. */
accept?: string;
/** The largest file, in bytes. Missing means no limit. */
maxSize?: number;
/** How many files the field holds in all. Missing means no limit. */
maxFiles?: number;
…89 more lines…Registry JSON
The raw registry record — what the shadcn CLI fetches.