Leave Yamada UI a star

Star
Yamada UIYamada UIv1.7.2

Drawer

Drawer is a component for a panel that appears from the edge of the screen.

Source@yamada-ui/modal

Import

import {
Drawer,
DrawerOverlay,
DrawerCloseButton,
DrawerHeader,
DrawerBody,
DrawerFooter,
} from "@yamada-ui/react"
Copied!
  • Drawer: A wrapper component that controls the state of the panel.
  • DrawerOverlay: A component for the overlay behind the panel.
  • DrawerCloseButton: A component for the button that closes the panel.
  • DrawerHeader: A component that displays the header of the panel.
  • DrawerBody: A component that displays the main content of the panel.
  • DrawerFooter: A component that displays the footer of the panel.

Usage

To control the visibility, set isOpen and onClose.

Editable example

const { isOpen, onOpen, onClose } = useDisclosure()

return (
  <>
    <Button onClick={onOpen}>Open Drawer</Button>

    <Drawer isOpen={isOpen} onClose={onClose}>
      <DrawerHeader>ドラゴンボール</DrawerHeader>

      <DrawerBody>
        『ドラゴンボール』は、鳥山明による日本の漫画作品です。...
      </DrawerBody>

      <DrawerFooter>
        <Button variant="ghost" onClick={onClose}>
          とじる
        </Button>
        <Button colorScheme="primary">Wikipedia</Button>
      </DrawerFooter>
    </Drawer>
  </>
)
Copied!

Change Size

Editable example

const sizeMap = ["xs", "sm", "md", "lg", "xl", "full"]
const [size, setSize] = useState("md")
const { isOpen, onOpen, onClose } = useDisclosure()

return (
  <>
    <Wrap gap="md">
      {sizeMap.map((size) => (
        <Button
          key={size}
          onClick={() => {
            setSize(size)
            onOpen()
          }}
        >
          Open {size} Drawer
        </Button>
      ))}
    </Wrap>

    <Drawer isOpen={isOpen} onClose={onClose} size={size}>
      <DrawerHeader>ドラゴンボール</DrawerHeader>

      <DrawerBody>
        『ドラゴンボール』は、鳥山明による日本の漫画作品です。...
      </DrawerBody>

      <DrawerFooter>
        <Button variant="ghost" onClick={onClose}>
          とじる
        </Button>
        <Button colorScheme="primary">Wikipedia</Button>
      </DrawerFooter>
    </Drawer>
  </>
)
Copied!

Change Position

To change the display position, set placement to values like top or left-start. By default, right is set.

Editable example

const placementMap = ["top", "right", "bottom", "left"]
const [placement, setPlacement] = useState("center")
const { isOpen, onOpen, onClose } = useDisclosure()

return (
  <>
    <Wrap gap="md">
      {placementMap.map((placement) => (
        <Button
          key={placement}
          onClick={() => {
            setPlacement(placement)
            onOpen()
          }}
        >
          Open {placement} Drawer
        </Button>
      ))}
    </Wrap>

    <Drawer isOpen={isOpen} onClose={onClose} placement={placement}>
      <DrawerHeader>ドラゴンボール</DrawerHeader>

      <DrawerBody>
        『ドラゴンボール』は、鳥山明による日本の漫画作品です。...
      </DrawerBody>

      <DrawerFooter>
        <Button variant="ghost" onClick={onClose}>
          とじる
        </Button>
        <Button colorScheme="primary">Wikipedia</Button>
      </DrawerFooter>
    </Drawer>
  </>
)
Copied!

Change Duration

To change the duration, set duration to a numerical value (seconds).

Editable example

const { isOpen, onOpen, onClose } = useDisclosure()

return (
  <>
    <Button onClick={onOpen}>Open Drawer</Button>

    <Drawer isOpen={isOpen} onClose={onClose} duration={0.7}>
      <DrawerHeader>ドラゴンボール</DrawerHeader>

      <DrawerBody>
        『ドラゴンボール』は、鳥山明による日本の漫画作品です。...
      </DrawerBody>

      <DrawerFooter>
        <Button variant="ghost" onClick={onClose}>
          とじる
        </Button>
        <Button colorScheme="primary">Wikipedia</Button>
      </DrawerFooter>
    </Drawer>
  </>
)
Copied!

Fit to Screen Height

If you want the panel to fit the height of the screen, set isFullHeight to true.

Editable example

const { isOpen, onOpen, onClose } = useDisclosure()

return (
  <>
    <Button onClick={onOpen}>Open Drawer</Button>

    <Drawer isOpen={isOpen} onClose={onClose} placement="bottom" isFullHeight>
      <DrawerHeader>ドラゴンボール</DrawerHeader>

      <DrawerBody>
        『ドラゴンボール』は、鳥山明による日本の漫画作品です。...
      </DrawerBody>

      <DrawerFooter>
        <Button variant="ghost" onClick={onClose}>
          とじる
        </Button>
        <Button colorScheme="primary">Wikipedia</Button>
      </DrawerFooter>
    </Drawer>
  </>
)
Copied!

Do Not Block Scroll on Mount

By default, scrolling of the main content is blocked when the panel is opened to ensure accessibility. If you do not want to block the scroll of the main content, set blockScrollOnMount to false.

Editable example

const { isOpen, onOpen, onClose } = useDisclosure()

