@momentum-design/components 0.54.3 → 0.55.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/dist/browser/index.js +163 -134
- package/dist/browser/index.js.map +4 -4
- package/dist/components/popover/popover.component.d.ts +1 -0
- package/dist/components/popover/popover.component.js +9 -7
- package/dist/components/popover/popover.utils.d.ts +8 -0
- package/dist/components/popover/popover.utils.js +28 -0
- package/dist/components/toggletip/index.d.ts +9 -0
- package/dist/components/toggletip/index.js +6 -0
- package/dist/components/toggletip/toggletip.component.d.ts +66 -0
- package/dist/components/toggletip/toggletip.component.js +131 -0
- package/dist/components/toggletip/toggletip.constants.d.ts +10 -0
- package/dist/components/toggletip/toggletip.constants.js +12 -0
- package/dist/components/toggletip/toggletip.styles.d.ts +2 -0
- package/dist/components/toggletip/toggletip.styles.js +25 -0
- package/dist/components/toggletip/toggletip.types.d.ts +7 -0
- package/dist/components/toggletip/toggletip.types.js +1 -0
- package/dist/custom-elements.json +1832 -160
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/react/index.d.ts +2 -1
- package/dist/react/index.js +2 -1
- package/dist/react/toggletip/index.d.ts +44 -0
- package/dist/react/toggletip/index.js +52 -0
- package/package.json +1 -1
@@ -185,6 +185,7 @@ declare class Popover extends Popover_base {
|
|
185
185
|
ariaDescribedby: string | null;
|
186
186
|
/**
|
187
187
|
* Disable aria-expanded attribute on trigger element.
|
188
|
+
* Make sure to set this to false when the popover is interactive.
|
188
189
|
* @default false
|
189
190
|
*/
|
190
191
|
disableAriaExpanded: boolean;
|
@@ -203,6 +203,7 @@ class Popover extends FocusTrapMixin(Component) {
|
|
203
203
|
this.ariaDescribedby = null;
|
204
204
|
/**
|
205
205
|
* Disable aria-expanded attribute on trigger element.
|
206
|
+
* Make sure to set this to false when the popover is interactive.
|
206
207
|
* @default false
|
207
208
|
*/
|
208
209
|
this.disableAriaExpanded = DEFAULTS.DISABLE_ARIA_EXPANDED;
|
@@ -397,6 +398,7 @@ class Popover extends FocusTrapMixin(Component) {
|
|
397
398
|
if (changedProperties.has('visible')) {
|
398
399
|
const oldValue = changedProperties.get('visible') || false;
|
399
400
|
await this.isOpenUpdated(oldValue, this.visible);
|
401
|
+
this.utils.updateAriaExpandedAttribute();
|
400
402
|
}
|
401
403
|
if (changedProperties.has('placement')) {
|
402
404
|
this.setAttribute('placement', Object.values(POPOVER_PLACEMENT).includes(this.placement) ? this.placement : DEFAULTS.PLACEMENT);
|
@@ -425,6 +427,12 @@ class Popover extends FocusTrapMixin(Component) {
|
|
425
427
|
|| changedProperties.has('aria-labelledby')) {
|
426
428
|
this.utils.setupAccessibility();
|
427
429
|
}
|
430
|
+
if (changedProperties.has('disableAriaExpanded')) {
|
431
|
+
this.utils.updateAriaExpandedAttribute();
|
432
|
+
}
|
433
|
+
if (changedProperties.has('interactive')) {
|
434
|
+
this.utils.updateAriaHasPopupAttribute();
|
435
|
+
}
|
428
436
|
}
|
429
437
|
/**
|
430
438
|
* Handles the popover visibility change and position the popover.
|
@@ -462,12 +470,6 @@ class Popover extends FocusTrapMixin(Component) {
|
|
462
470
|
if (this.hideOnEscape) {
|
463
471
|
document.addEventListener('keydown', this.onEscapeKeydown);
|
464
472
|
}
|
465
|
-
if (!this.disableAriaExpanded) {
|
466
|
-
this.triggerElement.setAttribute('aria-expanded', 'true');
|
467
|
-
}
|
468
|
-
if (this.interactive) {
|
469
|
-
this.triggerElement.setAttribute('aria-haspopup', this.triggerElement.getAttribute('aria-haspopup') || 'dialog');
|
470
|
-
}
|
471
473
|
PopoverEventManager.onShowPopover(this);
|
472
474
|
}
|
473
475
|
else {
|
@@ -678,7 +680,7 @@ __decorate([
|
|
678
680
|
__metadata("design:type", String)
|
679
681
|
], Popover.prototype, "appendTo", void 0);
|
680
682
|
__decorate([
|
681
|
-
property({ type: String, attribute: 'close-button-aria-label' }),
|
683
|
+
property({ type: String, attribute: 'close-button-aria-label', reflect: true }),
|
682
684
|
__metadata("design:type", Object)
|
683
685
|
], Popover.prototype, "closeButtonAriaLabel", void 0);
|
684
686
|
__decorate([
|
@@ -28,6 +28,14 @@ export declare class PopoverUtils {
|
|
28
28
|
* Sets up the accessibility attributes for the popover.
|
29
29
|
*/
|
30
30
|
setupAccessibility(): void;
|
31
|
+
/**
|
32
|
+
* Updates the aria-haspopup attribute on the trigger element.
|
33
|
+
*/
|
34
|
+
updateAriaHasPopupAttribute(): void;
|
35
|
+
/**
|
36
|
+
* Updates the aria-expanded attribute on the trigger element.
|
37
|
+
*/
|
38
|
+
updateAriaExpandedAttribute(): void;
|
31
39
|
/**
|
32
40
|
* Updates the arrow style based on the arrow data and placement.
|
33
41
|
*
|
@@ -93,6 +93,7 @@ export class PopoverUtils {
|
|
93
93
|
this.popover.toggleAttribute('aria-modal', this.popover.interactive);
|
94
94
|
}
|
95
95
|
if (this.popover.interactive) {
|
96
|
+
this.popover.setAttribute('aria-modal', 'true');
|
96
97
|
if (!this.popover.ariaLabel) {
|
97
98
|
this.popover.ariaLabel = ((_a = this.popover.triggerElement) === null || _a === void 0 ? void 0 : _a.ariaLabel)
|
98
99
|
|| ((_b = this.popover.triggerElement) === null || _b === void 0 ? void 0 : _b.textContent)
|
@@ -102,6 +103,33 @@ export class PopoverUtils {
|
|
102
103
|
this.popover.ariaLabelledby = ((_c = this.popover.triggerElement) === null || _c === void 0 ? void 0 : _c.id) || '';
|
103
104
|
}
|
104
105
|
}
|
106
|
+
else {
|
107
|
+
this.popover.removeAttribute('aria-modal');
|
108
|
+
}
|
109
|
+
}
|
110
|
+
/**
|
111
|
+
* Updates the aria-haspopup attribute on the trigger element.
|
112
|
+
*/
|
113
|
+
updateAriaHasPopupAttribute() {
|
114
|
+
var _a, _b, _c;
|
115
|
+
if (this.popover.interactive) {
|
116
|
+
(_a = this.popover.triggerElement) === null || _a === void 0 ? void 0 : _a.setAttribute('aria-haspopup', ((_b = this.popover.triggerElement) === null || _b === void 0 ? void 0 : _b.getAttribute('aria-haspopup')) || 'dialog');
|
117
|
+
}
|
118
|
+
else {
|
119
|
+
(_c = this.popover.triggerElement) === null || _c === void 0 ? void 0 : _c.removeAttribute('aria-haspopup');
|
120
|
+
}
|
121
|
+
}
|
122
|
+
/**
|
123
|
+
* Updates the aria-expanded attribute on the trigger element.
|
124
|
+
*/
|
125
|
+
updateAriaExpandedAttribute() {
|
126
|
+
var _a, _b;
|
127
|
+
if (this.popover.disableAriaExpanded) {
|
128
|
+
(_a = this.popover.triggerElement) === null || _a === void 0 ? void 0 : _a.removeAttribute('aria-expanded');
|
129
|
+
}
|
130
|
+
else {
|
131
|
+
(_b = this.popover.triggerElement) === null || _b === void 0 ? void 0 : _b.setAttribute('aria-expanded', `${this.popover.visible}`);
|
132
|
+
}
|
105
133
|
}
|
106
134
|
/**
|
107
135
|
* Updates the arrow style based on the arrow data and placement.
|
@@ -0,0 +1,66 @@
|
|
1
|
+
import { CSSResult, PropertyValueMap } from 'lit';
|
2
|
+
import Popover from '../popover/popover.component';
|
3
|
+
/**
|
4
|
+
* A toggletip is triggered by clicking a trigger element.
|
5
|
+
*
|
6
|
+
* It can contain interactive content and can be closed by
|
7
|
+
* clicking outside the toggletip or pressing the escape key.
|
8
|
+
*
|
9
|
+
* It can have optional close button to close the toggletip.
|
10
|
+
*
|
11
|
+
* Toggletip component uses `mdc-screenreaderannouncer` internally to
|
12
|
+
* announce the toggletip text content with screen readers when the toggletip is shown.
|
13
|
+
*
|
14
|
+
* `screenreader-announcer-identity` attribute can be used to provide ID of an element
|
15
|
+
* in DOM to which announcement elements are added. If not set, a visually hidden
|
16
|
+
* div element is created in DOM to which announcement elements are added.
|
17
|
+
*
|
18
|
+
* Please refer to the `mdc-screenreaderannouncer` component for more details.
|
19
|
+
*
|
20
|
+
* @dependency mdc-screenreaderannouncer
|
21
|
+
* @dependency mdc-button
|
22
|
+
*
|
23
|
+
* @tagname mdc-toggletip
|
24
|
+
*
|
25
|
+
* @event shown - (React: onShown) This event is dispatched when the toggletip is shown
|
26
|
+
* @event hidden - (React: onHidden) This event is dispatched when the toggletip is hidden
|
27
|
+
* @event created - (React: onCreated) This event is dispatched when the toggletip is created (added to the DOM)
|
28
|
+
* @event destroyed - (React: onDestroyed) This event is dispatched when the toggletip
|
29
|
+
* is destroyed (removed from the DOM)
|
30
|
+
*
|
31
|
+
* @cssproperty --mdc-toggletip-max-width - The maximum width of the toggletip.
|
32
|
+
* @cssproperty --mdc-toggletip-text-color - The text color of the toggletip.
|
33
|
+
* @cssproperty --mdc-toggletip-text-color-contrast - The text color of the toggletip
|
34
|
+
* when the color is contrast.
|
35
|
+
*
|
36
|
+
* @slot - Default slot for the toggletip content
|
37
|
+
*/
|
38
|
+
declare class ToggleTip extends Popover {
|
39
|
+
private defaultSlotNodes;
|
40
|
+
/** @internal */
|
41
|
+
currentAnnouncement: string;
|
42
|
+
/**
|
43
|
+
* Set this attribute with the id of the element in the DOM, to which announcement
|
44
|
+
* elements will be appended.
|
45
|
+
* If an id is provided, the announcement elements will be appended to this element.
|
46
|
+
* If id is not provided, a visually hidden div element will be created in the DOM.
|
47
|
+
*
|
48
|
+
* Please refer to the `mdc-screenreaderannouncer` component for more details.
|
49
|
+
*/
|
50
|
+
screenreaderAnnouncerIdentity: string;
|
51
|
+
connectedCallback(): void;
|
52
|
+
/**
|
53
|
+
* @returns The text content of all the nodes in the default slot, joined by a space.
|
54
|
+
* If there are no nodes, an empty string is returned.
|
55
|
+
*/
|
56
|
+
private getToggleTipText;
|
57
|
+
/**
|
58
|
+
* Updates the placement attribute if it is not a valid placement.
|
59
|
+
* Default placement for toggle tip is top.
|
60
|
+
*/
|
61
|
+
private onPlacementUpdated;
|
62
|
+
protected update(changedProperties: PropertyValueMap<any> | Map<PropertyKey, unknown>): void;
|
63
|
+
render(): import("lit-html").TemplateResult<1>;
|
64
|
+
static styles: Array<CSSResult>;
|
65
|
+
}
|
66
|
+
export default ToggleTip;
|
@@ -0,0 +1,131 @@
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
6
|
+
};
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
9
|
+
};
|
10
|
+
import { html } from 'lit';
|
11
|
+
import { property, queryAssignedNodes, state } from 'lit/decorators.js';
|
12
|
+
import Popover from '../popover/popover.component';
|
13
|
+
import { POPOVER_PLACEMENT } from '../popover/popover.constants';
|
14
|
+
import { DEFAULTS } from './toggletip.constants';
|
15
|
+
import styles from './toggletip.styles';
|
16
|
+
/**
|
17
|
+
* A toggletip is triggered by clicking a trigger element.
|
18
|
+
*
|
19
|
+
* It can contain interactive content and can be closed by
|
20
|
+
* clicking outside the toggletip or pressing the escape key.
|
21
|
+
*
|
22
|
+
* It can have optional close button to close the toggletip.
|
23
|
+
*
|
24
|
+
* Toggletip component uses `mdc-screenreaderannouncer` internally to
|
25
|
+
* announce the toggletip text content with screen readers when the toggletip is shown.
|
26
|
+
*
|
27
|
+
* `screenreader-announcer-identity` attribute can be used to provide ID of an element
|
28
|
+
* in DOM to which announcement elements are added. If not set, a visually hidden
|
29
|
+
* div element is created in DOM to which announcement elements are added.
|
30
|
+
*
|
31
|
+
* Please refer to the `mdc-screenreaderannouncer` component for more details.
|
32
|
+
*
|
33
|
+
* @dependency mdc-screenreaderannouncer
|
34
|
+
* @dependency mdc-button
|
35
|
+
*
|
36
|
+
* @tagname mdc-toggletip
|
37
|
+
*
|
38
|
+
* @event shown - (React: onShown) This event is dispatched when the toggletip is shown
|
39
|
+
* @event hidden - (React: onHidden) This event is dispatched when the toggletip is hidden
|
40
|
+
* @event created - (React: onCreated) This event is dispatched when the toggletip is created (added to the DOM)
|
41
|
+
* @event destroyed - (React: onDestroyed) This event is dispatched when the toggletip
|
42
|
+
* is destroyed (removed from the DOM)
|
43
|
+
*
|
44
|
+
* @cssproperty --mdc-toggletip-max-width - The maximum width of the toggletip.
|
45
|
+
* @cssproperty --mdc-toggletip-text-color - The text color of the toggletip.
|
46
|
+
* @cssproperty --mdc-toggletip-text-color-contrast - The text color of the toggletip
|
47
|
+
* when the color is contrast.
|
48
|
+
*
|
49
|
+
* @slot - Default slot for the toggletip content
|
50
|
+
*/
|
51
|
+
class ToggleTip extends Popover {
|
52
|
+
constructor() {
|
53
|
+
super(...arguments);
|
54
|
+
/** @internal */
|
55
|
+
this.currentAnnouncement = '';
|
56
|
+
/**
|
57
|
+
* Set this attribute with the id of the element in the DOM, to which announcement
|
58
|
+
* elements will be appended.
|
59
|
+
* If an id is provided, the announcement elements will be appended to this element.
|
60
|
+
* If id is not provided, a visually hidden div element will be created in the DOM.
|
61
|
+
*
|
62
|
+
* Please refer to the `mdc-screenreaderannouncer` component for more details.
|
63
|
+
*/
|
64
|
+
this.screenreaderAnnouncerIdentity = '';
|
65
|
+
}
|
66
|
+
connectedCallback() {
|
67
|
+
super.connectedCallback();
|
68
|
+
this.closeButton = DEFAULTS.CLOSE_BUTTON;
|
69
|
+
this.closeButtonAriaLabel = DEFAULTS.CLOSE_BUTTON_ARIA_LABEL;
|
70
|
+
this.placement = DEFAULTS.PLACEMENT;
|
71
|
+
this.trigger = DEFAULTS.CLICK;
|
72
|
+
this.showArrow = DEFAULTS.SHOW_ARROW;
|
73
|
+
this.interactive = true;
|
74
|
+
this.backdrop = true;
|
75
|
+
this.hideOnBlur = true;
|
76
|
+
this.hideOnEscape = true;
|
77
|
+
this.hideOnOutsideClick = true;
|
78
|
+
this.disableAriaExpanded = false;
|
79
|
+
this.focusBackToTrigger = true;
|
80
|
+
}
|
81
|
+
/**
|
82
|
+
* @returns The text content of all the nodes in the default slot, joined by a space.
|
83
|
+
* If there are no nodes, an empty string is returned.
|
84
|
+
*/
|
85
|
+
getToggleTipText() {
|
86
|
+
var _a, _b;
|
87
|
+
return ((_b = (_a = this.defaultSlotNodes) === null || _a === void 0 ? void 0 : _a.map((node) => node.textContent).join(' ')) === null || _b === void 0 ? void 0 : _b.trim()) || '';
|
88
|
+
}
|
89
|
+
/**
|
90
|
+
* Updates the placement attribute if it is not a valid placement.
|
91
|
+
* Default placement for toggle tip is top.
|
92
|
+
*/
|
93
|
+
onPlacementUpdated() {
|
94
|
+
if (!Object.values(POPOVER_PLACEMENT).includes(this.placement)) {
|
95
|
+
this.placement = DEFAULTS.PLACEMENT;
|
96
|
+
}
|
97
|
+
}
|
98
|
+
update(changedProperties) {
|
99
|
+
super.update(changedProperties);
|
100
|
+
if (changedProperties.has('placement')) {
|
101
|
+
this.onPlacementUpdated();
|
102
|
+
}
|
103
|
+
if (changedProperties.has('visible')) {
|
104
|
+
this.currentAnnouncement = this.visible ? this.getToggleTipText() : '';
|
105
|
+
}
|
106
|
+
}
|
107
|
+
render() {
|
108
|
+
return html `
|
109
|
+
${super.render()}
|
110
|
+
<mdc-screenreaderannouncer
|
111
|
+
identity="${this.screenreaderAnnouncerIdentity}"
|
112
|
+
announcement="${this.currentAnnouncement}"
|
113
|
+
delay="300">
|
114
|
+
</mdc-screenreaderannouncer>
|
115
|
+
`;
|
116
|
+
}
|
117
|
+
}
|
118
|
+
ToggleTip.styles = [...Popover.styles, ...styles];
|
119
|
+
__decorate([
|
120
|
+
queryAssignedNodes(),
|
121
|
+
__metadata("design:type", Array)
|
122
|
+
], ToggleTip.prototype, "defaultSlotNodes", void 0);
|
123
|
+
__decorate([
|
124
|
+
state(),
|
125
|
+
__metadata("design:type", Object)
|
126
|
+
], ToggleTip.prototype, "currentAnnouncement", void 0);
|
127
|
+
__decorate([
|
128
|
+
property({ type: String, reflect: true, attribute: 'screenreader-announcer-identity' }),
|
129
|
+
__metadata("design:type", Object)
|
130
|
+
], ToggleTip.prototype, "screenreaderAnnouncerIdentity", void 0);
|
131
|
+
export default ToggleTip;
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import utils from '../../utils/tag-name';
|
2
|
+
import { POPOVER_PLACEMENT, TRIGGER } from '../popover/popover.constants';
|
3
|
+
const TAG_NAME = utils.constructTagName('toggletip');
|
4
|
+
const DEFAULTS = {
|
5
|
+
CLOSE_BUTTON: true,
|
6
|
+
CLOSE_BUTTON_ARIA_LABEL: 'Close',
|
7
|
+
OFFSET: 4,
|
8
|
+
PLACEMENT: POPOVER_PLACEMENT.TOP,
|
9
|
+
CLICK: TRIGGER.CLICK,
|
10
|
+
SHOW_ARROW: true,
|
11
|
+
};
|
12
|
+
export { DEFAULTS, TAG_NAME };
|
@@ -0,0 +1,25 @@
|
|
1
|
+
import { css } from 'lit';
|
2
|
+
const styles = css `
|
3
|
+
:host {
|
4
|
+
--mdc-toggletip-max-width: 400px;
|
5
|
+
--mdc-toggletip-text-color: var(--mds-color-theme-text-primary-normal);
|
6
|
+
--mdc-toggletip-text-color-contrast: var(--mds-color-theme-inverted-text-primary-normal);
|
7
|
+
}
|
8
|
+
|
9
|
+
:host::part(popover-content) {
|
10
|
+
color: var(--mdc-toggletip-text-color);
|
11
|
+
min-width: fit-content;
|
12
|
+
max-width: var(--mdc-toggletip-max-width);
|
13
|
+
|
14
|
+
font-size: var(--mds-font-apps-body-midsize-regular-font-size);
|
15
|
+
font-weight: var(--mds-font-apps-body-midsize-regular-font-weight);
|
16
|
+
line-height: var(--mds-font-apps-body-midsize-regular-line-height);
|
17
|
+
text-decoration: var(--mds-font-apps-body-midsize-regular-text-decoration);
|
18
|
+
text-transform: var(--mds-font-apps-body-midsize-regular-text-case);
|
19
|
+
}
|
20
|
+
|
21
|
+
:host([color='contrast'])::part(popover-content) {
|
22
|
+
color: var(--mdc-toggletip-text-color-contrast);
|
23
|
+
}
|
24
|
+
`;
|
25
|
+
export default [styles];
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|