ImagePicker
A multi-image picker: click or drag to select → thumbnail grid → reorder / remove, with a count limit. The component does not upload; files is handed to the host's upload chain as File[].
Basic usage
max=6
No images selected yet
Click “Add image” to pick files, or drop images onto the component. Each thumbnail has move-forward / remove / move-backward actions (keyboard accessible).
Count limit
Files beyond max are dropped and oas-exceed-limit is dispatched; once full, the add tile is hidden and the counter shows selected / max.
max=2 (pick 3 to see the feedback)
Limit: 2 images
Readonly and disabled
disabled
readonly (preview only)
disabled: the add tile and all reorder/remove buttons are disabledreadonly: the add entry is hidden and action buttons are disabled (for post-submit display)
Type filtering and capture
accept passes through the native type filter (extensions or MIME types, comma separated); filtered-out files dispatch oas-reject. capture makes mobile browsers open the camera directly.
accept only .jpg / .jpeg + capture
Try picking a PNG: it is rejected with feedback
Auto compression and EXIF orientation (compress)
Automatic compression of picked images (default off; when enabled it only applies to newly picked files; controlled files writes are never compressed — what the host provides is final):
compress="": enable with defaults (quality 0.8 / max-dimension 4096)compress='{"quality":0.8,"max-dimension":1920}': JSON overrides (quality 0–1, longest-edge pixel cap with proportional downscale)- JPEG / WebP are re-encoded at the configured quality; PNG keeps transparency (kept as-is when no resize is needed); GIF / SVG and other types pass through untouched
- EXIF orientation: modern browsers already decode
<img>upright per EXIF (sideways phone shots display correctly), so compression only scales proportionally and never re-applies a rotation; re-encoded output is upright (JPEG/WebP/PNG re-encoding carries no orientation marker) - The source file's EXIF Orientation is reported as meta info:
compressed[].orientation(1 = no orientation marker), so hosts can tell whether the original carried one - Decode failure / canvas unavailable: graceful degradation keeps the original file (meta entry stays null)
- While enabled,
oas-changedetail carries acompressedarray (aligned withfiles): each entry is{ originalWidth, originalHeight, width, height, orientation, quality }(original → compressed size) ornull(untouched) - Invalid configuration warns once in dev and behaves as off (detail returns to the current shape without
compressed)
compress auto compression (pick an image to see the compression meta)
Pick an image to see the compression meta here
Working with the upload chain
files is a JS property (not reflected to attributes); host assignment applies silently and dispatches no event, so echo-back in a form is straightforward.
const picker = document.querySelector('oas-image-picker')
picker.addEventListener('oas-change', async (e) => {
const form = new FormData()
for (const file of e.detail.files) form.append('images', file)
await fetch('/api/upload', { method: 'POST', body: form })
})
// Echo existing images (e.g. an edit form)
picker.files = existingFilesEvents
| Event | When | detail |
|---|---|---|
oas-change | After the user adds / removes / reorders | { files, count } |
oas-exceed-limit | The selection exceeds the limit (extra files dropped; dispatched after oas-change) | { count, max } |
oas-reject | A file is filtered out by accept | { files } |
API
oas-image-picker
Attributes
| Attribute | Description | Type | Default |
|---|---|---|---|
accept | File type filter (native accept syntax, default image/*) | string | image/* |
capture | Passes through native capture: opens the camera directly on mobile | boolean | — |
compress | Auto compression for picked images (default off = byte-identical to current behavior): empty string = defaults (quality 0.8 / max-dimension 4096); JSON {"quality":0.8,"max-dimension":1920} overrides; invalid warns once and behaves as off. Only applies to newly picked files (controlled files writes are never compressed); EXIF orientation is handled by the browser's upright decoding — output is always upright, with the source orientation marker reported as orientation meta; while active oas-change detail carries the compressed meta array | string | — |
disabled | Disabled: adding, reordering and removing are all unavailable | boolean | — |
max | Max image count (default 9); invalid/non-positive values fall back with a warning | string | — |
readonly | Preview only: add entry hidden and action buttons disabled | boolean | — |
Property (JS property; see each row for attribute reflection)
| Property | Description | Type | Default |
|---|---|---|---|
files | Current image list (File[], controlled): assignment refreshes silently; only user interaction dispatches oas-change | File[] | [] |
Methods
| Method | Signature | Description |
|---|---|---|
removeAt | removeAt(index: number): void | Remove the image at index (out-of-range ignored, dispatches oas-change) |
move | move(index: number, delta: number): void | Move an image by delta (±1, out-of-range ignored, dispatches oas-change) |
open | open(): void | Open the system file picker (requires a user gesture) |
clear | clear(): void | Clear the list (dispatches oas-change) |
Events
| Event | Description |
|---|---|
oas-change | After the user adds / removes / reorders, detail: { files, count } |
oas-exceed-limit | The selection exceeds the limit, detail: { count, max } (extra files dropped; dispatched after oas-change) |
oas-reject | Files filtered out by accept, detail: { files } |