Avatar picker also Profile picture, Photo picker
A profile picture field: a ray-avatar (the initials of display-name without a picture), Choose photo / Change photo and Remove photo, and a sheet with a ray-image-crop to frame the chosen image in a circle before it is kept. A bottom drawer on a narrow screen, a dialog otherwise. The value is the framed picture as a data URL, or a Blob with output="blob"; it takes part in a <form>.
Choose a picture: its size shows here.
API
For AI agents: this API as Markdown, or every component in llms-full.txt.
<ray-avatar-picker> · RayAvatarPicker
Choose photo opens the system picker (on a phone, the camera or the photo library); the chosen image opens in the sheet, framed in a circle, and Use photo makes the framed part, at output-size, the value. Cancel or a picture that cannot be decoded leaves the value as it was (the latter shows failed-label and fires ray-error). edit(file) opens the sheet on an image from elsewhere (a drop, a paste). Styling: the parts, and ::part(crop) for --ray-image-crop-* .
| Property | Attribute | Type | Default | Description |
|---|---|---|---|---|
name | name reflects | string | Form field name. The value is submitted as a string (data URL) or, with output="blob", as a file named <name>.jpg (.png, .webp). | |
value | value | string | The picture: a URL or data URL (the value attribute: the initial picture, and what a form reset goes back to), or a Blob. null without one. | |
output | output reflects | dataurl | blob | dataurl | What Use photo makes the value: a data URL (easy to keep in JSON) or a Blob (to upload). |
label | label | string | Label above the avatar and the buttons. | |
description | description | string | Help text under the label. | |
error | error | string | Error message; marks the field invalid. | |
required | required reflects | boolean | A picture is required to submit the form. | |
disabled | disabled reflects | boolean | No choosing, removing nor preview (also inside a disabled <fieldset>). | |
readonly | readonly reflects | boolean | The picture cannot be changed: the buttons are hidden, the preview still works. Not validated (required does not apply), as a native readonly field. | |
displayName | display-name | string | The person's name: the avatar shows its initials without a picture (name is the form field). | |
accept | accept | string | image/* | File types the picker offers. |
size | size reflects | xs | sm | md | lg | xl | xl | Size of the avatar. |
color | color | string | Color of the avatar's initials (a palette color or any CSS color). | |
variant | variant | light | filled | outline | default | light | Style of the avatar's initials. |
radius | radius | xs | sm | md | lg | xl | full | Corner radius of the avatar. Default: full (the crop frames a circle either way; the picture is square). | |
buttonSize | button-size | xs | sm | md | lg | xl | sm | Size of the buttons. |
layout | layout reflects | stack | inline | stack | The buttons one under the other, beside the avatar, or in a row. |
sheet | sheet reflects | auto | drawer | dialog | auto | Where the crop opens: auto is a bottom drawer on a narrow screen (up to 40em) and a dialog otherwise. |
outputSize | output-size | string | 320 | Side of the square picture kept, in pixels. |
type | type | string | image/jpeg | Format of the picture kept (PNG where the browser cannot encode it). |
quality | quality | number | 0.85 | 0…1, for image/jpeg and image/webp. |
maxZoom | max-zoom | number | 4 | The most zoom of the crop. |
pickLabel | pick-label | string | Choose photo (text avatar-picker.pick) | The button without a picture. |
changeLabel | change-label | string | Change photo (text avatar-picker.change) | The same button with a picture. |
removeLabel | remove-label | string | Remove photo (text avatar-picker.remove) | The button that removes the picture. |
sheetLabel | sheet-label | string | Adjust the photo (text avatar-picker.sheet) | Title of the crop sheet. |
useLabel | use-label | string | Use photo (text avatar-picker.use) | The sheet's button that keeps the framed picture. |
cancelLabel | cancel-label | string | Cancel (text avatar-picker.cancel) | The sheet's button that leaves the value as it was. |
cropLabel | crop-label | string | Photo framing (text avatar-picker.crop) | Accessible name of the crop area. |
zoomLabel | zoom-label | string | Zoom (text avatar-picker.zoom) | Name of the zoom slider. |
preview | preview reflects | boolean | With a picture, the avatar is a button (click, Enter, Space): it fires ray-preview and, unless that is canceled, shows the picture large in a dialog. Also with readonly; not while disabled. | |
previewLabel | preview-label | string | View photo (text avatar-picker.preview) | Accessible name of the avatar button and title of the preview dialog. |
requiredLabel | required-label | string | Please choose a photo. (text avatar-picker.required) | Validation message of required without a picture. |
failedLabel | failed-label | string | That image could not be opened. (text avatar-picker.failed) | Shown under the field when the chosen file cannot be decoded, or the framed picture encoded (until the next picture). |
| Event | Description |
|---|---|
input | The value changed (fired with change). |
change | A picture was kept (Use photo) or removed. Read value. |
ray-preview | The avatar was pressed (with preview and a picture). Cancelable: preventDefault() to do something else than the preview dialog (a menu, an app's own viewer). |
ray-error | The chosen file could not be decoded, or the framed picture encoded; the value is unchanged. |
| Part | Description |
|---|---|
label | The label. |
description | The description. |
row | The avatar and the buttons (role group, named by the label). |
view | Around the avatar; a button with preview and a picture. |
avatar | The ray-avatar. |
actions | The buttons' column (or row). |
pick | The Choose photo / Change photo ray-button. |
remove | The Remove photo ray-button. |
error | The error message. |
sheet | The ray-drawer or ray-dialog of the crop. |
crop | The ray-image-crop. |
preview | The ray-dialog of the preview. |
preview-image | The picture in the preview dialog. |
cancel | The sheet's Cancel ray-button. |
use | The sheet's Use photo ray-button. |
Texts
What it writes itself, in English; setStrings() translates them (Getting started: Languages).
| Key | English |
|---|---|
avatar-picker.pick | Choose photo |
avatar-picker.change | Change photo |
avatar-picker.remove | Remove photo |
avatar-picker.sheet | Adjust the photo |
avatar-picker.use | Use photo |
avatar-picker.cancel | Cancel |
avatar-picker.crop | Photo framing |
avatar-picker.zoom | Zoom |
avatar-picker.preview | View photo |
avatar-picker.required | Please choose a photo. |
avatar-picker.failed | That image could not be opened. |