DropZone
En yta som ett eller flera objekt kan dras och släppas på. Kombinera med FileTrigger för filuppladdning, eller använd den fristående för andra typer av drag & drop.
<DropZone
onDrop={handleDrop}
aria-label='Släpp filer här'
>
<Text slot='label'>Släpp filer här</Text>
</DropZone>
Varianter
Etikett
Textetiketten inuti ytan beskriver vad som ska släppas eller väljas. Används DropZone som ett fält bland andra i ett formulär, komplettera med en etikett ovanför.
<Label id='upload-label'>Ladda upp filer</Label>
<DropZone
aria-labelledby='upload-label'
aria-label='Släpp filer här'
>
<Text slot='label'>Släpp filer här</Text>
</DropZone>
Validering
DropZone kan markeras som ogiltig med isInvalid, tillsammans med ett felmeddelande.
<DropZone
isInvalid
aria-label='Släpp filer här'
>
<Text slot='label'>Släpp filer här</Text>
</DropZone>
<FieldError isInvalid>Filen är för stor</FieldError>
Samma tillstånd kan användas för att begränsa vilka filtyper som är tillåtna:
Filuppladdning
Kombinera med FileTrigger för att låta användaren dra och släppa eller klicka för att välja filer. Se FileTriggers dokumentation för ett komplett exempel med filhantering.
<DropZone
onDrop={handleDrop}
aria-label='Dra och släpp filer här'
>
<Text slot='label'>Dra och släpp filer här</Text>
<FileTrigger onSelect={handleSelect}>
<Button variant='secondary'>
<Upload aria-hidden size={20} />
Välj filer
</Button>
</FileTrigger>
</DropZone>
Inaktiverad
<DropZone
isDisabled
aria-label='Släpp filer här'
>
<Text slot='label'>Släpp filer här</Text>
<FileTrigger>
<Button
variant='secondary'
isDisabled
>
<Upload aria-hidden size={20} />
Välj filer
</Button>
</FileTrigger>
</DropZone>
API
DropZone
| Name | Type | Default | Description |
|---|---|---|---|
isInvalid | boolean | false | Marks the dropzone as invalid, e.g. after a failed validation. Pair with
|
className | ClassNameOrFunction<DropZoneRenderProps> | 'react-aria-DropZone' | The CSS className for the element. A function may be provided to compute the class based on component state. |
isDisabled | boolean | - | Whether the drop target is disabled. If true, the drop target will not accept any drops. |
getDropOperation | ((types: DragTypes, allowedOperations: DropOperation[]) => DropOperation) | - | A function returning the drop operation to be performed when items matching the given types are dropped on the drop target. |
children | ChildrenOrFunction<DropZoneRenderProps> | - | The children of the component. A function may be provided to alter the children based on component state. |
style | StyleOrFunction<DropZoneRenderProps> | - | The inline style for the element. A function may be provided to compute the style based on component state. |
render | DOMRenderFunction<"div", DropZoneRenderProps> | - | Overrides the default DOM element with a custom render function. This allows rendering existing components with built-in styles and behaviors such as router links, animation libraries, and pre-styled components. Requirements:
|
slot | string | null | - | A slot name for the component. Slots allow the component to receive props from a parent
component. An explicit |