An attach button with a letterbox slot: a dragged file opens the lips, drops in as a tile and the counter ball takes +1; a rejected type bounces off.
DragDrag
Expenses /New expense
mail-slot · , lively
mail-slot-demo.tsx
When to use
Use it as the attach button of a form row: it opens the file picker on click and accepts dropped files. It checks the file type with accept and a limit with maxFiles, and shows how many are attached.
Use Mail Slot for the attach button of a form row: receipts on an expense, attachments on a ticket reply, scans on an onboarding checklist. It is a real button that opens the file picker, and also a drop target: while a file is dragged over the page the slot opens toward it, a drop slides the file in as a tile, and the counter ball shows the new total. A type it does not take hits the closed slot and bounces back, with the reason announced. For a large area that also shows upload progress, use a dropzone.
accept uses the same syntax as <input accept>. onFiles receives the accepted Files when the slot closes on them; onReject receives the rest with a reason (rejectMessage for a wrong type, built from accept by default, or "up to N files" past maxFiles). count is the real number of files in the form (controlled); without it the counter starts at defaultCount and adds what it accepts. onDragStateChange reports accept, reject or idle while a file is over the page, for a hint next to the button. Button props (aria-describedby, onClick, name) go to the <button>.
Presets: letterbox (default: the slot beside the label), stacked (the slot above the label, for document tiles) and compact (slot only, the label read by screen readers, for toolbars and table rows). slot and counter replace the pill and the ball with any shape.
Set the character for the whole app with MotionKitProvider, or per instance with temperament (calm, lively, playful). It changes motion intensity only, never the drawing.
A native <button> opens a hidden <input type="file">: Enter, Space and tap do the same job as a drag, so dropping is never the only way in.
The button's name is its label plus ", N attached" (visually hidden), so the count is read with it, also in the compact preset.
A polite live region announces each outcome: "taxi-receipt.pdf attached. 3 files." or "receipts.zip not attached: only PDF, PNG or JPG.". Set announce={false} when the page already announces it.
The slot, the counter and the flying tile are aria-hidden. Focus shows a 3 px ring; the plate uses secondary with an ink rim, label contrast at least 4.5:1 in both themes.