Popover size to content
See original GitHub issueFeature 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:
-
Add a boolean property like
fitToContent={true}
which disables themaxWidth
setting -
Support the
sx
property on<Popover>
to override the style of the outermost popper div -
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>
'ssize
prop doesn’t seem to do anything? -
<PopoverContent>
supportsLayoutProps
, but it’s constrained by themaxWidth
property on the parent popper div. -
<Popover>
doesn’t supportLayoutProps
,sx
, orcss
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:
- Created 3 years ago
- Reactions:1
- Comments:6 (1 by maintainers)
Top GitHub Comments
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:And in use:
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.
My version of @baumandm’s answer: