A Bootstrap 6 image uploader that shows every chosen photo as a thumbnail before anything is sent. You can star one photo as the cover, open a Bootstrap 6 Dialog to write alt text, remove photos, and then upload them all with a progress bar on each tile. It suits trip stories, listings and galleries.
How it works
The root .iup-root holds a .iup-card with a slot meter, an error alert, the .iup-grid list and a footer with the upload button. The first grid item is .iup-add-tile, a dashed <label> around a visually hidden input.iup-input (accept="image/*" multiple). Every photo tile is cloned from <template class="iup-tile-template">.
When files are picked or dropped on the grid, addFiles() skips anything that is not an image, is larger than data-iup-max-mb, or would exceed data-iup-max. The skipped names are listed in the .iup-error alert. Accepted files get a local preview through URL.createObjectURL(), so nothing leaves the browser yet. refresh() updates the "5 / 12 photos" meter, hides the add tile when the grid is full, and keeps one tile marked .iup-tile--cover.
Each tile has three buttons. The star calls setCover() and uses aria-pressed. The pencil opens the <dialog class="dialog iup-dialog"> with Dialog.getOrCreateInstance(...).show(), showing a larger preview, an alt text textarea and a Bootstrap 6 .switch for the cover. The trash button removes the tile. The upload button adds .iup-tile--uploading to every pending tile, fills its .progress bar on a timer, and marks it .iup-tile--done with a green check.
The starting photos come from Unsplash through SAMPLE_PHOTOS; replace them with your own images.
Customization
data-iup-maxanddata-iup-max-mbon.iup-card: the photo limit (12) and the size limit per file (10 MB).--iup-accenton.iup-root: the coral used by the cover ring, the add tile and the focus outline. The buttons, badge and bars usetheme-danger, so swap that class too.--iup-radiuson.iup-root: the corner radius of every tile.grid-template-columnsin.iup-grid: two columns on phones and three from 640px.- Replace the timer in the
.iup-uploadclick handler with onefetch()per photo, sending the originalFile, its alt text and a cover flag.
Use cases
- Property and product listings: sellers upload photos and mark one as the cover with a star
- Profile and portfolio pages: thumbnails appear before the upload so users can check the images
- Accessibility-aware CMS forms: an alt text dialog lets people describe each photo
- Media managers: size checks and per-photo progress show which images are ready
Accessibility
The file input stays keyboard focusable, and its tile shows a focus ring through :focus-within. Every tile button has an aria-label that names the photo. The cover star reports its state with aria-pressed. The Dialog is labelled by its title, traps focus while open, closes with Escape, and returns focus to the pencil button. Rejected files are listed in a role="alert" box, and a polite live region announces additions, removals and finished uploads.
Bootstrap 6 notes
The details editor is a native <dialog class="dialog"> with data-bs-dismiss="dialog" instead of Bootstrap 5's .modal. style.css includes dialog.dialog:not([open]) { position: fixed; } so the closed dialog adds no blank space. The cover toggle is the new .switch, buttons use btn-solid theme-inverse btn-icon, and the progress bars are colored with theme-danger. Built on 6.0.0-alpha.1, so the APIs can still change.