MCPcopy Create free account
hub / github.com/adobe/react-spectrum / openLink

Function openLink

packages/react-aria/src/utils/openLink.tsx:106–128  ·  view source on GitHub ↗
(target: HTMLAnchorElement, modifiers: Modifiers, setOpening = true)

Source from the content-addressed store, hash-verified

104}
105
106export function openLink(target: HTMLAnchorElement, modifiers: Modifiers, setOpening = true): void {
107 let {metaKey, ctrlKey, altKey, shiftKey} = modifiers;
108
109 // WebKit does not support firing click events with modifier keys, but does support keyboard events.
110 // https://github.com/WebKit/WebKit/blob/c03d0ac6e6db178f90923a0a63080b5ca210d25f/Source/WebCore/html/HTMLAnchorElement.cpp#L184
111 let event =
112 isWebKit() && isMac() && !isIPad() && process.env.NODE_ENV !== 'test'
113 ? // @ts-ignore - keyIdentifier is a non-standard property, but it's what webkit expects
114 new KeyboardEvent('keydown', {keyIdentifier: 'Enter', metaKey, ctrlKey, altKey, shiftKey})
115 : new MouseEvent('click', {
116 metaKey,
117 ctrlKey,
118 altKey,
119 shiftKey,
120 detail: 1,
121 bubbles: true,
122 cancelable: true
123 });
124 (openLink as any).isOpening = setOpening;
125 focusWithoutScrolling(target);
126 target.dispatchEvent(event);
127 (openLink as any).isOpening = false;
128}
129// https://github.com/parcel-bundler/parcel/issues/8724
130(openLink as any).isOpening = false;
131

Callers 3

onKeyUpFunction · 0.90
RouterProviderFunction · 0.85
openSyntheticLinkFunction · 0.85

Calls 1

focusWithoutScrollingFunction · 0.90

Tested by

no test coverage detected