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.

[Menu] Extra padding when included as child of <Stack>

See original GitHub issue

Describe the bug A clear and concise description of what the bug is.

The <Menu> component renders two children, one for the menu button, and another for the menu itself. This means that when <Menu> is a child of <Stack>, the menu will be offset incorrectly.

Screen Shot 2020-07-04 at 5 21 55 PM

Should <Menu> render a <Box> around the children? Like this:

Screen Shot 2020-07-04 at 5 22 28 PM

This is the fixed code (notice how I manually wrap the <Menu> in a <Box>):

    <Stack
      direction='row'
      align='center'
      width='full'
      {...rest}
    >
      <Box>
        <Menu>
          <MenuButton size='sm'><MdMoreHorizIcon boxSize={5} /></MenuButton>
          <MenuList>
            <ReportButton as={MenuItem} game={game}>
              <MdReportProblemIcon mr={2} />
              Report
            </ReportButton>
          </MenuList>
        </Menu>
      </Box>
  </Stack>

Expected Behavior A clear and concise description of what you expected to happen.

The following code, without a <Box> manually added around the <Menu> should render without extra padding on the menu.

    <Stack
      direction='row'
      align='center'
      width='full'
      {...rest}
    >
        <Menu>
          <MenuButton size='sm'><MdMoreHorizIcon boxSize={5} /></MenuButton>
          <MenuList>
            <ReportButton as={MenuItem} game={game}>
              <MdReportProblemIcon mr={2} />
              Report
            </ReportButton>
          </MenuList>
        </Menu>
  </Stack>

Desktop (please complete the following information):

  • OS: [e.g. iOS] macOS
  • Browser [e.g. chrome, safari] Chrome
  • Version [e.g. 22] Latest

Additional context Add any other context about the problem here, or some background information of how you ran into this bug.

1.0.0-next.4

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
ferosscommented, Jul 17, 2020

@segunadebayo I’m assuming that you want to give some space between the MenuButton and MenuList, right? If that’s the case you can pass gutter prop to Menu and set it’s value to the space you want between them (30, 24, etc).

The intention of using a <Stack> was to have other buttons horizontally alongside the button that triggers the menu, not to get spacing between MenuButton and MenuList. For example:

Screen Shot 2020-07-16 at 8 41 02 PM

So the ‘…’ button (which opens the menu) and the ‘Extend by 2 minutes’ button are in the <Stack>. Does that make sense?

0reactions
with-heartcommented, Jul 17, 2020

Here’s a reproduction: https://codesandbox.io/s/boring-shape-mhgib?file=/src/App.tsx

Definitely see what you mean @feross.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Extra padding under menu with child - css - Stack Overflow
Your CSS contained display:inline which has block child element and position absolute as well. Try this CSS property.
Read more >
Stack class - widgets library - Flutter - Dart API docs
A widget that positions its children relative to the edges of its box. This class is useful if you want to overlap several...
Read more >
Xamarin.Forms StackLayout - Microsoft Learn
A StackLayout organizes child views in a one-dimensional stack, either horizontally or vertically.
Read more >
Explore auto layout properties - Figma Help Center
Padding. Padding controls the empty or white space between the boundary of an auto layout frame and the frame's child objects. You can...
Read more >
React Stack component - Material UI - MUI
To control space between children, use the spacing prop. The spacing value can be any number, including decimals and any string. The prop...
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