RouteDrawer - Admin Components

Note: This component is available since Medusa v2.21.0.

The RouteDrawer component renders a drawer that slides in from the side of the screen. The Medusa Admin uses it for edit forms, such as the form that edits a customer's details.

Code
import { RouteDrawer } from "@medusajs/dashboard/components"

Route Modals#

RouteDrawer is tied to a route, not to a trigger button. You render it as the root element of a UI route that is nested under the page it edits. When the user navigates to that route, the drawer opens. When the user closes the drawer, RouteDrawer navigates back to the previous route.

So, to open the drawer, link the user to the drawer's route. For example, link to /brands/:id/edit from the brand's details page.


Example#

Consider a UI route at src/admin/routes/brands/[id]/edit/page.tsx that edits a brand:

src/admin/routes/brands/[id]/edit/page.tsx
1import { Heading } from "@medusajs/ui"2import { RouteDrawer } from "@medusajs/dashboard/components"3import { useParams } from "react-router-dom"4
5const BrandEdit = () => {6  const { id } = useParams()7
8  return (9    <RouteDrawer>10      <RouteDrawer.Header>11        <RouteDrawer.Title asChild>12          <Heading>Edit Brand</Heading>13        </RouteDrawer.Title>14      </RouteDrawer.Header>15      <EditBrandForm id={id!} />16    </RouteDrawer>17  )18}19
20export default BrandEdit

EditBrandForm renders the form's fields, as explained in the useRouteModal section.


Props#

RouteDrawer accepts the following props, in addition to its children:

Loading...

Sub-components#

Component

Description

RouteDrawer.Header

The drawer's header. Place the title and description in it.

RouteDrawer.Title

The drawer's title. Pass asChild to render your own heading element.

RouteDrawer.Description

An accessible description of the drawer's purpose.

RouteDrawer.Body

The drawer's scrollable content area.

RouteDrawer.Footer

The drawer's footer. Place the cancel and submit buttons in it.

RouteDrawer.Close

Closes the drawer when clicked, which navigates back to the prev route. Pass asChild to use your own button.

RouteDrawer.Form

Wraps a React Hook Form form. It provides the form's context to the fields, and shows a confirmation prompt if the user leaves the route while the form has unsaved changes.

RouteDrawer.Form Props#

Loading...

useRouteModal#

Use the useRouteModal hook in components rendered inside a RouteDrawer or a RouteFocusModal. It gives you access to the modal's route context.

Code
import { useRouteModal } from "@medusajs/dashboard/components"

The hook throws an error if you use it outside of a route modal.

Returned Values#

Loading...

Example#

The form component uses handleSuccess to close the drawer after the brand is updated:

src/admin/routes/brands/[id]/edit/page.tsx
1import { Button, Input, toast } from "@medusajs/ui"2import {3  RouteDrawer,4  useRouteModal,5} from "@medusajs/dashboard/components"6import { useForm } from "react-hook-form"7
8const EditBrandForm = ({ id }: { id: string }) => {9  const { handleSuccess } = useRouteModal()10  const form = useForm({11    defaultValues: {12      name: "",13    },14  })15
16  const handleSubmit = form.handleSubmit(async (data) => {17    await updateBrand(id, data)18    toast.success("Brand updated")19    handleSuccess()20  })21
22  return (23    <RouteDrawer.Form form={form}>24      <form onSubmit={handleSubmit}>25        <RouteDrawer.Body>26          <Input {...form.register("name")} />27        </RouteDrawer.Body>28        <RouteDrawer.Footer>29          <RouteDrawer.Close asChild>30            <Button variant="secondary" size="small">31              Cancel32            </Button>33          </RouteDrawer.Close>34          <Button type="submit" size="small">35            Save36          </Button>37        </RouteDrawer.Footer>38      </form>39    </RouteDrawer.Form>40  )41}
Was this page helpful?
Ask Bloom
For assistance in your development, use Claude Code Plugins or Docs MCP server in Cursor, VSCode, etc...FAQ
What is Medusa?
How can I create a module?
How can I create a data model?
How do I create a workflow?
How can I extend a data model in the Product Module?
Recipes
How do I build a marketplace with Medusa?
How do I build digital products with Medusa?
How do I build subscription-based purchases with Medusa?
What other recipes are available in the Medusa documentation?
Chat is cleared on refresh
Line break
⇧↵