question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Drawer] Drawer height changes when placement is "bottom/top"

See original GitHub issue

Bug report

Describe the bug

With <Drawer placement="bottom" size="md" />, the drawer height keeps growing as you add more content to DrawerBody, even though you have specified a md size.

To reproduce

  1. Go to https://next.chakra-ui.com/docs/overlay/drawer#drawer-placement
  2. Choose placement bottom
  3. Add lots of content within DrawerBody
  4. See the oversized panel

Minimal reproduction

Expected behavior

The Drawer should honor size and have a max-height when placement is bottom or top, just like it has max-width when placement is left or right

Screenshots

image

System information

  • OS: [e.g. macOS, Windows]
  • Browser (if applies): [e.g. Chrome, Safari]
  • Version of @chakra-ui/core: [e.g. 1.0.0-rc.3]
  • Version of Node.js: [e.g. 12.11.1]

Additional context

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
binajmencommented, Apr 13, 2021

Hi @ctpaulson,

I solved this using a hook largely inspired from https://usehooks.com/useWindowSize/:

import * as React from 'react'

type WindowSize = {
  width: number
  height: number
}

export default function useWindowSize() {
  // https://joshwcomeau.com/react/the-perils-of-rehydration/
  const [windowSize, setWindowSize] = React.useState<WindowSize>({
    width: 0,
    height: 0,
  })

  React.useEffect(() => {
    function handleResize() {
      setWindowSize({
        width: window.innerWidth,
        height: window.innerHeight,
      })
    }

    window.addEventListener("resize", handleResize)
    handleResize()

    return () => window.removeEventListener("resize", handleResize)
  }, [])

  return windowSize
}
const { height } = useWindowSite()
...
      <Drawer placement="bottom" isOpen={isOpen} onClose={onClose}>
        <DrawerOverlay>
          <DrawerContent maxH={height}>

It works pretty well 😉

1reaction
ctpaulsoncommented, Apr 12, 2021

@binajmen @imdongchen Here’s a workaround I figured out.

You can add a maxH attribute to the <DrawerContent> component, like so:

<Drawer
        isOpen={isOpen}
        placement="bottom"
        onClose={onClose}
        finalFocusRef={btnRef}
      >
        <DrawerOverlay>
          <DrawerContent maxH="75vh">
            <DrawerCloseButton />
            <DrawerHeader>Create your account</DrawerHeader>

            <DrawerBody>
              <Input placeholder="Type here..." />
            </DrawerBody>

            <DrawerFooter>
              <Button variant="outline" mr={3} onClick={onClose}>
                Cancel
              </Button>
              <Button colorScheme="blue">Save</Button>
            </DrawerFooter>
          </DrawerContent>
        </DrawerOverlay>
      </Drawer>

You can use either vh units if you want the drawer to take up a certain portion of the viewport height, or hardcode a px value.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Slidingdrawer position changes while adjust it's height
I have created sliding drawer for my relative layout which includes some buttons. But when I adjust the height of the drawer the...
Read more >
Install Drawers Without Metal Slides - Wood Magazine
This method allows for drawers the full height and width of the opening. Because the groove should be at least 3 ⁄ 8...
Read more >
How to Adjust Cabinet Drawer Guides & Faces - YouTube
If your cabinet drawer looks crooked or isn't operating smoothly, chances are it just needs some minor adjustments.
Read more >
Overview | TMS Diagram Studio documentation
Helper class TBlockDrawer for easy custom drawing on custom blocks;. Lots of ready-to-use TAction descendants available for specific diagram operations:.
Read more >
Vantage+Spec+Book+2019+.pdf - Amazon AWS
Throughout this specifications guide, you'll find thousands of ways to ... randomly distress cabinet doors and drawers to mimic the character marks of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found