form fields

<tc-file>

File picker with a styled button + filename label. Form-associated, supports single or multiple files.

import "@ra9/tan-compose-kit/file"

Props

NameTypeDefaultDescription
namestring""Field name used in form submission.
acceptstring""MIME type filter, same shape as the native `<input accept>` attribute.
multiplebooleanfalseAllow selecting more than one file. Reflects to the host.
labelstring""Label rendered above the picker.
helperstring""Small helper text below the picker.
errorstring""Error message; paints invalid when set.
buttonTextstring"Choose file"Text on the picker's call-to-action button.
disabledbooleanfalseDisables the control; reflects to the host.
requiredbooleanfalseRequired for form validation; reflects to the host.

Events

EventDetailWhen
tc-files{ files: File[] }Fires after the user picks one or more files.

CSS variables

VariableDefaultDescription
--tc-input-fgvar(--tc-color-ink, #14171f)Label color.
--tc-input-bordervar(--tc-color-rule-strong, #d9cfb8)Dashed zone border.
--tc-input-errorvar(--tc-color-danger, #b3261e)Border + error message color.
--tc-input-helpervar(--tc-color-ink-muted, #6b7280)Helper text color.
--tc-input-radiusvar(--tc-radius-md, 8px)Corner radius.
--tc-input-fontvar(--tc-font-sans, …)Font family.
--tc-file-zone-bgvar(--tc-color-surface-alt, #faf8f3)Background of the picker zone.
--tc-file-zone-fgvar(--tc-color-ink-soft, #4a5061)Filename text color.

Examples

Basic usage

<tc-file label="Avatar" accept="image/*"></tc-file>

Multiple

<tc-file label="Photos" accept="image/*" multiple button-text="Choose photos" ></tc-file>

Custom button text

button-text lets you put the action verb on the control itself.

Reading the picked files

<tc-file id="resume" label="Resume" accept=".pdf"></tc-file> <script type="module"> document.getElementById("resume").addEventListener("tc-files", (e) => { const [file] = e.detail.files; console.log("picked", file.name, file.size); }); </script>

In a form

Submits using the form-associated path — single files set setFormValue(file), multiple files set a FormData with repeated entries under name.

<form enctype="multipart/form-data"> <tc-file name="attachment" label="Attachment"></tc-file> <tc-button type="submit">Send</tc-button> </form>

Theming

<tc-file style="--tc-file-zone-bg: #f5f5dc; --tc-input-radius: 2px;" label="Subtle zone" ></tc-file>

Accessibility

  • The visible button is a real <button>; the native <input type="file"> is visually hidden but kept in the DOM for form submission and assistive tech.
  • The label is associated with the control via wrapping markup; clicking the label focuses the button.
  • The filename text is plain text — screen readers read it after each pick.
  • Note: the native file dialog is provided by the browser; styling cannot reach inside it.