Skip to content

Attribute selector support? #1794

Answered by hasparus
lanyusan asked this question in Q&A
Discussion options

You must be logged in to vote

Selecting on data attributes should just work (TM).

        sx={{
          '[data-my-attribute="hello"]': { color: "blue" }
        }}

Here's a CodeSandbox for you: https://codesandbox.io/s/gracious-zhukovsky-4ikim?file=/src/App.tsx

I have found out framer motion wouldn't animate sx but only style, which is fine. But I don't want to put the above css in a css file.

Sidenote: I think animating sx is technically possible to do with some more fiddling, but it's a really bad idea anyway -- each unique style object given to sx will create a new className and append a style tag to your DOM.

Later, if you need dynamic, frequently changing values in your styles (e.g. animations), you can set a…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@lanyusan
Comment options

Answer selected by lanyusan
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants