@momentum-design/components 0.81.0 → 0.81.1
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/dist/browser/index.js +81 -81
- package/dist/browser/index.js.map +3 -3
- package/dist/components/dialog/dialog.component.d.ts +49 -21
- package/dist/components/dialog/dialog.component.js +143 -93
- package/dist/components/dialog/dialog.constants.d.ts +1 -0
- package/dist/components/dialog/dialog.constants.js +1 -0
- package/dist/components/popover/popover.component.d.ts +8 -1
- package/dist/components/popover/popover.component.js +16 -4
- package/dist/components/popover/popover.constants.d.ts +1 -0
- package/dist/components/popover/popover.constants.js +1 -0
- package/dist/components/popover/popover.utils.js +1 -1
- package/dist/components/toggletip/toggletip.component.js +1 -0
- package/dist/components/tooltip/tooltip.component.js +0 -2
- package/dist/custom-elements.json +2216 -2008
- package/dist/react/index.d.ts +3 -3
- package/dist/react/index.js +3 -3
- package/dist/utils/mixins/FocusTrapMixin.d.ts +6 -5
- package/dist/utils/mixins/FocusTrapMixin.js +51 -22
- package/package.json +1 -1
package/dist/react/index.d.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
export { default as Appheader } from './appheader';
|
2
1
|
export { default as AlertChip } from './alertchip';
|
3
2
|
export { default as Animation } from './animation';
|
3
|
+
export { default as Appheader } from './appheader';
|
4
4
|
export { default as Avatar } from './avatar';
|
5
5
|
export { default as AvatarButton } from './avatarbutton';
|
6
6
|
export { default as Badge } from './badge';
|
@@ -12,14 +12,15 @@ export { default as ButtonLink } from './buttonlink';
|
|
12
12
|
export { default as Buttonsimple } from './buttonsimple';
|
13
13
|
export { default as Card } from './card';
|
14
14
|
export { default as CardButton } from './cardbutton';
|
15
|
+
export { default as CardCheckbox } from './cardcheckbox';
|
15
16
|
export { default as CardRadio } from './cardradio';
|
16
17
|
export { default as Checkbox } from './checkbox';
|
17
18
|
export { default as Chip } from './chip';
|
18
|
-
export { default as CardCheckbox } from './cardcheckbox';
|
19
19
|
export { default as Coachmark } from './coachmark';
|
20
20
|
export { default as Dialog } from './dialog';
|
21
21
|
export { default as Divider } from './divider';
|
22
22
|
export { default as FilterChip } from './filterchip';
|
23
|
+
export { default as FormfieldGroup } from './formfieldgroup';
|
23
24
|
export { default as FormfieldWrapper } from './formfieldwrapper';
|
24
25
|
export { default as Icon } from './icon';
|
25
26
|
export { default as IconProvider } from './iconprovider';
|
@@ -29,7 +30,6 @@ export { default as Link } from './link';
|
|
29
30
|
export { default as Linksimple } from './linksimple';
|
30
31
|
export { default as List } from './list';
|
31
32
|
export { default as ListItem } from './listitem';
|
32
|
-
export { default as FormfieldGroup } from './formfieldgroup';
|
33
33
|
export { default as Marker } from './marker';
|
34
34
|
export { default as Menu } from './menu';
|
35
35
|
export { default as MenuBar } from './menubar';
|
package/dist/react/index.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
export { default as Appheader } from './appheader';
|
2
1
|
export { default as AlertChip } from './alertchip';
|
3
2
|
export { default as Animation } from './animation';
|
3
|
+
export { default as Appheader } from './appheader';
|
4
4
|
export { default as Avatar } from './avatar';
|
5
5
|
export { default as AvatarButton } from './avatarbutton';
|
6
6
|
export { default as Badge } from './badge';
|
@@ -12,14 +12,15 @@ export { default as ButtonLink } from './buttonlink';
|
|
12
12
|
export { default as Buttonsimple } from './buttonsimple';
|
13
13
|
export { default as Card } from './card';
|
14
14
|
export { default as CardButton } from './cardbutton';
|
15
|
+
export { default as CardCheckbox } from './cardcheckbox';
|
15
16
|
export { default as CardRadio } from './cardradio';
|
16
17
|
export { default as Checkbox } from './checkbox';
|
17
18
|
export { default as Chip } from './chip';
|
18
|
-
export { default as CardCheckbox } from './cardcheckbox';
|
19
19
|
export { default as Coachmark } from './coachmark';
|
20
20
|
export { default as Dialog } from './dialog';
|
21
21
|
export { default as Divider } from './divider';
|
22
22
|
export { default as FilterChip } from './filterchip';
|
23
|
+
export { default as FormfieldGroup } from './formfieldgroup';
|
23
24
|
export { default as FormfieldWrapper } from './formfieldwrapper';
|
24
25
|
export { default as Icon } from './icon';
|
25
26
|
export { default as IconProvider } from './iconprovider';
|
@@ -29,7 +30,6 @@ export { default as Link } from './link';
|
|
29
30
|
export { default as Linksimple } from './linksimple';
|
30
31
|
export { default as List } from './list';
|
31
32
|
export { default as ListItem } from './listitem';
|
32
|
-
export { default as FormfieldGroup } from './formfieldgroup';
|
33
33
|
export { default as Marker } from './marker';
|
34
34
|
export { default as Menu } from './menu';
|
35
35
|
export { default as MenuBar } from './menubar';
|
@@ -1,9 +1,10 @@
|
|
1
|
+
import type { Component } from '../../models';
|
1
2
|
import type { Constructor } from './index.types';
|
2
|
-
export declare class FocusTrapClassInterface {
|
3
|
-
|
3
|
+
export declare abstract class FocusTrapClassInterface {
|
4
|
+
protected abstract focusTrap: boolean;
|
4
5
|
enabledPreventScroll: boolean;
|
5
|
-
|
6
|
-
|
6
|
+
setInitialFocus(elementIndexToReceiveFocus?: number): void;
|
7
|
+
activateFocusTrap(): void;
|
7
8
|
deactivateFocusTrap(): void;
|
8
9
|
}
|
9
|
-
export declare const FocusTrapMixin: <T extends Constructor<
|
10
|
+
export declare const FocusTrapMixin: <T extends Constructor<Component>>(superClass: T) => Constructor<HTMLElement & FocusTrapClassInterface> & T;
|
@@ -11,14 +11,16 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
11
11
|
import { property } from 'lit/decorators.js';
|
12
12
|
export const FocusTrapMixin = (superClass) => {
|
13
13
|
class FocusTrap extends superClass {
|
14
|
-
constructor(
|
15
|
-
super(...
|
14
|
+
constructor() {
|
15
|
+
super(...arguments);
|
16
16
|
/**
|
17
|
-
* Determines whether the
|
18
|
-
* If true, focus will
|
19
|
-
*
|
17
|
+
* Determines whether focus should wrap around when reaching the first or last focusable element.
|
18
|
+
* If true, focus will cycle from end to start and vice versa.
|
19
|
+
*
|
20
|
+
* This only applies when `enabledFocusTrap` is true.
|
21
|
+
* @default true
|
20
22
|
*/
|
21
|
-
this.
|
23
|
+
this.shouldFocusTrapWrap = true;
|
22
24
|
/**
|
23
25
|
* Prevent outside scrolling when element is shown.
|
24
26
|
* @default false
|
@@ -28,16 +30,43 @@ export const FocusTrapMixin = (superClass) => {
|
|
28
30
|
this.focusTrapIndex = -1;
|
29
31
|
/** @internal */
|
30
32
|
this.focusableElements = [];
|
31
|
-
|
32
|
-
this.
|
33
|
+
/** @internal */
|
34
|
+
this.isFocusTrapActivated = false;
|
35
|
+
}
|
36
|
+
connectedCallback() {
|
37
|
+
super.connectedCallback();
|
38
|
+
document.addEventListener('keydown', this.handleTabKeydown.bind(this));
|
39
|
+
}
|
40
|
+
disconnectedCallback() {
|
41
|
+
super.disconnectedCallback();
|
42
|
+
document.removeEventListener('keydown', this.handleTabKeydown.bind(this));
|
43
|
+
}
|
44
|
+
async updated(changedProperties) {
|
45
|
+
super.updated(changedProperties);
|
46
|
+
if (changedProperties.has('focusTrap')) {
|
47
|
+
if (!this.focusTrap) {
|
48
|
+
this.deactivateFocusTrap();
|
49
|
+
}
|
50
|
+
}
|
51
|
+
}
|
52
|
+
/**
|
53
|
+
* Activate the focus trap
|
54
|
+
* This calculates the focusable elements within the component's shadow root
|
55
|
+
*/
|
56
|
+
activateFocusTrap() {
|
57
|
+
if (this.focusTrap) {
|
58
|
+
this.isFocusTrapActivated = true;
|
59
|
+
this.setFocusableElements();
|
60
|
+
}
|
33
61
|
}
|
34
62
|
/**
|
35
63
|
* Deactivate the focus trap.
|
36
64
|
*/
|
37
65
|
deactivateFocusTrap() {
|
38
|
-
this.
|
39
|
-
this.enabledPreventScroll = false;
|
66
|
+
this.isFocusTrapActivated = false;
|
40
67
|
this.focusTrapIndex = -1;
|
68
|
+
// todo: this should not override the body overflow style, but reset it instead
|
69
|
+
this.enabledPreventScroll = false;
|
41
70
|
document.body.style.overflow = '';
|
42
71
|
}
|
43
72
|
/**
|
@@ -198,17 +227,17 @@ export const FocusTrapMixin = (superClass) => {
|
|
198
227
|
/**
|
199
228
|
* Sets the initial focus within the container.
|
200
229
|
*
|
201
|
-
* @param
|
230
|
+
* @param elementIndexToReceiveFocus - The index of the preferable element to focus.
|
202
231
|
*/
|
203
|
-
setInitialFocus(
|
232
|
+
setInitialFocus(elementIndexToReceiveFocus = 0) {
|
204
233
|
if (this.focusableElements.length === 0)
|
205
234
|
return;
|
206
235
|
if (this.enabledPreventScroll) {
|
207
236
|
document.body.style.overflow = 'hidden';
|
208
237
|
}
|
209
|
-
if (this.focusableElements[
|
210
|
-
this.focusTrapIndex =
|
211
|
-
this.focusableElements[
|
238
|
+
if (this.focusableElements[elementIndexToReceiveFocus]) {
|
239
|
+
this.focusTrapIndex = elementIndexToReceiveFocus;
|
240
|
+
this.focusableElements[elementIndexToReceiveFocus].focus();
|
212
241
|
}
|
213
242
|
}
|
214
243
|
/**
|
@@ -220,12 +249,11 @@ export const FocusTrapMixin = (superClass) => {
|
|
220
249
|
*/
|
221
250
|
calculateNextIndex(currentIndex, step) {
|
222
251
|
const { length } = this.focusableElements;
|
223
|
-
const wrapFocus = this.shouldWrapFocus();
|
224
252
|
if (currentIndex === -1) {
|
225
253
|
return step > 0 ? 0 : length - 1;
|
226
254
|
}
|
227
255
|
let nextIndex = currentIndex + step;
|
228
|
-
if (
|
256
|
+
if (this.shouldFocusTrapWrap) {
|
229
257
|
if (nextIndex < 0)
|
230
258
|
nextIndex = length - 1;
|
231
259
|
if (nextIndex >= length)
|
@@ -281,8 +309,9 @@ export const FocusTrapMixin = (superClass) => {
|
|
281
309
|
* If true, the focus will be trapped in the previous element.
|
282
310
|
*/
|
283
311
|
trapFocus(direction) {
|
284
|
-
if (this.focusableElements.length === 0)
|
312
|
+
if (this.focusableElements.length === 0) {
|
285
313
|
return;
|
314
|
+
}
|
286
315
|
const activeElement = this.getDeepActiveElement();
|
287
316
|
const activeIndex = this.findElement(activeElement);
|
288
317
|
if (direction) {
|
@@ -301,8 +330,8 @@ export const FocusTrapMixin = (superClass) => {
|
|
301
330
|
*
|
302
331
|
* @param event - The keyboard event.
|
303
332
|
*/
|
304
|
-
|
305
|
-
if (!this.
|
333
|
+
handleTabKeydown(event) {
|
334
|
+
if (!this.isFocusTrapActivated || !this.focusableElements.length) {
|
306
335
|
return;
|
307
336
|
}
|
308
337
|
if (event.key === 'Tab') {
|
@@ -312,9 +341,9 @@ export const FocusTrapMixin = (superClass) => {
|
|
312
341
|
}
|
313
342
|
}
|
314
343
|
__decorate([
|
315
|
-
property({ type: Boolean }),
|
344
|
+
property({ type: Boolean, reflect: true, attribute: 'should-focus-trap-wrap' }),
|
316
345
|
__metadata("design:type", Boolean)
|
317
|
-
], FocusTrap.prototype, "
|
346
|
+
], FocusTrap.prototype, "shouldFocusTrapWrap", void 0);
|
318
347
|
__decorate([
|
319
348
|
property({ type: Boolean }),
|
320
349
|
__metadata("design:type", Boolean)
|
package/package.json
CHANGED