@brightspace-ui/core 3.153.4 → 3.154.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.
- package/components/dialog/demo/dialog.html +34 -0
- package/components/dialog/dialog-mixin.js +4 -10
- package/helpers/README.md +8 -2
- package/helpers/dom.js +14 -3
- package/helpers/focus.js +19 -6
- package/package.json +1 -1
@@ -12,11 +12,15 @@
|
|
12
12
|
import '../../button/button.js';
|
13
13
|
import '../../dropdown/dropdown-button-subtle.js';
|
14
14
|
import '../../dropdown/dropdown-content.js';
|
15
|
+
import '../../dropdown/dropdown.js';
|
16
|
+
import '../../dropdown/dropdown-menu.js';
|
15
17
|
import '../../filter/filter.js';
|
16
18
|
import '../../filter/filter-dimension-set.js';
|
17
19
|
import '../../filter/filter-dimension-set-value.js';
|
18
20
|
import '../../inputs/input-checkbox.js';
|
19
21
|
import '../../list/demo/demo-list.js';
|
22
|
+
import '../../menu/menu.js';
|
23
|
+
import '../../menu/menu-item.js';
|
20
24
|
import '../dialog.js';
|
21
25
|
import './dialog-async-content.js';
|
22
26
|
import './dialog-async-content-until.js';
|
@@ -82,6 +86,36 @@
|
|
82
86
|
</template>
|
83
87
|
</d2l-demo-snippet>
|
84
88
|
|
89
|
+
<h2>Dialog with complex opener</h2>
|
90
|
+
|
91
|
+
<d2l-demo-snippet>
|
92
|
+
<template>
|
93
|
+
<d2l-dropdown>
|
94
|
+
<button class="d2l-dropdown-opener">Open it!</button>
|
95
|
+
<d2l-dropdown-menu id="dropdown">
|
96
|
+
<d2l-menu label="Astronomy">
|
97
|
+
<d2l-menu-item id="complex-opener" text="Open dialog"></d2l-menu-item>
|
98
|
+
<d2l-menu-item text="Item 2"></d2l-menu-item>
|
99
|
+
<d2l-menu-item text="Item 3"></d2l-menu-item>
|
100
|
+
<d2l-menu-item text="Item 4"></d2l-menu-item>
|
101
|
+
</d2l-menu>
|
102
|
+
</d2l-dropdown-menu>
|
103
|
+
</d2l-dropdown>
|
104
|
+
<d2l-dialog id="complex-opener-dialog" title-text="Dialog Title">
|
105
|
+
<div>
|
106
|
+
Hello
|
107
|
+
</div>
|
108
|
+
<d2l-button slot="footer" primary data-dialog-action="ok">Click Me!</d2l-button>
|
109
|
+
<d2l-button slot="footer" data-dialog-action>Cancel</d2l-button>
|
110
|
+
</d2l-dialog>
|
111
|
+
<script>
|
112
|
+
document.querySelector('#complex-opener').addEventListener('d2l-menu-item-select', () => {
|
113
|
+
document.querySelector('#complex-opener-dialog').opened = true;
|
114
|
+
});
|
115
|
+
</script>
|
116
|
+
</template>
|
117
|
+
</d2l-demo-snippet>
|
118
|
+
|
85
119
|
<h2>Dialog (with promise)</h2>
|
86
120
|
|
87
121
|
<d2l-demo-snippet>
|
@@ -3,7 +3,7 @@ import '../../helpers/viewport-size.js';
|
|
3
3
|
import { allowBodyScroll, preventBodyScroll } from '../backdrop/backdrop.js';
|
4
4
|
import { clearDismissible, setDismissible } from '../../helpers/dismissible.js';
|
5
5
|
import { findComposedAncestor, getComposedChildren, isComposedAncestor } from '../../helpers/dom.js';
|
6
|
-
import { getComposedActiveElement, getFirstFocusableDescendant, getNextFocusable, isFocusable } from '../../helpers/focus.js';
|
6
|
+
import { getComposedActiveElement, getFirstFocusableDescendant, getFirstFocusableRelative, getNextFocusable, isFocusable } from '../../helpers/focus.js';
|
7
7
|
import { classMap } from 'lit/directives/class-map.js';
|
8
8
|
import { getUniqueId } from '../../helpers/uniqueId.js';
|
9
9
|
import { html } from 'lit';
|
@@ -530,15 +530,9 @@ export const DialogMixin = superclass => class extends RtlMixin(superclass) {
|
|
530
530
|
|
531
531
|
}
|
532
532
|
|
533
|
-
_tryApplyFocus(
|
534
|
-
|
535
|
-
|
536
|
-
if (focusable === null) return;
|
537
|
-
if (!isFocusable(focusable)) {
|
538
|
-
focusable = getFirstFocusableDescendant(focusable);
|
539
|
-
}
|
540
|
-
}
|
541
|
-
if (isFocusable(focusable)) focusable.focus();
|
533
|
+
_tryApplyFocus(node) {
|
534
|
+
const focusable = getFirstFocusableRelative(node);
|
535
|
+
if (focusable) focusable.focus();
|
542
536
|
}
|
543
537
|
|
544
538
|
_updateFocusableContentElemPresent() {
|
package/helpers/README.md
CHANGED
@@ -107,7 +107,10 @@ getOffsetParent(node);
|
|
107
107
|
isComposedAncestor(ancestorNode, node);
|
108
108
|
|
109
109
|
// returns true/false whether the element is visible regardless of positioning
|
110
|
-
isVisible(node);
|
110
|
+
isVisible(node, { checkAncestors: true });
|
111
|
+
|
112
|
+
// returns the first visible ancestor of the given node
|
113
|
+
getFirstVisibleAncestor(node)
|
111
114
|
|
112
115
|
// similar to document.querySelector or element.querySelector,
|
113
116
|
// except it queries not just the light DOM but also shadow DOM
|
@@ -125,7 +128,10 @@ import { ... } from '@brightspace-ui/core/helpers/focus.js';
|
|
125
128
|
getComposedActiveElement()
|
126
129
|
|
127
130
|
// gets the first focusable descendant given a node, including those within the shadow DOM
|
128
|
-
getFirstFocusableDescendant(node, includeHidden, predicate, includeTabbablesOnly)
|
131
|
+
getFirstFocusableDescendant(node, includeHidden, predicate, includeTabbablesOnly, checkNodeVisibility = true)
|
132
|
+
|
133
|
+
// gets the first focusable relative given a node, checking first itself, its children, and lastly, recursively its parent
|
134
|
+
getFirstFocusableRelative(node, { includeHidden, predicate, includeTabbablesOnly, checkNodeVisibility: true })
|
129
135
|
|
130
136
|
// gets the focusable elements within the specified element
|
131
137
|
getFocusableDescendants(node, { deep: false, disabled: false, hidden: false, predicate: elem => false, tabbablesOnly: true })
|
package/helpers/dom.js
CHANGED
@@ -206,7 +206,7 @@ export function isComposedAncestor(ancestorNode, node) {
|
|
206
206
|
}) !== null;
|
207
207
|
}
|
208
208
|
|
209
|
-
export function isVisible(node) {
|
209
|
+
export function isVisible(node, { checkAncestors = true } = {}) {
|
210
210
|
|
211
211
|
/* this helper is different from checking offsetParent because offsetParent
|
212
212
|
returns null for fixed position elements regardless of visibility */
|
@@ -223,13 +223,24 @@ export function isVisible(node) {
|
|
223
223
|
if (computedStyle.getPropertyValue('visibility') === 'hidden') return false;
|
224
224
|
}
|
225
225
|
|
226
|
-
|
227
|
-
|
226
|
+
if (checkAncestors) {
|
227
|
+
const parentNode = getComposedParent(node);
|
228
|
+
if (parentNode) return isVisible(parentNode);
|
229
|
+
}
|
228
230
|
|
229
231
|
return true;
|
230
232
|
|
231
233
|
}
|
232
234
|
|
235
|
+
export function getFirstVisibleAncestor(node) {
|
236
|
+
let hiddenAncestor = findComposedAncestor(node, n => !isVisible(n, { checkAncestors: false }));
|
237
|
+
while (hiddenAncestor) {
|
238
|
+
node = getComposedParent(hiddenAncestor);
|
239
|
+
hiddenAncestor = findComposedAncestor(node, n => !isVisible(n, { checkAncestors: false }));
|
240
|
+
}
|
241
|
+
return node;
|
242
|
+
}
|
243
|
+
|
233
244
|
export function querySelectorComposed(node, selector) {
|
234
245
|
|
235
246
|
if (!node || (node.nodeType !== 1 && node.nodeType !== 9 && node.nodeType !== 11)) {
|
package/helpers/focus.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import { css, unsafeCSS } from 'lit';
|
2
|
-
import { getComposedChildren, getComposedParent, getNextAncestorSibling, getPreviousAncestorSibling, isVisible } from './dom.js';
|
2
|
+
import { getComposedChildren, getComposedParent, getFirstVisibleAncestor, getNextAncestorSibling, getPreviousAncestorSibling, isVisible } from './dom.js';
|
3
3
|
|
4
4
|
const focusableElements = {
|
5
5
|
a: true,
|
@@ -26,21 +26,34 @@ export function getComposedActiveElement() {
|
|
26
26
|
return node;
|
27
27
|
}
|
28
28
|
|
29
|
-
export function getFirstFocusableDescendant(node, includeHidden, predicate, includeTabbablesOnly) {
|
30
|
-
if (predicate === undefined) predicate = () => true;
|
31
|
-
|
29
|
+
export function getFirstFocusableDescendant(node, includeHidden, predicate = () => true, includeTabbablesOnly, nodeVisibilityUnknown = true) {
|
32
30
|
const composedChildren = getComposedChildren(node);
|
31
|
+
if (!composedChildren?.length || (!includeHidden && nodeVisibilityUnknown && !isVisible(node))) return null;
|
33
32
|
|
34
33
|
for (let i = 0; i < composedChildren.length; i++) {
|
35
|
-
if (
|
34
|
+
if (!includeHidden && !isVisible(composedChildren[i], { checkAncestors: false })) continue;
|
35
|
+
if (isFocusable(composedChildren[i], true, includeTabbablesOnly) && predicate(composedChildren[i])) return composedChildren[i];
|
36
36
|
|
37
|
-
const focusable = getFirstFocusableDescendant(composedChildren[i], includeHidden, predicate, includeTabbablesOnly);
|
37
|
+
const focusable = getFirstFocusableDescendant(composedChildren[i], includeHidden, predicate, includeTabbablesOnly, false);
|
38
38
|
if (focusable) return focusable;
|
39
39
|
}
|
40
40
|
|
41
41
|
return null;
|
42
42
|
}
|
43
43
|
|
44
|
+
export function getFirstFocusableRelative(node, { includeHidden, predicate = () => true, includeTabbablesOnly, nodeVisibilityUnknown = true } = {}) {
|
45
|
+
if (!node) return null;
|
46
|
+
|
47
|
+
if (!includeHidden && nodeVisibilityUnknown) node = getFirstVisibleAncestor(node);
|
48
|
+
|
49
|
+
if (isFocusable(node, true) && predicate(node)) return node;
|
50
|
+
|
51
|
+
const focusableDescendant = getFirstFocusableDescendant(node, includeHidden, predicate, includeTabbablesOnly, false);
|
52
|
+
if (focusableDescendant !== null) return focusableDescendant;
|
53
|
+
|
54
|
+
return getFirstFocusableRelative(getComposedParent(node), { includeHidden, predicate, includeTabbablesOnly, nodeVisibilityUnknown: false });
|
55
|
+
}
|
56
|
+
|
44
57
|
export function getFocusableDescendants(node, options) {
|
45
58
|
let focusables = [];
|
46
59
|
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@brightspace-ui/core",
|
3
|
-
"version": "3.
|
3
|
+
"version": "3.154.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",
|