eui icon indicating copy to clipboard operation
eui copied to clipboard

[EuiCard] onClick loses MouseEvent details

Open pickypg opened this issue 4 years ago • 0 comments

While integrating an EUI with React Router 5.1, I noticed that opening EuiCard-based links (by clicking the card itself) in new tabs resulted in the current tab also navigating to the link even though I was actively ignoring onClick using the suggested mechanism:

const isModifiedEvent = (event: MouseEvent) =>
  !!(event.metaKey || event.altKey || event.ctrlKey || event.shiftKey);

Upon deeper inspection, I realized that it simply did not recognize that any of those were pressed (on Windows it's normal for metaKey to be ignored, but on macOS that's the Command key). Looking at the code, it appears to be because the onClick handler calls the link.click, which itself appears unable to passthrough the MouseEvent:

https://github.com/elastic/eui/blob/00fa72904df581617e37f4f8bcf1c66abcdf04e0/src/components/card/card.tsx#L211-L215

As a minor workaround, at the expense of functionality, I have temporarily removed the href and onClick properties from EuiCard and simply leave it to a button in the footer.

pickypg avatar Feb 26 '21 04:02 pickypg