How to apply styles to a child element on parent hover? #4313
-
Hey guys, I'm trying to achieve a simple task with Paste - to toggle an element visibility on a parent element hover. The Paste AI helper says that it's achievable by assigning unique IDs to parent and child elements and then using e.g. I'm using latest versions of Paste core and icons packages. Here's what was suggested by the AI and what I tried to do. This had no effect whatsoever on the child element. import { CustomizationProvider } from '@twilio-paste/customization';
import { Box } from '@twilio-paste/core/box';
<CustomizationProvider
elements={{
PARENT: {
position: 'relative',
':hover CHILD': {
display: 'block',
},
},
CHILD: {
display: 'none', // Initially hidden
position: 'absolute',
top: '0',
left: '0',
backgroundColor: 'colorBackgroundPrimary',
padding: 'space20',
zIndex: 1,
},
}}
>
<Box data-paste-element="PARENT">
Hover over me
<Box data-paste-element="CHILD">
I show on hover!
</Box>
</Box>
</CustomizationProvider> |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 4 replies
-
Disclaimer: This is a very experimental bot using OpenAI's GPT-4. The answers may not be correct, a human will review the answer and update it if necessary. Sorry, I don't know how to help with that. I did do a search though, and I managed to find these other Discussions that might be similar or related to your question. Give them a read to see if they answer your question. If they do, head back here and update this discussion and mark it as answered, pointing others to the related discussion:
|
Beta Was this translation helpful? Give feedback.
-
To achieve the desired effect of toggling a child element's visibility on a parent element's hover using the Paste framework, you can use the Here's an example of how you can implement this: import React, { useState } from 'react';
import { Box } from '@twilio-paste/box';
const ParentComponent = () => {
const [isHovered, setIsHovered] = useState(false);
return (
<Box
data-paste-element="PARENT"
onMouseEnter={() => setIsHovered(true)}
onMouseLeave={() => setIsHovered(false)}
position="relative"
>
Hover over me
<Box
data-paste-element="CHILD"
display={isHovered ? 'block' : 'none'} // Toggle visibility based on hover state
position="absolute"
top="0"
left="0"
backgroundColor="colorBackgroundPrimary"
padding="space20"
zIndex={1}
>
I show on hover!
</Box>
</Box>
);
};
export default ParentComponent; In this example, the To continue talking to Dosu, mention @dosu. Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other |
Beta Was this translation helpful? Give feedback.
-
Hi @dmitriy-kudelko! I'm exploring this and will get back to you this week. I'm not positive that the Customization Provider does support that type of selector. Can you explain why you're hoping to find a CSS selector over using the solution that DosuBot provided? Thanks! |
Beta Was this translation helpful? Give feedback.
It's definitely possible to achieve with Paste! I just don't believe the Customization Provider currently supports the type of selector you're looking to use. If you add the hover styles directly onto the Box you should see the results you're expecting.
Here's a CodeSandbox @PixeledCode made showing the behavior.