Attachment
Shows a file and its upload state.
Sizes
defaultdefault
sm
Drop
regiondefault
zone
States
idle
uploading
processing
done
error
drag accept
drag reject
Usage
When to use it
Rules
6 rules
- Never
- Put a bare <input type="file"> on screen; use AttachmentDrop with an AttachmentDropTrigger. Because the native input has no drag judgement, no reasons and a look Glaze cannot reach, while the trigger opens the same picker.
- Must
- Show a refused or failed file as state="error" with the reason in AttachmentDescription. Because a file that silently vanishes makes the person try again, and rejectionReason already says why in words.
- Must
- Name every AttachmentAction with the file: "Remove refund-policy.pdf". Because a group of chips each with a "Remove" button gives a screen reader five identical names.
- Must
- Give AttachmentProgress a label naming the file, and write the bytes in AttachmentDescription. Because the 2px bar is the progressbar's only visible part, and "1.2 of 4.8 MB" says what is left.
- Never
- Put glass, a tint or a shadow on an Attachment chip. Because the chip is not pressed, and a raised chip reads as a button beside the composer's send.
- Should
- Say what the zone takes in AttachmentDropDescription: types and the size limit. Because the overlay can refuse a type during a drag, but only the words tell the person before they try.
Accessibility
4 checks
- A busy chip is aria-busy; AttachmentProgress is a named progressbar with the percent.
- The drag overlay is aria-hidden; the trigger is the way in for keyboard and screen reader users.
- The file name is whole in the DOM even when cut in the middle.
- The error reason is in the failure word colour, 5.9:1, and in words.
Keyboard
2 keys
- Tab
- Moves to each chip's actions, and to the zone's trigger.
- Enter
- Presses the focused action or opens the file picker.
Edge cases
6 edge cases
- Wrong type dragged
- The overlay turns coral and says what the region takes before the drop.
- Extension-only accept
- Judged on drop, since a drag shows types and not names.
- Regions nested
- The inner one takes the drop; the outer one shows nothing.
- Same file picked twice
- The picker fires again.
- Thumbnail fails to load
- Falls back to the image glyph.
- Long file name
- Cut in the middle so the extension stays.
API
9 props
Attachment state'idle' | 'uploading' | 'processing' | 'done' | 'error'default'done'Attachment size'default' | 'sm'default'default'AttachmentProgress value, labelnumber, stringAttachmentGroup layout'wrap' | 'scroll'default'wrap'AttachmentDrop variant'region' | 'zone'default'region'AttachmentDrop accept, maxSize, multiplestring, number, booleandefault, , trueAttachmentDrop onFiles, onReject(files) => void, (rejections) => voidAttachmentDrop pastebooleandefaultfalseAttachmentDrop dragState'accept' | 'reject'
Tokens
15 tokens
--paper- #ffffff
--line- rgb(5 5 5 / 0.10)
--line-control- rgb(5 5 5 / 0.15)
--fail- #e35e49
--fail-text- #b23c29
--field- #efefef
--ink- #050505
--radius-overlay- 10px
--radius-tag- 6px
--row- 36px
--type-label- 500 13px/1.35 var(--font-sans)
--type-caption- 400 12px/1.35 var(--font-sans)
--text-1- rgb(5 5 5 / 0.80)
--text-2- rgb(5 5 5 / 0.60)
--dur-state- 160ms