return (
  <>
    <Button onClick={onOpen}>Open Drawer</Button>

    <Drawer isOpen={isOpen} onClose={onClose} blockScrollOnMount={false}>
      <DrawerHeader>ドラゴンボール</DrawerHeader>

      <DrawerBody>
        『ドラゴンボール』は、鳥山明による日本の漫画作品です。...
      </DrawerBody>

      <DrawerFooter>
        <Button variant="ghost" onClick={onClose}>
          とじる
        </Button>
        <Button colorScheme="primary">Wikipedia</Button>
      </DrawerFooter>
    </Drawer>
  </>
)
Copied!

Customize the Close Button

If you want to customize the DrawerCloseButton by passing props, etc., set it without omitting.

Editable example

const { isOpen, onOpen, onClose } = useDisclosure()

return (
  <>
    <Button onClick={onOpen}>Open Drawer</Button>

    <Drawer isOpen={isOpen} onClose={onClose}>
      <DrawerCloseButton color="red.500" />

      <DrawerHeader>ドラゴンボール</DrawerHeader>

      <DrawerBody>
        『ドラゴンボール』は、鳥山明による日本の漫画作品です。...
      </DrawerBody>

      <DrawerFooter>
        <Button variant="ghost" onClick={onClose}>
          とじる
        </Button>
        <Button colorScheme="primary">Wikipedia</Button>
      </DrawerFooter>
    </Drawer>
  </>
)
Copied!

Disable the Close Button

If onClose is not set, the close button will be disabled (hidden).

Editable example

const { isOpen, onOpen, onClose } = useDisclosure()

return (
  <>
    <Button onClick={onOpen}>Open Drawer</Button>

    <Drawer isOpen={isOpen}>
      <DrawerHeader>ドラゴンボール</DrawerHeader>

      <DrawerBody>
        『ドラゴンボール』は、鳥山明による日本の漫画作品です。...
      </DrawerBody>

      <DrawerFooter>
        <Button variant="ghost" onClick={onClose}>
          とじる
        </Button>
        <Button colorScheme="primary">Wikipedia</Button>
      </DrawerFooter>
    </Drawer>
  </>
)
Copied!

Close on drag

If you want to close the Drawer on drag, set closeOnDrag to true.

Editable example

const placementMap = ["top", "right", "bottom", "left"]
const [placement, setPlacement] = useState("center")
const { isOpen, onOpen, onClose } = useDisclosure()

return (
  <>
    <Wrap gap="md">
      {placementMap.map((placement) => (
        <Button
          key={placement}
          onClick={() => {
            setPlacement(placement)
            onOpen()
          }}
        >
          Open {placement} Drawer
        </Button>
      ))}
    </Wrap>

    <Drawer closeOnDrag isOpen={isOpen} onClose={onClose} placement={placement}>
      <DrawerHeader>ドラゴンボール</DrawerHeader>

      <DrawerBody>
        『ドラゴンボール』は、鳥山明による日本の漫画作品です。...
      </DrawerBody>

      <DrawerFooter>
        <Button variant="ghost" onClick={onClose}>
          とじる
        </Button>
        <Button colorScheme="primary">Wikipedia</Button>
      </DrawerFooter>
    </Drawer>
  </>
)
Copied!

Hide the Drag Bar

To hide the drag bar, set withDragBar to false.

Editable example

const { isOpen, onOpen, onClose } = useDisclosure()

return (
  <>
    <Button onClick={onOpen}>Open Drawer</Button>

    <Drawer
      isOpen={isOpen}
      onClose={onClose}
      closeOnDrag
      withDragBar={false}
      withCloseButton
    >
      <DrawerHeader>ドラゴンボール</DrawerHeader>

      <DrawerBody>
        『ドラゴンボール』は、鳥山明による日本の漫画作品です。...
      </DrawerBody>

      <DrawerFooter>
        <Button variant="ghost" onClick={onClose}>
          とじる
        </Button>
        <Button colorScheme="primary">Wikipedia</Button>
      </DrawerFooter>
    </Drawer>
  </>
)
Copied!

Customize the Overlay

If you want to customize the DrawerOverlay by passing props, etc., set it without omitting.

Editable example

const { isOpen, onOpen, onClose } = useDisclosure()

return (
  <>
    <Button onClick={onOpen}>Open Drawer</Button>

    <Drawer isOpen={isOpen} onClose={onClose}>
      <DrawerOverlay bg="blackAlpha.300" backdropFilter="blur(10px)" />

      <DrawerHeader>ドラゴンボール</DrawerHeader>

      <DrawerBody>
        『ドラゴンボール』は、鳥山明による日本の漫画作品です。...
      </DrawerBody>

      <DrawerFooter>
        <Button variant="ghost" onClick={onClose}>
          とじる
        </Button>
        <Button colorScheme="primary">Wikipedia</Button>
      </DrawerFooter>
    </Drawer>
  </>
)
Copied!

Disable the Overlay

To disable (hide) the overlay of the panel, set withOverlay to false.

Editable example

const { isOpen, onOpen, onClose } = useDisclosure()

return (
  <>
    <Button onClick={onOpen}>Open Drawer</Button>

    <Drawer isOpen={isOpen} onClose={onClose} withOverlay={false}>
      <DrawerHeader>ドラゴンボール</DrawerHeader>

      <DrawerBody>
        『ドラゴンボール』は、鳥山明による日本の漫画作品です。...
      </DrawerBody>

      <DrawerFooter>
        <Button variant="ghost" onClick={onClose}>
          とじる
        </Button>
        <Button colorScheme="primary">Wikipedia</Button>
      </DrawerFooter>
    </Drawer>
  </>
)
Copied!

Edit this page on GitHub

PreviousDialogNextMenu