@brightspace-ui/core 3.156.4 → 3.158.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -21,11 +21,6 @@ export const LinkMixin = superclass => class extends LocalizeCoreElement(supercl
|
|
21
21
|
* @type {string}
|
22
22
|
*/
|
23
23
|
href: { type: String },
|
24
|
-
/**
|
25
|
-
* Label for the link
|
26
|
-
* @type {string}
|
27
|
-
*/
|
28
|
-
ariaLabel: { type: String, attribute: 'aria-label' },
|
29
24
|
/**
|
30
25
|
* Where to display the linked URL
|
31
26
|
* @type {string}
|
@@ -57,14 +52,19 @@ export const LinkMixin = superclass => class extends LocalizeCoreElement(supercl
|
|
57
52
|
`];
|
58
53
|
}
|
59
54
|
|
60
|
-
|
55
|
+
getNewWindowDescription(label) {
|
56
|
+
return label && this.target === '_blank' ? this.localize('components.link.open-in-new-window') : undefined;
|
57
|
+
}
|
58
|
+
|
59
|
+
_render(inner, { ariaLabel = undefined, rel = undefined, linkClasses = {}, tabindex = undefined } = {}) {
|
61
60
|
/*
|
62
61
|
* NOTICE:
|
63
62
|
* All html template whitespace within this component is critical to proper rendering and wrapping.
|
64
63
|
* Do not modify for readability!
|
65
64
|
*/
|
66
65
|
return html`<a
|
67
|
-
aria-label="${ifDefined(
|
66
|
+
aria-label="${ifDefined(ariaLabel)}"
|
67
|
+
aria-description="${ifDefined(this.getNewWindowDescription(ariaLabel))}"
|
68
68
|
class="${classMap(linkClasses)}"
|
69
69
|
download="${ifDefined(this.download)}"
|
70
70
|
href="${ifDefined(this.href)}"
|
@@ -4,6 +4,12 @@
|
|
4
4
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
5
5
|
<meta charset="UTF-8">
|
6
6
|
<link rel="stylesheet" href="../../demo/styles.css" type="text/css">
|
7
|
+
<script type="module">
|
8
|
+
import { mockFlag } from '../../../helpers/flags.js';
|
9
|
+
const urlParams = new URLSearchParams(window.location.search);
|
10
|
+
mockFlag('GAUD-8295-menu-item-link-new-window-icon', urlParams.get('link-new-window-icon') === 'true');
|
11
|
+
mockFlag('GAUD-8369-menu-item-link-click-changes', urlParams.get('link-click-changes') === 'true');
|
12
|
+
</script>
|
7
13
|
<script type="module">
|
8
14
|
import '../../demo/demo-page.js';
|
9
15
|
import './custom-menu-item.js';
|
@@ -200,5 +206,12 @@
|
|
200
206
|
</template>
|
201
207
|
</d2l-demo-snippet>
|
202
208
|
</d2l-demo-page>
|
209
|
+
|
210
|
+
<script>
|
211
|
+
document.addEventListener('click', e => {
|
212
|
+
if (e.target.tagName !== 'D2L-MENU-ITEM-LINK') return;
|
213
|
+
console.log('Click event propagated up for router!', e.target);
|
214
|
+
});
|
215
|
+
</script>
|
203
216
|
</body>
|
204
217
|
</html>
|
@@ -2,21 +2,24 @@ import { css, html, LitElement } from 'lit';
|
|
2
2
|
import { getFlag } from '../../helpers/flags.js';
|
3
3
|
import { ifDefined } from 'lit/directives/if-defined.js';
|
4
4
|
import { LinkMixin } from '../link/link-mixin.js';
|
5
|
+
import { LocalizeCoreElement } from '../../helpers/localize-core-element.js';
|
5
6
|
import { MenuItemMixin } from './menu-item-mixin.js';
|
6
7
|
import { menuItemStyles } from './menu-item-styles.js';
|
7
8
|
|
8
9
|
const newWindowIconEnabled = getFlag('GAUD-8295-menu-item-link-new-window-icon', true);
|
9
10
|
|
11
|
+
const menuItemClickChangesEnabled = getFlag('GAUD-8369-menu-item-link-click-changes', true);
|
12
|
+
|
10
13
|
/**
|
11
14
|
* A menu item component used for navigating.
|
12
15
|
* @fires click - Dispatched when the link is clicked
|
13
16
|
* @slot supporting - Allows supporting information to be displayed on the right-most side of the menu item
|
14
17
|
*/
|
15
|
-
class MenuItemLink extends (newWindowIconEnabled ? LinkMixin(MenuItemMixin(LitElement)) : MenuItemMixin(LitElement)) {
|
18
|
+
class MenuItemLink extends (newWindowIconEnabled ? LinkMixin(MenuItemMixin(LitElement)) : LocalizeCoreElement(MenuItemMixin(LitElement))) {
|
16
19
|
|
17
20
|
static get properties() {
|
18
|
-
|
19
|
-
return {
|
21
|
+
// remove this block when cleaning up GAUD-8295-menu-item-link-new-window-icon
|
22
|
+
if (!newWindowIconEnabled) return {
|
20
23
|
/**
|
21
24
|
* Prompts the user to save the linked URL instead of navigating to it.
|
22
25
|
* Must be to a resource on the same origin.
|
@@ -33,7 +36,12 @@ class MenuItemLink extends (newWindowIconEnabled ? LinkMixin(MenuItemMixin(LitEl
|
|
33
36
|
* Where to display the linked URL
|
34
37
|
* @type {string}
|
35
38
|
*/
|
36
|
-
target: { type: String }
|
39
|
+
target: { type: String },
|
40
|
+
_ariaDescription: { type: String, attribute: 'aria-description', reflect: true },
|
41
|
+
};
|
42
|
+
|
43
|
+
return {
|
44
|
+
_ariaDescription: { type: String, attribute: 'aria-description', reflect: true },
|
37
45
|
};
|
38
46
|
}
|
39
47
|
|
@@ -90,9 +98,14 @@ class MenuItemLink extends (newWindowIconEnabled ? LinkMixin(MenuItemMixin(LitEl
|
|
90
98
|
];
|
91
99
|
}
|
92
100
|
|
101
|
+
constructor() {
|
102
|
+
super();
|
103
|
+
this._letClickPropagate = true;
|
104
|
+
}
|
105
|
+
|
93
106
|
firstUpdated() {
|
94
107
|
super.firstUpdated();
|
95
|
-
this.addEventListener('click', this._onClick);
|
108
|
+
if (!menuItemClickChangesEnabled) this.addEventListener('click', this._onClick); // remove when cleaning up GAUD-8369-menu-item-link-click-changes
|
96
109
|
this.addEventListener('keydown', this._onKeyDown);
|
97
110
|
}
|
98
111
|
|
@@ -113,10 +126,23 @@ class MenuItemLink extends (newWindowIconEnabled ? LinkMixin(MenuItemMixin(LitEl
|
|
113
126
|
${this._renderNewWindowIcon()}
|
114
127
|
<div class="d2l-menu-item-supporting"><slot name="supporting"></slot></div>
|
115
128
|
`;
|
116
|
-
return this._render(inner, { rel: this.target ? 'noreferrer noopener' : undefined, tabindex: -1 });
|
129
|
+
return this._render(inner, { ariaLabel: this._ariaLabel, rel: this.target ? 'noreferrer noopener' : undefined, tabindex: -1 });
|
117
130
|
|
118
131
|
}
|
119
132
|
|
133
|
+
willUpdate(changedProperties) {
|
134
|
+
super.willUpdate(changedProperties);
|
135
|
+
if (newWindowIconEnabled && changedProperties.has('_ariaLabel') || changedProperties.has('target')) {
|
136
|
+
this._ariaDescription = this.getNewWindowDescription(this._ariaLabel);
|
137
|
+
}
|
138
|
+
}
|
139
|
+
|
140
|
+
// remove this function when cleaning up GAUD-8295-menu-item-link-new-window-icon
|
141
|
+
getNewWindowDescription(label) {
|
142
|
+
return label && this.target === '_blank' ? this.localize('components.link.open-in-new-window') : undefined;
|
143
|
+
}
|
144
|
+
|
145
|
+
// remove this function when cleaning up GAUD-8369-menu-item-link-click-changes
|
120
146
|
_getTarget() {
|
121
147
|
if (this.target && this.target !== '') {
|
122
148
|
return this.target;
|
@@ -129,19 +155,27 @@ class MenuItemLink extends (newWindowIconEnabled ? LinkMixin(MenuItemMixin(LitEl
|
|
129
155
|
return null;
|
130
156
|
}
|
131
157
|
|
158
|
+
// remove this function when cleaning up GAUD-8369-menu-item-link-click-changes
|
132
159
|
_onClick() {
|
133
160
|
if (this.shadowRoot) this.shadowRoot.querySelector('a').dispatchEvent(new CustomEvent('click'));
|
134
161
|
}
|
135
162
|
|
136
163
|
_onKeyDown(e) {
|
137
|
-
if (
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
164
|
+
if (menuItemClickChangesEnabled) {
|
165
|
+
if (e.keyCode === this.__keyCodes.ENTER || e.keyCode === this.__keyCodes.SPACE) {
|
166
|
+
this.shadowRoot.querySelector('a').click();
|
167
|
+
}
|
168
|
+
} else { // remove this block when cleaning up GAUD-8369-menu-item-link-click-changes
|
169
|
+
super._onKeyDown(e);
|
170
|
+
if (e.keyCode === this.__keyCodes.ENTER || e.keyCode === this.__keyCodes.SPACE) {
|
171
|
+
const target = this._getTarget();
|
172
|
+
if (target === '_parent') {
|
173
|
+
window.parent.location.assign(this.href);
|
174
|
+
} else if (target === '_top') {
|
175
|
+
window.top.location.assign(this.href);
|
176
|
+
} else {
|
177
|
+
window.location.assign(this.href);
|
178
|
+
}
|
145
179
|
}
|
146
180
|
}
|
147
181
|
}
|
@@ -1,6 +1,8 @@
|
|
1
|
+
import { getFlag } from '../../helpers/flags.js';
|
1
2
|
import { PropertyRequiredMixin } from '../../mixins/property-required/property-required-mixin.js';
|
2
3
|
|
3
4
|
const defaultLines = 2;
|
5
|
+
const menuItemClickChangesEnabled = getFlag('GAUD-8369-menu-item-link-click-changes', true);
|
4
6
|
|
5
7
|
export const MenuItemMixin = superclass => class extends PropertyRequiredMixin(superclass) {
|
6
8
|
|
@@ -54,7 +56,8 @@ export const MenuItemMixin = superclass => class extends PropertyRequiredMixin(s
|
|
54
56
|
*/
|
55
57
|
description: { type: String },
|
56
58
|
_ariaDisabled: { type: String, attribute: 'aria-disabled', reflect: true },
|
57
|
-
_ariaLabel: { type: String, attribute: 'aria-label', reflect: true }
|
59
|
+
_ariaLabel: { type: String, attribute: 'aria-label', reflect: true },
|
60
|
+
_letClickPropagate: { state: true }
|
58
61
|
};
|
59
62
|
}
|
60
63
|
|
@@ -74,6 +77,7 @@ export const MenuItemMixin = superclass => class extends PropertyRequiredMixin(s
|
|
74
77
|
this.role = 'menuitem';
|
75
78
|
/** @ignore */
|
76
79
|
this.tabindex = -1;
|
80
|
+
this._letClickPropagate = false;
|
77
81
|
}
|
78
82
|
|
79
83
|
firstUpdated(changedProperties) {
|
@@ -82,7 +86,7 @@ export const MenuItemMixin = superclass => class extends PropertyRequiredMixin(s
|
|
82
86
|
this.addEventListener('click', this.__onClick);
|
83
87
|
this.addEventListener('d2l-hierarchical-view-hide-complete', this.__onHideComplete);
|
84
88
|
this.addEventListener('dom-change', this.__onDomChange);
|
85
|
-
this.addEventListener('keydown', this.
|
89
|
+
this.addEventListener('keydown', this._onKeyDown);
|
86
90
|
|
87
91
|
this.__initializeItem();
|
88
92
|
|
@@ -152,7 +156,12 @@ export const MenuItemMixin = superclass => class extends PropertyRequiredMixin(s
|
|
152
156
|
}
|
153
157
|
|
154
158
|
__onClick(e) {
|
155
|
-
|
159
|
+
if (menuItemClickChangesEnabled) {
|
160
|
+
if (!this._letClickPropagate) e.stopPropagation();
|
161
|
+
} else { // remove this block when cleaning up GAUD-8369-menu-item-link-click-changes
|
162
|
+
e.stopPropagation();
|
163
|
+
}
|
164
|
+
|
156
165
|
this.__action();
|
157
166
|
}
|
158
167
|
|
@@ -171,7 +180,12 @@ export const MenuItemMixin = superclass => class extends PropertyRequiredMixin(s
|
|
171
180
|
this.setAttribute('tabindex', '0');
|
172
181
|
}
|
173
182
|
|
174
|
-
|
183
|
+
_onHidden() {
|
184
|
+
/** Dispatched when the visibility of the menu item changes */
|
185
|
+
this.dispatchEvent(new CustomEvent('d2l-menu-item-visibility-change', { bubbles: true, composed: true }));
|
186
|
+
}
|
187
|
+
|
188
|
+
_onKeyDown(e) {
|
175
189
|
if (e.target !== this) {
|
176
190
|
return;
|
177
191
|
}
|
@@ -188,9 +202,4 @@ export const MenuItemMixin = superclass => class extends PropertyRequiredMixin(s
|
|
188
202
|
}
|
189
203
|
}
|
190
204
|
|
191
|
-
_onHidden() {
|
192
|
-
/** Dispatched when the visibility of the menu item changes */
|
193
|
-
this.dispatchEvent(new CustomEvent('d2l-menu-item-visibility-change', { bubbles: true, composed: true }));
|
194
|
-
}
|
195
|
-
|
196
205
|
};
|
package/custom-elements.json
CHANGED
@@ -10540,43 +10540,6 @@
|
|
10540
10540
|
"name": "d2l-menu-item-link",
|
10541
10541
|
"path": "./components/menu/menu-item-link.js",
|
10542
10542
|
"description": "A menu item component used for navigating.",
|
10543
|
-
"attributes": [
|
10544
|
-
{
|
10545
|
-
"name": "download",
|
10546
|
-
"description": "Prompts the user to save the linked URL instead of navigating to it.\nMust be to a resource on the same origin.\nCan be used with or without a value, when set the value becomes the filename.",
|
10547
|
-
"type": "string"
|
10548
|
-
},
|
10549
|
-
{
|
10550
|
-
"name": "href",
|
10551
|
-
"description": "REQUIRED: The url the menu item link navigates to",
|
10552
|
-
"type": "string"
|
10553
|
-
},
|
10554
|
-
{
|
10555
|
-
"name": "target",
|
10556
|
-
"description": "Where to display the linked URL",
|
10557
|
-
"type": "string"
|
10558
|
-
}
|
10559
|
-
],
|
10560
|
-
"properties": [
|
10561
|
-
{
|
10562
|
-
"name": "download",
|
10563
|
-
"attribute": "download",
|
10564
|
-
"description": "Prompts the user to save the linked URL instead of navigating to it.\nMust be to a resource on the same origin.\nCan be used with or without a value, when set the value becomes the filename.",
|
10565
|
-
"type": "string"
|
10566
|
-
},
|
10567
|
-
{
|
10568
|
-
"name": "href",
|
10569
|
-
"attribute": "href",
|
10570
|
-
"description": "REQUIRED: The url the menu item link navigates to",
|
10571
|
-
"type": "string"
|
10572
|
-
},
|
10573
|
-
{
|
10574
|
-
"name": "target",
|
10575
|
-
"attribute": "target",
|
10576
|
-
"description": "Where to display the linked URL",
|
10577
|
-
"type": "string"
|
10578
|
-
}
|
10579
|
-
],
|
10580
10543
|
"events": [
|
10581
10544
|
{
|
10582
10545
|
"name": "click",
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@brightspace-ui/core",
|
3
|
-
"version": "3.
|
3
|
+
"version": "3.158.0",
|
4
4
|
"description": "A collection of accessible, free, open-source web components for building Brightspace applications",
|
5
5
|
"type": "module",
|
6
6
|
"repository": "https://github.com/BrightspaceUI/core.git",
|