I have overridden the onClick
function of anchor() tag in ReactJs to show loading.
const child: ReactElement = Children.only(children);
const childProps = {};
childProps['onClick'] = (event) => {
if (childProps.href && child.props.target !== '_blank') {
props.showSpinner(true);
}
let onClick = child.props.onClick;
onClick && onClick();
};
return React.cloneElement(child, childProps);
But the problem is that if the user clicks on anchor(<a>)
with shift
and command
keypress, then the user switches to the new tab but loading started showing.
So I added the following condition to show loading.
if (!event.shiftKey && childProps.href && child.props.target !== '_blank') {
props.showSpinner(true);
}
This code handled the Shift key press but I have to handle command
keypress also.
I searched through many posts, they showing solution for alt, shift, and ctl
keypress but not command keypress.