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.

<motion.div> breaks styled jsx

See original GitHub issue

Describe the bug With styled-jsx a <style jsx>{}</style> tag is added right before the closing element tag in a component. Adding Motion to that component breaks the styled-jsx and does not style the component.

To Reproduce Check out this sandbox showing the issue: https://codesandbox.io/s/hello-world-ec8og

Expected behavior Its expected that the styles would be applied to a motion element just like it would if it wasn’t a motion element.

Desktop (please complete the following information):

  • OS: MacOS
  • Browser Chrome
  • Version 75

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:4
  • Comments:8

github_iconTop GitHub Comments

5reactions
danilocktharcommented, Apr 1, 2020

I think the corrected version its not the best way to do it. Hope this get fixed in some advanced version of framer motion.

2reactions
rudralcommented, Aug 29, 2020

Got the same issue today… Thanks for the solution @krall12 .

Here is my example of using more than one classNames in a component:

modal.styles.js

import css from 'styled-jsx/css'

export default css.resolve`
    .modal-backdrop {
        ...
    }
    .modal-content {
        ...
    }
`

modal.js

import styledJsx from './modal.styles'
import { motion } from 'framer-motion'

const Modal = ({children, ...otherStuff}) => {
        <motion.div className={`${styledJsx.className} modal-backdrop`}
            initial={{ opacity: 0 }}
            animate={{ opacity: 1 }}
        >
            <motion.div className={`${styledJsx.className} modal-content`}
                initial={{ y: '-100vh' }}
                animate={{ y: 0 }}
            >
                {children}
            </motion.div>
            {styledJsx.styles}
        </motion.div>
}

export default Modal
Read more comments on GitHub >

github_iconTop Results From Across the Web

Styled-jsx styling not applied to Framer-Motion element
Just for kicks I created a new react app with framer-motion and it worked without issue there. import {motion} from 'framer-motion'; export ...
Read more >
Layout animations | Framer for Developers
Create layout and shared layout animations with React and Framer Motion. CSS layouts are difficult and expensive to animate. Animating a style like...
Read more >
How to use the framer-motion.motion.div function in ... - Snyk
width};` : 'width: 200px;')} display: inline-block; `; const BottomWrapper = styled(motion.div)``; export const FormField: React.FC<Props> = React.forwardRef( ( ...
Read more >
framer-motion.motion.div JavaScript and Node.js code examples
origin: indreklasn/react-framer-motion-examples. src/pop.js/Pop. const Pop = () => ( <motion.div style={styles} animate={{ scale: [1, 2, 2, 1, 1], ...
Read more >
page-break-before - CSS: Cascading Style Sheets | MDN
The page-break-before CSS property adjusts page breaks before the current ... Avoid page break before div elements of class note */ div.note ...
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