overlayClassName and styled-components not playing nicely
See original GitHub issueI’m running into a problem trying to encapsulate my Modal styles with styled-components. The following approach fails to work and the defaultProps() route is a no go as well. After looking at how react-modal generates the modal elements outside of the <App/>
root in the DOM, it’s not surprising this is causing problems. It looks like buildClassName() is correctly adding the ‘modal-overlay’ className, yet even the second approach doesn’t work. I suspect styled-components doesn’t inject the CSS as it doesn’t see any of it’s children, or any of the <App/>
children using it. Any ideas on how to get this to work to avoid using a global css class for the overlay?
const overlayClassName = 'modal-overlay'
const StyledModal = styled(Modal).attrs({
overlayClassName
})`
styles: here;
&.${overlayClassName} {
doesnt: work;
}
.${overlayClassName} {
also-doesnt: work;
}
`
Issue Analytics
- State:
- Created 6 years ago
- Comments:9 (1 by maintainers)
Top Results From Across the Web
Advanced Usage - styled-components
This component provides a theme to all React components underneath itself via the context API. In the render tree all styled-components will have...
Read more >Classes - react-modal documentation
You can use the className and overlayClassName props to control the CSS ... If you specify className , the default content styles will...
Read more >AntD Tooltip with styled-components - CodeSandbox
Activating extension 'vscode.typescript-language-features' failed: Could not find bundled tsserver.js.
Read more >Popover - Headless UI
These components are completely unstyled, so how you style your Popover is up to you. ... Button and not disturb the normal document...
Read more >styled-components.Overlay JavaScript and Node.js ... - Tabnine
Best JavaScript code snippets using styled-components. ... badgeLabels) || {}; return ( <Overlay className={className} isFaded={status.type === BADGE_TYPES.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I solved the problem without using
.attrs()
.For anyone searching, I solved this using a wrapper function, assuggested by @exogen