@momentum-design/components 0.134.3 → 0.134.5
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 +261 -251
- package/dist/browser/index.js.map +3 -3
- package/dist/components/screenreaderannouncer/screenreaderannouncer.component.d.ts +14 -0
- package/dist/components/screenreaderannouncer/screenreaderannouncer.component.js +49 -0
- package/dist/components/toast/toast.component.d.ts +12 -1
- package/dist/components/toast/toast.component.js +28 -3
- package/dist/components/toast/toast.styles.js +10 -0
- package/dist/custom-elements.json +60 -0
- package/dist/utils/mixins/OverflowMixin.d.ts +1 -0
- package/dist/utils/mixins/OverflowMixin.js +4 -0
- package/package.json +1 -1
|
@@ -99,6 +99,11 @@ declare class ScreenreaderAnnouncer extends Component {
|
|
|
99
99
|
* @default 500
|
|
100
100
|
*/
|
|
101
101
|
debounceTime: number;
|
|
102
|
+
/**
|
|
103
|
+
* Whether this instance currently holds a ref for its identity.
|
|
104
|
+
* @internal
|
|
105
|
+
*/
|
|
106
|
+
private hasIdentityRef;
|
|
102
107
|
/**
|
|
103
108
|
* Array to store timeOutIds for clearing timeouts later.
|
|
104
109
|
* @internal
|
|
@@ -160,6 +165,15 @@ declare class ScreenreaderAnnouncer extends Component {
|
|
|
160
165
|
* this.debounceTime milliseconds have passed since the last time this.announcement was updated.
|
|
161
166
|
*/
|
|
162
167
|
private setupDebouncedAnnounce;
|
|
168
|
+
/**
|
|
169
|
+
* Increments the refcount for the current identity.
|
|
170
|
+
*/
|
|
171
|
+
private acquireIdentityRef;
|
|
172
|
+
/**
|
|
173
|
+
* Decrements the refcount for the current identity.
|
|
174
|
+
* When the count reaches zero the live-region DOM node is removed.
|
|
175
|
+
*/
|
|
176
|
+
private releaseIdentityRef;
|
|
163
177
|
connectedCallback(): void;
|
|
164
178
|
disconnectedCallback(): void;
|
|
165
179
|
protected updated(changedProperties: PropertyValueMap<any> | Map<PropertyKey, unknown>): void;
|
|
@@ -13,6 +13,14 @@ import { Component } from '../../models';
|
|
|
13
13
|
import { debounce } from '../../utils/debounce';
|
|
14
14
|
import { DEFAULTS } from './screenreaderannouncer.constants';
|
|
15
15
|
import styles from './screenreaderannouncer.styles';
|
|
16
|
+
// AI-Assisted
|
|
17
|
+
/**
|
|
18
|
+
* Module-scope refcount: tracks how many live ScreenreaderAnnouncer instances
|
|
19
|
+
* reference each identity. When the count drops to zero the DOM node created
|
|
20
|
+
* by createAnnouncementAriaLiveRegion() is removed.
|
|
21
|
+
*/
|
|
22
|
+
const identityRefCount = new Map();
|
|
23
|
+
// End AI-Assisted
|
|
16
24
|
/**
|
|
17
25
|
* `mdc-screenreaderannouncer` can be used to announce messages with the screen reader.
|
|
18
26
|
*
|
|
@@ -113,6 +121,11 @@ class ScreenreaderAnnouncer extends Component {
|
|
|
113
121
|
* @default 500
|
|
114
122
|
*/
|
|
115
123
|
this.debounceTime = DEFAULTS.DEBOUNCE;
|
|
124
|
+
/**
|
|
125
|
+
* Whether this instance currently holds a ref for its identity.
|
|
126
|
+
* @internal
|
|
127
|
+
*/
|
|
128
|
+
this.hasIdentityRef = false;
|
|
116
129
|
/**
|
|
117
130
|
* Array to store timeOutIds for clearing timeouts later.
|
|
118
131
|
* @internal
|
|
@@ -262,12 +275,47 @@ class ScreenreaderAnnouncer extends Component {
|
|
|
262
275
|
}
|
|
263
276
|
}, this.debounceTime);
|
|
264
277
|
}
|
|
278
|
+
// AI-Assisted
|
|
279
|
+
/**
|
|
280
|
+
* Increments the refcount for the current identity.
|
|
281
|
+
*/
|
|
282
|
+
acquireIdentityRef() {
|
|
283
|
+
var _a;
|
|
284
|
+
if (this.hasIdentityRef)
|
|
285
|
+
return;
|
|
286
|
+
identityRefCount.set(this.identity, ((_a = identityRefCount.get(this.identity)) !== null && _a !== void 0 ? _a : 0) + 1);
|
|
287
|
+
this.hasIdentityRef = true;
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Decrements the refcount for the current identity.
|
|
291
|
+
* When the count reaches zero the live-region DOM node is removed.
|
|
292
|
+
*/
|
|
293
|
+
releaseIdentityRef() {
|
|
294
|
+
var _a;
|
|
295
|
+
if (!this.hasIdentityRef)
|
|
296
|
+
return;
|
|
297
|
+
const next = ((_a = identityRefCount.get(this.identity)) !== null && _a !== void 0 ? _a : 1) - 1;
|
|
298
|
+
if (next <= 0) {
|
|
299
|
+
identityRefCount.delete(this.identity);
|
|
300
|
+
const node = this.getElementByIdAcrossShadowRoot(this.identity);
|
|
301
|
+
// Only remove nodes WE created (they carry our class).
|
|
302
|
+
if (node === null || node === void 0 ? void 0 : node.classList.contains('mdc-screenreaderannouncer__visually-hidden')) {
|
|
303
|
+
node.remove();
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
else {
|
|
307
|
+
identityRefCount.set(this.identity, next);
|
|
308
|
+
}
|
|
309
|
+
this.hasIdentityRef = false;
|
|
310
|
+
}
|
|
311
|
+
// End AI-Assisted
|
|
265
312
|
connectedCallback() {
|
|
266
313
|
super.connectedCallback();
|
|
267
314
|
if (this.identity.length === 0) {
|
|
268
315
|
this.identity = DEFAULTS.IDENTITY;
|
|
269
316
|
}
|
|
270
317
|
this.createAnnouncementAriaLiveRegion();
|
|
318
|
+
this.acquireIdentityRef();
|
|
271
319
|
this.setupDebouncedAnnounce();
|
|
272
320
|
}
|
|
273
321
|
disconnectedCallback() {
|
|
@@ -276,6 +324,7 @@ class ScreenreaderAnnouncer extends Component {
|
|
|
276
324
|
this.clearTimeOutsAndAnnouncements();
|
|
277
325
|
// cancel any pending debounced action and clear DOM timeouts
|
|
278
326
|
(_a = this.debouncedAnnounce) === null || _a === void 0 ? void 0 : _a.cancel();
|
|
327
|
+
this.releaseIdentityRef();
|
|
279
328
|
}
|
|
280
329
|
updated(changedProperties) {
|
|
281
330
|
var _a;
|
|
@@ -44,6 +44,11 @@ declare const Toast_base: import("../../utils/mixins/index.types").Constructor<i
|
|
|
44
44
|
* @cssproperty --mdc-toast-padding - Padding inside the toast.
|
|
45
45
|
*/
|
|
46
46
|
declare class Toast extends Toast_base {
|
|
47
|
+
/**
|
|
48
|
+
* Reference to the header text element
|
|
49
|
+
* @internal
|
|
50
|
+
*/
|
|
51
|
+
private headerTextElement;
|
|
47
52
|
/**
|
|
48
53
|
* Type of toast
|
|
49
54
|
* - Can be `custom`, `success`, `warning` or `error`.
|
|
@@ -79,6 +84,12 @@ declare class Toast extends Toast_base {
|
|
|
79
84
|
showLessText?: string;
|
|
80
85
|
private isDetailVisible;
|
|
81
86
|
private hasDetailedSlot;
|
|
87
|
+
/**
|
|
88
|
+
* Indicates whether the header text is overflowing and requires the show more/less toggle button to be shown when detailed content is present.
|
|
89
|
+
* This is determined on first update and will not update dynamically if the header text changes after initial render.
|
|
90
|
+
* @internal
|
|
91
|
+
*/
|
|
92
|
+
private hasOverflowingHeaderText;
|
|
82
93
|
private detailedElements;
|
|
83
94
|
private hasFooterButtons;
|
|
84
95
|
/**
|
|
@@ -90,7 +101,7 @@ declare class Toast extends Toast_base {
|
|
|
90
101
|
private toggleDetailVisibility;
|
|
91
102
|
private updateDetailedSlotPresence;
|
|
92
103
|
private updateFooterButtonsPresence;
|
|
93
|
-
protected firstUpdated(changedProperties: PropertyValues): void
|
|
104
|
+
protected firstUpdated(changedProperties: PropertyValues): Promise<void>;
|
|
94
105
|
protected renderIcon(iconName: string): import("lit-html").TemplateResult<1> | typeof nothing;
|
|
95
106
|
private shouldRenderToggleButton;
|
|
96
107
|
private renderToggleDetailButton;
|
|
@@ -8,11 +8,12 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
8
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
9
|
};
|
|
10
10
|
import { html, nothing } from 'lit';
|
|
11
|
-
import { property, queryAssignedElements, state } from 'lit/decorators.js';
|
|
11
|
+
import { property, query, queryAssignedElements, state } from 'lit/decorators.js';
|
|
12
12
|
import { ifDefined } from 'lit/directives/if-defined.js';
|
|
13
13
|
import { Component } from '../../models';
|
|
14
14
|
import { FooterMixin } from '../../utils/mixins/FooterMixin';
|
|
15
15
|
import { TYPE } from '../text/text.constants';
|
|
16
|
+
import { hasOverflowMixin } from '../../utils/dom';
|
|
16
17
|
import { DEFAULTS } from './toast.constants';
|
|
17
18
|
import { getIconNameForVariant } from './toast.utils';
|
|
18
19
|
import styles from './toast.styles';
|
|
@@ -77,6 +78,12 @@ class Toast extends FooterMixin(Component) {
|
|
|
77
78
|
this.ariaLabel = null;
|
|
78
79
|
this.isDetailVisible = false;
|
|
79
80
|
this.hasDetailedSlot = false;
|
|
81
|
+
/**
|
|
82
|
+
* Indicates whether the header text is overflowing and requires the show more/less toggle button to be shown when detailed content is present.
|
|
83
|
+
* This is determined on first update and will not update dynamically if the header text changes after initial render.
|
|
84
|
+
* @internal
|
|
85
|
+
*/
|
|
86
|
+
this.hasOverflowingHeaderText = false;
|
|
80
87
|
this.hasFooterButtons = '';
|
|
81
88
|
}
|
|
82
89
|
/**
|
|
@@ -94,6 +101,12 @@ class Toast extends FooterMixin(Component) {
|
|
|
94
101
|
}
|
|
95
102
|
toggleDetailVisibility() {
|
|
96
103
|
this.isDetailVisible = !this.isDetailVisible;
|
|
104
|
+
if (this.isDetailVisible) {
|
|
105
|
+
this.setAttribute('data-expanded', 'true');
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
this.removeAttribute('data-expanded');
|
|
109
|
+
}
|
|
97
110
|
}
|
|
98
111
|
updateDetailedSlotPresence() {
|
|
99
112
|
var _a, _b;
|
|
@@ -108,9 +121,13 @@ class Toast extends FooterMixin(Component) {
|
|
|
108
121
|
? 'has-footer-buttons'
|
|
109
122
|
: '';
|
|
110
123
|
}
|
|
111
|
-
firstUpdated(changedProperties) {
|
|
124
|
+
async firstUpdated(changedProperties) {
|
|
112
125
|
super.firstUpdated(changedProperties);
|
|
113
126
|
this.updateDetailedSlotPresence();
|
|
127
|
+
await this.updateComplete;
|
|
128
|
+
if (hasOverflowMixin(this.headerTextElement)) {
|
|
129
|
+
this.hasOverflowingHeaderText = this.headerTextElement.isHeightOverflowing();
|
|
130
|
+
}
|
|
114
131
|
}
|
|
115
132
|
renderIcon(iconName) {
|
|
116
133
|
if (!iconName)
|
|
@@ -120,7 +137,7 @@ class Toast extends FooterMixin(Component) {
|
|
|
120
137
|
`;
|
|
121
138
|
}
|
|
122
139
|
shouldRenderToggleButton() {
|
|
123
|
-
return this.hasDetailedSlot && this.showMoreText && this.showLessText;
|
|
140
|
+
return (this.hasDetailedSlot || this.hasOverflowingHeaderText) && this.showMoreText && this.showLessText;
|
|
124
141
|
}
|
|
125
142
|
renderToggleDetailButton() {
|
|
126
143
|
if (!this.shouldRenderToggleButton())
|
|
@@ -193,6 +210,10 @@ class Toast extends FooterMixin(Component) {
|
|
|
193
210
|
}
|
|
194
211
|
}
|
|
195
212
|
Toast.styles = [...Component.styles, ...styles];
|
|
213
|
+
__decorate([
|
|
214
|
+
query("[part='toast-header']"),
|
|
215
|
+
__metadata("design:type", HTMLElement)
|
|
216
|
+
], Toast.prototype, "headerTextElement", void 0);
|
|
196
217
|
__decorate([
|
|
197
218
|
property({ type: String, reflect: true }),
|
|
198
219
|
__metadata("design:type", String)
|
|
@@ -229,6 +250,10 @@ __decorate([
|
|
|
229
250
|
state(),
|
|
230
251
|
__metadata("design:type", Boolean)
|
|
231
252
|
], Toast.prototype, "hasDetailedSlot", void 0);
|
|
253
|
+
__decorate([
|
|
254
|
+
state(),
|
|
255
|
+
__metadata("design:type", Boolean)
|
|
256
|
+
], Toast.prototype, "hasOverflowingHeaderText", void 0);
|
|
232
257
|
__decorate([
|
|
233
258
|
queryAssignedElements({ slot: 'toast-body-detailed', flatten: true }),
|
|
234
259
|
__metadata("design:type", Array)
|
|
@@ -65,6 +65,16 @@ const styles = css `
|
|
|
65
65
|
line-height: var(--mds-font-lineheight-body-large);
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
+
[part='toast-header']::part(text) {
|
|
69
|
+
display: unset;
|
|
70
|
+
-webkit-box-orient: inherit;
|
|
71
|
+
-webkit-line-clamp: inherit;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
:host([data-expanded='true'])::part(toast-header) {
|
|
75
|
+
-webkit-line-clamp: unset;
|
|
76
|
+
}
|
|
77
|
+
|
|
68
78
|
:host::part(footer) {
|
|
69
79
|
display: flex;
|
|
70
80
|
justify-content: flex-end;
|
|
@@ -5160,6 +5160,20 @@
|
|
|
5160
5160
|
"attribute": "inverted",
|
|
5161
5161
|
"reflects": true
|
|
5162
5162
|
},
|
|
5163
|
+
{
|
|
5164
|
+
"kind": "method",
|
|
5165
|
+
"name": "isHeightOverflowing",
|
|
5166
|
+
"privacy": "public",
|
|
5167
|
+
"return": {
|
|
5168
|
+
"type": {
|
|
5169
|
+
"text": "boolean"
|
|
5170
|
+
}
|
|
5171
|
+
},
|
|
5172
|
+
"inheritedFrom": {
|
|
5173
|
+
"name": "OverflowMixin",
|
|
5174
|
+
"module": "utils/mixins/OverflowMixin.js"
|
|
5175
|
+
}
|
|
5176
|
+
},
|
|
5163
5177
|
{
|
|
5164
5178
|
"kind": "method",
|
|
5165
5179
|
"name": "isWidthOverflowing",
|
|
@@ -38526,6 +38540,12 @@
|
|
|
38526
38540
|
"description": "`mdc-screenreaderannouncer` can be used to announce messages with the screen reader.\n\nTo make an announcement set `announcement` attribute on the `mdc-screenreaderannouncer` element.\n\nConsumers can also use the public `announce` function to trigger announcements programmatically\nby passing an options object where `announcement` is required and all other fields are optional.\n\n**Internal logic**\n\nWhen the screenreader announcer is connected to the DOM, if the `identity` attribute is not\nprovided, it is set to `mdc-screenreaderannouncer-identity` and a `<div>` element with this id is created\nin the DOM. If the `identity` attribute is provided, the identity element is used and no new element\nis created in the DOM.\n\nIf you provide a custom `identity`, you must ensure that the element exists and is visually hidden.\n\nExample CSS:\n\n```css\n#your-custom-announcer-id {\n clip: rect(0 0 0 0);\n clip-path: inset(50%);\n height: 1px;\n overflow: hidden;\n position: absolute;\n white-space: nowrap;\n width: 1px;\n}\n```\n\nWhen the `announcement` attribute is set, the screenreader announcer will create a `<div>` element with\n`aria-live` attribute set to the value of `data-aria-live` attribute and append it to the `identity` element.\nAfter delay of `delay` milliseconds, a `<p>` element with the announcement text is appended to the `<div>` element.\n\nThe announcement `<div>` element is removed from the DOM after `timeout` milliseconds.\n\nWhen the screen announcer component is disconnected from the DOM, all the timeouts are cleared and\nall the announcement elements added are removed from the DOM and timeouts cleared.\n\n**Note**\n1. The default delay of 150 miliseconds is used as we dynamically generate the\naria-live region in the DOM and add the announcement text to it.\n2. If multiple `mdc-screenreaderannouncer` instances use the same `identity`, `data-aria-live`\nfor that identity is effectively determined by the first instance that creates announcements for it.\nChanging `data-aria-live` in later instances for the same identity will not update already-created\nlive-region containers.\n3. If no `identity` is provided, all the screen reader components will create and use only one\n`<div>` element with id `mdc-screenreaderannouncer-identity` in the DOM.\n\nReference: https://patrickhlauke.github.io/aria/tests/live-regions/",
|
|
38527
38541
|
"name": "ScreenreaderAnnouncer",
|
|
38528
38542
|
"members": [
|
|
38543
|
+
{
|
|
38544
|
+
"kind": "method",
|
|
38545
|
+
"name": "acquireIdentityRef",
|
|
38546
|
+
"privacy": "private",
|
|
38547
|
+
"description": "Increments the refcount for the current identity."
|
|
38548
|
+
},
|
|
38529
38549
|
{
|
|
38530
38550
|
"kind": "method",
|
|
38531
38551
|
"name": "announce",
|
|
@@ -38611,6 +38631,12 @@
|
|
|
38611
38631
|
"attribute": "identity",
|
|
38612
38632
|
"reflects": true
|
|
38613
38633
|
},
|
|
38634
|
+
{
|
|
38635
|
+
"kind": "method",
|
|
38636
|
+
"name": "releaseIdentityRef",
|
|
38637
|
+
"privacy": "private",
|
|
38638
|
+
"description": "Decrements the refcount for the current identity.\nWhen the count reaches zero the live-region DOM node is removed."
|
|
38639
|
+
},
|
|
38614
38640
|
{
|
|
38615
38641
|
"kind": "method",
|
|
38616
38642
|
"name": "setupDebouncedAnnounce",
|
|
@@ -47409,6 +47435,20 @@
|
|
|
47409
47435
|
}
|
|
47410
47436
|
],
|
|
47411
47437
|
"members": [
|
|
47438
|
+
{
|
|
47439
|
+
"kind": "method",
|
|
47440
|
+
"name": "isHeightOverflowing",
|
|
47441
|
+
"privacy": "public",
|
|
47442
|
+
"return": {
|
|
47443
|
+
"type": {
|
|
47444
|
+
"text": "boolean"
|
|
47445
|
+
}
|
|
47446
|
+
},
|
|
47447
|
+
"inheritedFrom": {
|
|
47448
|
+
"name": "OverflowMixin",
|
|
47449
|
+
"module": "utils/mixins/OverflowMixin.js"
|
|
47450
|
+
}
|
|
47451
|
+
},
|
|
47412
47452
|
{
|
|
47413
47453
|
"kind": "method",
|
|
47414
47454
|
"name": "isWidthOverflowing",
|
|
@@ -57823,6 +57863,16 @@
|
|
|
57823
57863
|
"description": "",
|
|
57824
57864
|
"name": "OverflowMixin",
|
|
57825
57865
|
"members": [
|
|
57866
|
+
{
|
|
57867
|
+
"kind": "method",
|
|
57868
|
+
"name": "isHeightOverflowing",
|
|
57869
|
+
"privacy": "public",
|
|
57870
|
+
"return": {
|
|
57871
|
+
"type": {
|
|
57872
|
+
"text": "boolean"
|
|
57873
|
+
}
|
|
57874
|
+
}
|
|
57875
|
+
},
|
|
57826
57876
|
{
|
|
57827
57877
|
"kind": "method",
|
|
57828
57878
|
"name": "isWidthOverflowing",
|
|
@@ -57849,6 +57899,16 @@
|
|
|
57849
57899
|
"description": "",
|
|
57850
57900
|
"name": "OverflowMixinInterface",
|
|
57851
57901
|
"members": [
|
|
57902
|
+
{
|
|
57903
|
+
"kind": "method",
|
|
57904
|
+
"name": "isHeightOverflowing",
|
|
57905
|
+
"privacy": "public",
|
|
57906
|
+
"return": {
|
|
57907
|
+
"type": {
|
|
57908
|
+
"text": "boolean"
|
|
57909
|
+
}
|
|
57910
|
+
}
|
|
57911
|
+
},
|
|
57852
57912
|
{
|
|
57853
57913
|
"kind": "method",
|
|
57854
57914
|
"name": "isWidthOverflowing",
|
|
@@ -3,5 +3,6 @@ import type { Constructor } from './index.types';
|
|
|
3
3
|
export declare abstract class OverflowMixinInterface {
|
|
4
4
|
protected get overflowElement(): HTMLElement;
|
|
5
5
|
isWidthOverflowing(): boolean;
|
|
6
|
+
isHeightOverflowing(): boolean;
|
|
6
7
|
}
|
|
7
8
|
export declare const OverflowMixin: <T extends Constructor<LitElement>>(superClass: T) => Constructor<OverflowMixinInterface> & T;
|
|
@@ -17,6 +17,10 @@ export const OverflowMixin = (superClass) => {
|
|
|
17
17
|
const el = this.overflowElement;
|
|
18
18
|
return el.scrollWidth > el.clientWidth;
|
|
19
19
|
}
|
|
20
|
+
isHeightOverflowing() {
|
|
21
|
+
const el = this.overflowElement;
|
|
22
|
+
return el.scrollHeight > el.clientHeight;
|
|
23
|
+
}
|
|
20
24
|
}
|
|
21
25
|
// Cast return type to your mixin's interface intersected with the superClass type
|
|
22
26
|
return InnerMixinClass;
|