File picker
ds-file-picker keeps a native input type="file" in light DOM. It is the
focusable hit target: the browser owns the file chooser, labels, keyboard
activation, file drops, required validation, form values, reset and disabled
fieldsets. DS1 composes the visible Button face, focus ring and scale.
<ds-file-picker label="Choose logo" secondary> <input type="file" name="logo" accept="image/svg+xml,.svg" aria-label="Choose logo"></ds-file-picker>The normal picker is one square high and as wide as its label. icon makes
it a one-square icon control; preview makes a four-square image control,
or two squares with compact.
area fills its container as an eight-square-high upload target, or four
squares with compact. It uses the shared secondary face and wraps its label.
Use it for a larger native drop target rather than drawing a product-owned well.
Put decorative content in the content slot. Keep an accessible name on the
native input. The composed button is inert and hidden from assistive technology
so there is one control and one tab stop.
In React, register the element in the browser before hydration. The label attribute supplies the visible copy; the native input keeps its own accessible name, attributes and event handlers, and className and style on the host place the picker.
<ds-file-picker label="Attach files" secondary> <input type="file" aria-label="Attach files" multiple accept="image/*,.pdf" disabled={pending} onChange={event => acceptFiles(event.currentTarget.files)} /></ds-file-picker>Products own accepted types, size limits, selected-file display, upload requests,
permissions and persistence. No file leaves the browser through this component.
Clear event.currentTarget.value after consuming a selection when choosing the
same file again should be possible. Do not hide the input or add a second click
trigger. Native accept guides selection; product validation still applies.
When a containing product surface also accepts dropped files, it owns that
drop: prevent the native default and pass a copied array to the same guarded
upload function. This avoids uploading once on drop and again on change.
Set dragging when that outer surface has a file over it: DS1 applies the same
drag feedback to the picker, suppressed when the native control is disabled.
Verify file selection and keyboard activation, disabled fieldsets, reset, focus,
pending recovery and light/dark scaled layouts without uploading live test data.
The input’s cancel event reports a dismissed chooser. Keep a menu
that contains the picker mounted until change or cancel, so returning
from the system chooser cannot lose the selected files. Use role="menuitem"
inside a Select or Context menu to share its row and arrow navigation while Enter and Space stay native; a file row never closes the menu before the chooser answers.
Design examples
Section titled “Design examples”The file input stays native. Selection is local to this preview; nothing is uploaded.
<section class="specimen">
<ds-file-picker label="Choose artwork" secondary><input type="file" accept="image/*,.pdf" aria-label="Choose artwork"></ds-file-picker><ds-gap></ds-gap><ds-text literal tone="muted" size="small">PDF or an image from your device</ds-text>
</section>
<style>
.specimen { width: 100%; min-width: 0; --cell: calc(20px * var(--sf, 1)); }
.specimen .line { width: 100%; }
.specimen .grow { flex: 1; min-width: 0; }
.specimen .muted { color: var(--ds-text-color-muted); }
.specimen .mono { --ds-typeface-regular: var(--ds-typeface-mono); font-variant-numeric: tabular-nums; }
.specimen .value { width: calc(4 * var(--cell)); text-align: right; }
.specimen .mark { display: inline-flex; align-items: flex-end; width: var(--cell); height: var(--ds-control-height); flex: 0 0 var(--cell); }
.specimen .columns { display: flex; flex-wrap: wrap; gap: var(--cell); }
.specimen .columns > * { min-width: 0; }
.specimen fieldset { border: 0; padding: 0; margin: 0; }
.specimen legend { padding: 0; }
.specimen label { display: flex; align-items: flex-end; gap: calc(var(--cell) / 2); min-height: var(--cell); }
.specimen ds-panel { height: calc(10 * var(--cell)); }
</style>