How can any click events be disabled for props.children
?
const Example = props => (
<div>
<div>This can be clicked</div>
{props.children} /* These can't be clicked */
</div>
)
I am rendering a PDF page using react-pdf and want the user to be able to drag a custom selection marquee (like in Photoshop…). As it is, the PDF page under or inside the marquee element still registers mouse events upon dragging, like text selection.
3
Answers
Use CSS Grid to put a
div
on top!A transparent
div
rendered on top of anotherdiv
will intercept click events.CSS Grid can be used (abused?) to make a single grid area (using
grid-template-areas
) and assign multiple elements to it (usinggrid-area
).JSX
CSS
Note that ClickGuard expects two props:
allow
andblock
. These should be JSX. The React docs explain passing React elements here.You cannot change the props within an element thus its children props.
An alternative solution may be possible with React.cloneElement,
Here is a simple peace of code for you:
There is an easy, but not robust way to do this:
It is not robust, because if any of the children have
pointer-events
set toauto
, they will be clickable too. See if it fits your needs. Also, it will killhover
and other mouse events.