Image field

Point at the image to show the change and clear buttons

Current store icon
Shown in browser tabs and bookmarks.

data-fit="contain": the whole image in a wide box, for a logo

Current store logo

data-empty: no image yet, so only the icon and change button

Current category image

A checkbox is ticked while the image is cleared, and the form hears change

Current store icon
icon-clear: not sent

API

The field never uploads. Its form sends the file. Read the file from the input.

Event On Description
input, change input[type=file], bubbles Fired when a file is chosen (by the browser) and when the image is cleared. After a clear, event.target.files is empty.
Key Description
Tab Moves to the change button, then the clear button. Both show while either has focus.
Enter, Space Change opens the file picker. Clear empties the field and moves focus to change.

Attributes

Attribute / element Values Description
.image-field A 96px square box around the img, icon, buttons and inputs.
data-fit contain Shows the whole image in a 2:1 box. By default (unset) the image fills the box and is cropped.
data-empty present Set by the script while there is no image. Add it yourself so it is right before the script runs.
> img[src] URL The starting image. Without src the field is empty.
> .icon Shown while empty, e.g. icon-image.
> [data-change] button Opens the file picker. Required.
> [data-clear] button Clears the image. Leave it out if the image cannot be removed.
> input[type=file] name, accept Sends the chosen file with the form.
> input[type=checkbox] name Optional. Ticked while cleared, to tell the server to delete the file.
aria-label, data-tooltip text On both icon buttons.