Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

POC of honoring cmd+click events in cards to open card links in a new tab #7989

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/eui/src-docs/src/views/card/card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ const cardNodes = icons.map(function (item, index) {
title={`Elastic ${item}`}
isDisabled={item === 'Kibana' ? true : false}
description="Example of a card's description. Stick to one or two sentences."
onClick={() => {}}
href="http://www.example.com"
onClick={() => {console.log('hi')}}
/>
</EuiFlexItem>
);
Expand Down
6 changes: 5 additions & 1 deletion packages/eui/src/components/card/card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,11 @@ export const EuiCard: FunctionComponent<EuiCardProps> = ({
let link: HTMLAnchorElement | HTMLButtonElement | null = null;
const outerOnClick = (e: React.MouseEvent<HTMLDivElement>) => {
if (link && link !== e.target && !link.contains(e.target as Node)) {
link.click();
// Clone and dispatch event rather than trigger link.click so that links can still be opened in a new tab
// with cmd+click, etc.
const newEvent = new PointerEvent(e.nativeEvent.type, e.nativeEvent);
// Dispatch the cloned event on the new target
link.dispatchEvent(newEvent);
}
};

Expand Down
Loading