@brightspace-ui/core 2.29.4 → 2.30.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/README.md +10 -0
- package/components/dialog/dialog-mixin.js +25 -3
- package/components/tooltip/tooltip-help.js +0 -1
- package/helpers/demo/prism.html +2128 -47
- package/helpers/focus.js +2 -2
- package/helpers/prism.js +113 -68
- package/package.json +1 -1
|
@@ -256,6 +256,16 @@ document.querySelector('#open').addEventListener('click', () => {
|
|
|
256
256
|
});
|
|
257
257
|
```
|
|
258
258
|
|
|
259
|
+
## Focus Management
|
|
260
|
+
|
|
261
|
+
When opened, focus will be automatically placed within the dialog. The element to be focused will either be the content element having the optional `autofocus` attribute, or a focusable element identified by the dialog depending on the type of dialog. For `d2l-dialog` and `d2l-dialog-fullscreen`, the first focusable element will be focused. For `d2l-dialog-confirm`, the least destructive action will be focused, which is assumed to be the first non-primary button in the footer.
|
|
262
|
+
|
|
263
|
+
### Specifying an `autofocus` Element (Optional)
|
|
264
|
+
|
|
265
|
+
To specify which element should be focused, add the `autofocus` attribute to that element. An element with the `autofocus` attribute will receive focus if the element has a `tabindex` value of `0` or `-1`, or is a naturally focusable element (e.g. button).
|
|
266
|
+
|
|
267
|
+
Note that the element must be in the dialog content's DOM scope and not within another component's Shadow DOM.
|
|
268
|
+
|
|
259
269
|
<!-- docs: start hidden content -->
|
|
260
270
|
## Future Improvements
|
|
261
271
|
|
|
@@ -177,13 +177,35 @@ export const DialogMixin = superclass => class extends RtlMixin(superclass) {
|
|
|
177
177
|
}
|
|
178
178
|
}
|
|
179
179
|
|
|
180
|
+
_findAutofocusElement(node) {
|
|
181
|
+
if (this._useNative) {
|
|
182
|
+
// Do not override native autofocus attribute implementation
|
|
183
|
+
return null;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
const slot = node.querySelector('slot');
|
|
187
|
+
if (!slot) {
|
|
188
|
+
// We are in a confirm dialog, autofocus attribute will never be set
|
|
189
|
+
return null;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
const content = slot.assignedElements({ flatten: true });
|
|
193
|
+
|
|
194
|
+
let autofocusElement = null;
|
|
195
|
+
for (const el of content) {
|
|
196
|
+
autofocusElement = el.hasAttribute('autofocus') ? el : el.querySelector('[autofocus]');
|
|
197
|
+
if (autofocusElement) break;
|
|
198
|
+
}
|
|
199
|
+
return autofocusElement;
|
|
200
|
+
}
|
|
201
|
+
|
|
180
202
|
_focusFirst() {
|
|
181
203
|
if (!this.shadowRoot) return;
|
|
182
204
|
const content = this.shadowRoot.querySelector('.d2l-dialog-content');
|
|
183
205
|
if (content) {
|
|
184
|
-
const
|
|
185
|
-
if (isComposedAncestor(this.shadowRoot.querySelector('.d2l-dialog-inner'),
|
|
186
|
-
forceFocusVisible(
|
|
206
|
+
const elementToFocus = this._findAutofocusElement(content) ?? getNextFocusable(content);
|
|
207
|
+
if (isComposedAncestor(this.shadowRoot.querySelector('.d2l-dialog-inner'), elementToFocus)) {
|
|
208
|
+
forceFocusVisible(elementToFocus, false);
|
|
187
209
|
return;
|
|
188
210
|
}
|
|
189
211
|
}
|
|
@@ -50,7 +50,6 @@ class TooltipHelp extends FocusMixin(FocusVisiblePolyfillMixin(LitElement)) {
|
|
|
50
50
|
border: none;
|
|
51
51
|
cursor: text;
|
|
52
52
|
padding: 0;
|
|
53
|
-
text-decoration-color: var(--d2l-color-galena);
|
|
54
53
|
text-decoration-line: underline;
|
|
55
54
|
text-decoration-style: dashed;
|
|
56
55
|
text-decoration-thickness: 1px;
|