In my application I have two grid items that overlap. In consequence, pointer events such as click or hover are only triggered on the upper element (according to z-index or order of appearance).
I am wondering if there is a way (react/js or css wise) to make both items detect the pointer events or at least simulate that hehavior:
Here is my example:
export default function App() {
function onClick() {
console.log("click");
}
return (
<div className="grid">
<div className="item-1" />
<div className="item-2" onClick={onClick}>
Click
</div>
</div>
);
}
.grid {
display: grid;
grid-template-columns: 100px 100px 100px;
}
.item-1 {
grid-row: 1;
grid-column: 1/-1;
background-color: deeppink;
}
.item-1:hover {
background-color: lime;
}
.item-2 {
grid-row: 1;
grid-column: 2;
border: 1px solid black;
cursor: pointer;
}
function App() {
function onClick() {
console.log("click");
}
return (
<div className="grid">
<div className="item-1" />
<div className="item-2" onClick={onClick}>
Click
</div>
</div>
);
}
ReactDOM.render(
<App />,
document.getElementById("root")
);
.grid {
display: grid;
grid-template-columns: 100px 100px 100px;
}
.item-1 {
grid-row: 1;
grid-column: 1/-1;
background-color: deeppink;
}
.item-1:hover {
background-color: lime;
}
.item-2 {
grid-row: 1;
grid-column: 2;
border: 1px solid black;
cursor: pointer;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.8.4/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.8.4/umd/react-dom.production.min.js"></script>
<div id="root"></div>
See this codesandbox.
item-1 changes its color on hover and item-2 triggers a function on click. Obviously, when hovering over item-2, it captures the hover event and item-1 doesn't change it's color.
What I'm looking for is a way such that hovering (and clicking) on item-2 is also redirected to item-1 or is somehow "bubbling" through both elements.
What I don't want to do is to change the html-structure, i.e. the two elements must be parallel children of a grid container.