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.

Popover size to content

See original GitHub issue

Feature request

Is your feature request related to a problem? Please describe.

Popovers constrain their content by default using a maxWidth setting. I’d like to be able to remove this setting, so the popover is sized to its content.

Describe the solution you’d like

Three ideas:

  1. Add a boolean property like fitToContent={true} which disables the maxWidth setting

  2. Support the sx property on <Popover> to override the style of the outermost popper div

  3. There is a size prop but it doesn’t appear to do anything. Depending on how it works, it might be a viable solution.

Describe alternatives you’ve considered

Here’s what I’ve tried so far:

  • <Popover>'s size prop doesn’t seem to do anything?

  • <PopoverContent> supports LayoutProps, but it’s constrained by the maxWidth property on the parent popper div.

  • <Popover> doesn’t support LayoutProps, sx, or css directly.

  • It does support styleConfig, but this overwrites the entire default theme, meaning I’d need to copy the entire default theme’s style config into my component as well:

      <Popover
        styleConfig={{
          maxWidth: 'unset',
          width: 'unset'
        }}

This works but loses all the default stylings.

  • Using extendTheme() to override the specific properties I want does work, but applies it globally to all Popovers which is not desireable:
const theme = extendTheme({
  components: {
    Popover: {
      baseStyle: {
        popper: {
          maxWidth: 'unset',
          width: 'unset'
        }
      }
    }
  }
});

Additional context

Using @chakra-ui/react: 1.0.0

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

22reactions
baumandmcommented, Dec 2, 2020

Good idea @AntonioDeCasper, I totally forgot about using variant. Here’s my updated theme, which works as expected and allows me to selectively apply it:

const theme = extendTheme({
  components: {
    Popover: {
      variants: {
        responsive: {
          popper: {
            maxWidth: 'unset',
            width: 'unset'
          }
        }
      }
    }
  }
});

And in use:

<Popover variant="responsive">
  ...
</Popover>

This solves my problem, so feel free to close this issue. However, it’s possible that some of the above alternatives should also work, so I’m leaving it open for someone else to decide what to do with.

3reactions
nvmnghiacommented, Jun 22, 2022

My version of @baumandm’s answer:

Popover: {
  variants: {
    responsive: {
      content: { width: "unset" },
    },
  },
},
Read more comments on GitHub >

github_iconTop Results From Across the Web

css - Changing the width of Bootstrap popover - Stack Overflow
I want the input form on the left side, and a wide popover on the right side. Mostly, I'm looking for a solution...
Read more >
Self-sizing Popovers - Use Your Loaf
Popover Guidelines. This technique works well when you know the content size will fit within the typical popover size (300-400 points wide).
Read more >
Popover size to fit content | Apple Developer Forums
The width of the view is fixed to 500 and I want the height to be dynamic, depending on content. One of those...
Read more >
How to change the width of the Popover body to more than ...
Bootstrap CSS sets the max-width of a popover to 276px in the popover class. If you want something wider you should override this....
Read more >
Popovers · Bootstrap v5.0
Zero-length title and content values will never show a popover. ... across multiple lines, popovers will be centered between the anchors' overall width....
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