Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,23 @@ export class BaseAnchor extends FASTElement {
return true;
}

/**
* Handles the anchor auxclick event (middle mouse button).
* Opens the link in a new tab when the middle mouse button is clicked.
*
* @param e - The event object
* @internal
*/
public auxclickHandler(e: PointerEvent): boolean {
if (e.button !== 1 || !this.href) {
return true;
}

e.preventDefault();
window.open(this.href, '_blank');
return true;
}

/**
* Handles keydown events for the anchor.
*
Expand Down Expand Up @@ -230,4 +247,4 @@ export class BaseAnchor extends FASTElement {
proxy.inert = true;
return proxy;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export function anchorTemplate<T extends AnchorButton>(options: AnchorOptions =
<template
tabindex="0"
@click="${(x, c) => x.clickHandler(c.event as PointerEvent)}"
@auxclick="${(x, c) => x.auxclickHandler(c.event as PointerEvent)}"
@keydown="${(x, c) => x.keydownHandler(c.event as KeyboardEvent)}"
>
${startSlotTemplate(options)}
Expand All @@ -26,4 +27,4 @@ export function anchorTemplate<T extends AnchorButton>(options: AnchorOptions =
* The template for the Button component.
* @public
*/
export const template: ElementViewTemplate<AnchorButton> = anchorTemplate();
export const template: ElementViewTemplate<AnchorButton> = anchorTemplate();
3 changes: 2 additions & 1 deletion packages/web-components/src/link/link.template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export function anchorTemplate<T extends Link>(): ViewTemplate<T> {
<template
tabindex="0"
@click="${(x, c) => x.clickHandler(c.event as PointerEvent)}"
@auxclick="${(x, c) => x.auxclickHandler(c.event as PointerEvent)}"
@keydown="${(x, c) => x.keydownHandler(c.event as KeyboardEvent)}"
>
<slot></slot>
Expand All @@ -21,4 +22,4 @@ export function anchorTemplate<T extends Link>(): ViewTemplate<T> {
* The template for the Link component.
* @public
*/
export const template: ElementViewTemplate<Link> = anchorTemplate();
export const template: ElementViewTemplate<Link> = anchorTemplate();