-
Notifications
You must be signed in to change notification settings - Fork 597
/
Copy pathanchor.ts
178 lines (161 loc) · 4.96 KB
/
anchor.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
import { attr, observable } from "@microsoft/fast-element";
import {
FoundationElement,
FoundationElementDefinition,
} from "../foundation-element/foundation-element.js";
import {
ARIAGlobalStatesAndProperties,
StartEnd,
StartEndOptions,
} from "../patterns/index.js";
import { applyMixins } from "../utilities/apply-mixins.js";
/**
* Anchor configuration options
* @public
*/
export type AnchorOptions = FoundationElementDefinition & StartEndOptions;
/**
* An Anchor Custom HTML Element.
* Based largely on the {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a | <a> element }.
*
* @slot start - Content which can be provided before the anchor content
* @slot end - Content which can be provided after the anchor content
* @slot - The default slot for anchor content
* @csspart control - The anchor element
* @csspart content - The element wrapping anchor content
*
* @public
*/
export class Anchor extends FoundationElement {
/**
* Prompts the user to save the linked URL. See {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a | <a> element } for more information.
* @public
* @remarks
* HTML Attribute: download
*/
@attr
public download: string;
/**
* The URL the hyperlink references. See {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a | <a> element } for more information.
* @public
* @remarks
* HTML Attribute: href
*/
@attr
public href: string;
/**
* Hints at the language of the referenced resource. See {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a | <a> element } for more information.
* @public
* @remarks
* HTML Attribute: hreflang
*/
@attr
public hreflang: string;
/**
* See {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a | <a> element } for more information.
* @public
* @remarks
* HTML Attribute: ping
*/
@attr
public ping: string;
/**
* See {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a | <a> element } for more information.
* @public
* @remarks
* HTML Attribute: referrerpolicy
*/
@attr
public referrerpolicy: string;
/**
* See {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a | <a> element } for more information.
* @public
* @remarks
* HTML Attribute: rel
*/
@attr
public rel: string;
/**
* See {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a | <a> element } for more information.
* @public
* @remarks
* HTML Attribute: target
*/
@attr
public target: "_self" | "_blank" | "_parent" | "_top";
/**
* See {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a | <a> element } for more information.
* @public
* @remarks
* HTML Attribute: type
*/
@attr
public type: string;
/**
*
* Default slotted content
*
* @internal
*/
@observable
public defaultSlottedContent: HTMLElement[];
/**
* References the root element
*/
public control: HTMLAnchorElement | undefined;
/**
* @internal
*/
public connectedCallback(): void {
super.connectedCallback();
this.handleUnsupportedDelegatesFocus();
}
/**
* Overrides the focus call for where delegatesFocus is unsupported.
* This check works for Chrome, Edge Chromium, FireFox, and Safari
* Relevant PR on the Firefox browser: https://phabricator.services.mozilla.com/D123858
*/
private handleUnsupportedDelegatesFocus = () => {
// Check to see if delegatesFocus is supported
if (
window.ShadowRoot &&
!window.ShadowRoot.prototype.hasOwnProperty("delegatesFocus") &&
this.$fastController.definition.shadowOptions?.delegatesFocus
) {
this.focus = () => {
this.control?.focus();
};
}
};
}
/**
* Includes ARIA states and properties relating to the ARIA link role
*
* @public
*/
export class DelegatesARIALink {
/**
* See {@link https://www.w3.org/WAI/PF/aria/roles#link} for more information
* @public
* @remarks
* HTML Attribute: aria-expanded
*/
@attr({ attribute: "aria-expanded" })
public ariaExpanded: "true" | "false" | string | null;
}
/**
* Mark internal because exporting class and interface of the same name
* confuses API documenter.
* TODO: https://github.com/microsoft/fast/issues/3317
* @internal
*/
export interface DelegatesARIALink extends ARIAGlobalStatesAndProperties {}
applyMixins(DelegatesARIALink, ARIAGlobalStatesAndProperties);
/**
* Mark internal because exporting class and interface of the same name
* confuses API documenter.
* TODO: https://github.com/microsoft/fast/issues/3317
* @internal
*/
export interface Anchor extends StartEnd, DelegatesARIALink {}
applyMixins(Anchor, StartEnd, DelegatesARIALink);