Closed benbynum closed 1 year ago
Add onClick
event to the element. It is already bypassed.
// Bypass onClick if it was present
if (elem && elem.props && typeof elem.props.onClick === 'function') {
elem.props.onClick(event);
}
Add
onClick
event to the element. It is already bypassed.// Bypass onClick if it was present if (elem && elem.props && typeof elem.props.onClick === 'function') { elem.props.onClick(event); }
This still doesn't address potential a11y issues since it will only check for an onClick
in the direct child, not any further descendants. Take my specific use case as an example:
<CopyToClipboard>
<Tooltip>
<IconButton>
<Icon />
</IconButton>
</Tooltip>
<CopyToClipboard>
The onClick
only gets triggered if attached to the Tooltip, not the IconButton.
Returning the click event from onCopy
would be an exceedingly low-risk and low-effort change while providing all parents with direct access to the event data.
Tooltip can wrap Copy, so only IconButton is a child. Then there are no problems
Please, do not wrap non-clickable elements, this makes no practical sense
Return the mouse event as a third parameter in the
onCopy
method. The particular use case is to allow event interception and stop propagation where needed. This avoids having to wrap the parent in an element with anonClick
which violates a11y principles of only having click behavior on interactive elements.Corresponding pull request for type defs: https://github.com/DefinitelyTyped/DefinitelyTyped/pull/64963