Drawer
Un panel que se desliza desde un borde y se puede arrastrar para cerrar. La columna de contenido mide 384px, el título 18px y los botones del pie 44px.
Instalación
npx shadcn@latest add @sevenone/drawerUso
import {
Drawer,
DrawerClose,
DrawerContent,
DrawerDescription,
DrawerFooter,
DrawerHeader,
DrawerTitle,
DrawerTrigger,
} from "@/components/ui/drawer"Ejemplos
Predeterminado
<Drawer>
<DrawerTrigger asChild>
<Button variant="outline">Open Drawer</Button>
</DrawerTrigger>
<DrawerContent>
<div className="mx-auto w-full max-w-sm">
<DrawerHeader>
<DrawerTitle>Move Goal</DrawerTitle>
<DrawerDescription>Set your daily activity goal.</DrawerDescription>
</DrawerHeader>
<div className="flex items-center justify-center gap-2 px-4">
<Button variant="outline" size="icon" className="rounded-full" onClick={() => change(-10)} aria-label="Decrease goal">
<Minus />
</Button>
<div className="flex-1 text-center">
<div className="text-7xl font-bold tracking-tighter" aria-live="polite">{goal}</div>
<div className="text-sm text-muted-foreground uppercase">Calories/day</div>
</div>
<Button variant="outline" size="icon" className="rounded-full" onClick={() => change(10)} aria-label="Increase goal">
<Plus />
</Button>
</div>
<DrawerFooter>
<Button>Submit</Button>
<DrawerClose asChild>
<Button variant="outline">Cancel</Button>
</DrawerClose>
</DrawerFooter>
</div>
</DrawerContent>
</Drawer>Lado
direction abre el drawer desde "top" (arriba), "right" (derecha), "bottom" (abajo) o "left" (izquierda).
<Drawer direction="right">
<DrawerTrigger asChild>
<Button variant="outline">Open from the right</Button>
</DrawerTrigger>
<DrawerContent>
<DrawerHeader>
<DrawerTitle>Filters</DrawerTitle>
<DrawerDescription>Choose what the list shows.</DrawerDescription>
</DrawerHeader>
…
<DrawerFooter>
<Button>Apply</Button>
<DrawerClose asChild>
<Button variant="outline">Cancel</Button>
</DrawerClose>
</DrawerFooter>
</DrawerContent>
</Drawer>Accesibilidad
- Es un diálogo: el foco entra cuando se abre y queda dentro hasta que se cierra; Esc lo cierra y el foco vuelve al disparador.
- Arrastrar nunca es la única forma: mantén un botón Cancelar (DrawerClose) en el pie.
- Dale siempre un DrawerTitle; los lectores de pantalla lo anuncian con la descripción.
- El movimiento de deslizar se detiene cuando la persona pide menos movimiento.