Skip to content

Commit e2ff35e

Browse files
committed
feat: add anchor attributes to payload in HandleLinkPressFeature
resolves #8
1 parent 9b1d579 commit e2ff35e

File tree

3 files changed

+58
-1
lines changed

3 files changed

+58
-1
lines changed

packages/webshell/src/features/HandleLinkPressFeature.ts

+36
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,42 @@ export interface LinkPressTarget {
4343
* The exact content of the `href` attribute.
4444
*/
4545
hrefAttribute: string;
46+
/**
47+
* The `download` attribute, if present.
48+
*/
49+
downloadAttribute: string | null;
50+
/**
51+
* The `target` attribute, if present.
52+
*/
53+
targetAttribute: string | null;
54+
/**
55+
* The `hreflang` attribute, if present.
56+
*/
57+
hreflangAttribute: string | null;
58+
/**
59+
* The `referrerpolicy` attribute, if present.
60+
*/
61+
referrerpolicyAttribute: string | null;
62+
/**
63+
* The `rel` attribute, if present.
64+
*/
65+
relAttribute: string | null;
66+
/**
67+
* The `type` attribute, if present.
68+
*/
69+
typeAttribute: string | null;
70+
/**
71+
* The `id` attribute, if present.
72+
*/
73+
idAttribute: string | null;
74+
/**
75+
* The `class` attribute, if present.
76+
*/
77+
classAttribute: string | null;
78+
/**
79+
* The `name` attribute, if present.
80+
*/
81+
nameAttribute: string | null;
4682
/**
4783
* The bounding rectangle of the anchor which has been clicked.
4884
* See {@link https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect | Element.getBoundingClientRect()}

packages/webshell/src/features/HandleLinkPressFeature.webjs

+9
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,15 @@ function HandleLinkPressFeature(context) {
4747
uri: href,
4848
scheme: extractScheme(href),
4949
hrefAttribute: anchor.getAttribute('href'),
50+
downloadAttribute: anchor.getAttribute('download'),
51+
targetAttribute: anchor.getAttribute('target'),
52+
hreflangAttribute: anchor.getAttribute('hreflang'),
53+
referrerpolicyAttribute: anchor.getAttribute('referrerpolicy'),
54+
relAttribute: anchor.getAttribute('rel'),
55+
typeAttribute: anchor.getAttribute('type'),
56+
idAttribute: anchor.getAttribute('id'),
57+
classAttribute: anchor.getAttribute('class'),
58+
nameAttribute: anchor.getAttribute('name'),
5059
clickedAnchorBoundingRect: clickedAnchorBoundingRect,
5160
page: {
5261
href: window.location.href,

packages/webshell/src/features/__tests__/HandleLinkPressFeature.test.tsx

+13-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ describe('Webshell with HandleLinkPressFeature', () => {
1616
render(
1717
<Webshell
1818
onDOMLinkPress={onDOMLinkPress}
19-
source={{ html: '<a id="anchor0" href="https://foo.org">bar</a>' }}
19+
source={{
20+
html:
21+
'<a id="anchor0" class="link" type="text/html" rel="alternate" download="" target="_blank" hreflang="en" referrerpolicy="no-referrer" href="https://foo.org">bar</a>'
22+
}}
2023
/>
2124
)
2225
);
@@ -25,6 +28,15 @@ describe('Webshell with HandleLinkPressFeature', () => {
2528
uri: 'https://foo.org/',
2629
scheme: expect.any(String),
2730
hrefAttribute: expect.any(String),
31+
downloadAttribute: '',
32+
targetAttribute: '_blank',
33+
hreflangAttribute: 'en',
34+
referrerpolicyAttribute: 'no-referrer',
35+
relAttribute: 'alternate',
36+
typeAttribute: 'text/html',
37+
idAttribute: 'anchor0',
38+
classAttribute: 'link',
39+
nameAttribute: null,
2840
clickedAnchorBoundingRect: {
2941
top: expect.any(Number),
3042
left: expect.any(Number),

0 commit comments

Comments
 (0)