import { Canvas, Controls, Meta, Title } from '@storybook/addon-docs/blocks';
import * as DropzoneStories from './Dropzone.stories';
<Meta of={DropzoneStories} name='Usage' />
<Title />
## Purpose
A compact area to add files by dragging them in or by browsing, for example to attach an image or a brief to a request.
## Usage
- It is one line: an upload icon, the text "Drop an image or brief, or" and a **browse** button that opens the file dialog. Both halves of the sentence are props (`label`, `browseLabel`) so they can be translated.
- While a file is dragged over it, the outline turns solid and highlighted.
- `onFilesDrop` gets the files, from a drop or from the dialog. `accept` filters both, as on a file input; `multiple` allows more than one.
- The zone does not show the files. The screen owns the list (chips, previews, errors, upload progress): use the Chat Attachment for chips in a chat.
- Keyboard and screen readers use the **browse** button, which is a real button. Dropping is a pointer shortcut, as in the Composer.
- Files that do not match `accept` (and any extra files when `multiple` is off) are dropped without a message, so the screen should check the result and say what it did not add.
- Not for a form field with a validation message and a chosen file name: use the PDS File Upload for that.
## Accessibility
- The zone has no role. What is announced is the text (`label`) and the **browse** button (`browseLabel`), which is a real `button` that opens the file dialog. Its name is only the `browseLabel` text, so write a `browseLabel` that makes sense alone, or tie it to the sentence.
- Keyboard: Tab reaches the **browse** button, which shows a visible focus ring; Enter or Space opens the file dialog. The zone itself is not focusable and the hidden file input is out of the tab order. Dropping files is a pointer-only shortcut, so everything it does must also be possible with the button.
- Not announced by the component: that files were added, that a file is over the zone, and that a file was not accepted. The screen owns the file list and should announce changes, for example in a live region.
- Disabled: the browse button is disabled and the zone is faded; drops do nothing.
- Provide `label` and `browseLabel` translated. Contrast follows the secondary text and link color tokens in both themes; the Storybook a11y panel result is not recorded for this proposal (not checked).
## Implementation
See the table below for the available props.
<hr />
<Canvas of={DropzoneStories.Default} />
<Controls of={DropzoneStories.Default} />
Dropzone
A net-new component, `Dropzone`:
Net-new componentOpen in Storybook