Filename Input

Selects only the base name when renaming and catches lost extensions and names Windows can't store, so a rename doesn't break a file.

StopsRename strips the file extension

Installation

pnpm dlx shadcn@latest add https://bollard-ui.vercel.app/r/filename-input.json

The files land in your project. They're yours to edit.

Usage

filename-input-usage.tsx
import { FilenameInput } from "@/components/ui/filename-input"

<FilenameInput label="Rename Q3 report.pdf" originalName="Q3 report.pdf" defaultValue="Q3 report.docx" existingNames={folder} />

What it catches

  • Extensions changed or removed, with undo
  • Characters Windows forbids
  • Reserved device names such as CON or NUL.txt
  • Trailing dots and spaces, and names over the byte limit
  • Names that differ from an existing file only in capitals

Props

FilenameInput props
PropTypeDefault
label

Visible label.

string"Name"
value

Controlled file name.

string—
defaultValue

Initial file name when uncontrolled.

string""
onValueChange

Called with the new name and whether it has no errors (extension warnings don't count).

(name: string, valid: boolean) => void—
originalName

The name before renaming. Defaults to the first value. Escape restores it.

string—
existingNames

Other names already in the folder, compared without regard to case.

string[]NO_NAMES
maxBytes

Longest name in UTF-8 bytes.

number255
messages

Override any of the default messages.

Partial<typeof FILENAME_MESSAGES>—

* required. Also accepts the native props of <input> (className, aria-*, data-*…), passed through to it.

Accessibility

  • Visible <label>; aria-invalid and aria-describedby to an aria-live="polite" status
  • Escape restores the original name
  • Fixes return focus to the input

Only what the source does. Test with your own screen reader and content before shipping.

Limitations

  • Follows Windows naming rules, the strictest common case; other systems allow more
  • Duplicate checks only cover the existingNames you pass

Rules

Rules last verified:

Informational. Checked the reserved device names (including superscript-digit COM/LPT) and the rule against trailing spaces and periods. Copied components don't update themselves, so re-check after rule changes (see updating a component).

What it stops

Rename strips the file extension

Also known as

filename · rename · file name · extension · upload · file manager · save as · download name

Field type

Dependencies

Pairs well with