@momentum-design/components 0.92.3 → 0.92.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 +183 -182
- package/dist/browser/index.js.map +4 -4
- package/dist/components/divider/divider.styles.js +1 -0
- package/dist/components/listitem/listitem.component.d.ts +6 -1
- package/dist/components/listitem/listitem.component.js +12 -0
- package/dist/components/listitem/listitem.events.d.ts +34 -0
- package/dist/components/listitem/listitem.events.js +45 -0
- package/dist/components/listitem/listitem.types.d.ts +14 -3
- package/dist/components/menupopover/menupopover.component.d.ts +4 -1
- package/dist/components/menupopover/menupopover.component.js +32 -0
- package/dist/custom-elements.json +1429 -1206
- package/dist/react/index.d.ts +3 -3
- package/dist/react/index.js +3 -3
- package/dist/react/listitem/index.d.ts +8 -0
- package/dist/react/listitem/index.js +8 -0
- package/dist/react/menuitem/index.d.ts +4 -0
- package/dist/react/menuitem/index.js +4 -0
- package/dist/react/menuitemcheckbox/index.d.ts +4 -0
- package/dist/react/menuitemcheckbox/index.js +4 -0
- package/dist/react/menuitemradio/index.d.ts +4 -0
- package/dist/react/menuitemradio/index.js +4 -0
- package/dist/react/navmenuitem/index.d.ts +4 -0
- package/dist/react/navmenuitem/index.js +4 -0
- package/dist/react/option/index.d.ts +4 -0
- package/dist/react/option/index.js +4 -0
- package/package.json +1 -1
@@ -3,7 +3,7 @@ import { nothing } from 'lit';
|
|
3
3
|
import { Component } from '../../models';
|
4
4
|
import type { PopoverPlacement } from '../popover/popover.types';
|
5
5
|
import type { TextType } from '../text/text.types';
|
6
|
-
import
|
6
|
+
import { ListItemVariants } from './listitem.types';
|
7
7
|
declare const ListItem_base: import("../../utils/mixins/index.types").Constructor<import("../../utils/mixins/DisabledMixin").DisabledMixinInterface> & import("../../utils/mixins/index.types").Constructor<import("../../utils/mixins/TabIndexMixin").TabIndexMixinInterface> & typeof Component;
|
8
8
|
/**
|
9
9
|
* mdc-listitem component is used to display a label with different types of controls.
|
@@ -49,6 +49,10 @@ declare const ListItem_base: import("../../utils/mixins/index.types").Constructo
|
|
49
49
|
* @event keydown - (React: onKeyDown) This event is dispatched when a key is pressed down on the listitem.
|
50
50
|
* @event keyup - (React: onKeyUp) This event is dispatched when a key is released on the listitem.
|
51
51
|
* @event focus - (React: onFocus) This event is dispatched when the listitem receives focus.
|
52
|
+
* @event enabled - (React: onEnabled) This event is dispatched after the listitem is enabled
|
53
|
+
* @event disabled - (React: onDisabled) This event is dispatched after the listitem is disabled
|
54
|
+
* @event created - (React: onCreated) This event is dispatched after the listitem is created (added to the DOM)
|
55
|
+
* @event destroyed - (React: onDestroyed) This event is dispatched after the listitem is destroyed (removed from the DOM)
|
52
56
|
*/
|
53
57
|
declare class ListItem extends ListItem_base {
|
54
58
|
/** @internal */
|
@@ -108,6 +112,7 @@ declare class ListItem extends ListItem_base {
|
|
108
112
|
tooltipPlacement: PopoverPlacement;
|
109
113
|
constructor();
|
110
114
|
connectedCallback(): void;
|
115
|
+
disconnectedCallback(): void;
|
111
116
|
/**
|
112
117
|
* Fires the click event when the enter or space key is pressed down.
|
113
118
|
* This behavior is similar to a button click and key interaction.
|
@@ -19,6 +19,7 @@ import { TAG_NAME as TOOLTIP_TAG_NAME } from '../tooltip/tooltip.constants';
|
|
19
19
|
import { DEFAULTS } from './listitem.constants';
|
20
20
|
import styles from './listitem.styles';
|
21
21
|
import { generateListItemId, generateTooltipId } from './listitem.utils';
|
22
|
+
import { ListItemEventManager } from './listitem.events';
|
22
23
|
/**
|
23
24
|
* mdc-listitem component is used to display a label with different types of controls.
|
24
25
|
* There can be three types of controls, a radio button, a checkbox on the
|
@@ -63,6 +64,10 @@ import { generateListItemId, generateTooltipId } from './listitem.utils';
|
|
63
64
|
* @event keydown - (React: onKeyDown) This event is dispatched when a key is pressed down on the listitem.
|
64
65
|
* @event keyup - (React: onKeyUp) This event is dispatched when a key is released on the listitem.
|
65
66
|
* @event focus - (React: onFocus) This event is dispatched when the listitem receives focus.
|
67
|
+
* @event enabled - (React: onEnabled) This event is dispatched after the listitem is enabled
|
68
|
+
* @event disabled - (React: onDisabled) This event is dispatched after the listitem is disabled
|
69
|
+
* @event created - (React: onCreated) This event is dispatched after the listitem is created (added to the DOM)
|
70
|
+
* @event destroyed - (React: onDestroyed) This event is dispatched after the listitem is destroyed (removed from the DOM)
|
66
71
|
*/
|
67
72
|
class ListItem extends DisabledMixin(TabIndexMixin(Component)) {
|
68
73
|
constructor() {
|
@@ -90,6 +95,11 @@ class ListItem extends DisabledMixin(TabIndexMixin(Component)) {
|
|
90
95
|
this.role = this.role || ROLE.LISTITEM;
|
91
96
|
// Add a unique id to the listitem if it does not have one.
|
92
97
|
this.id = this.id || generateListItemId();
|
98
|
+
ListItemEventManager.onCreatedListItem(this);
|
99
|
+
}
|
100
|
+
disconnectedCallback() {
|
101
|
+
super.disconnectedCallback();
|
102
|
+
ListItemEventManager.onDestroyedListItem(this);
|
93
103
|
}
|
94
104
|
/**
|
95
105
|
* Fires the click event when the enter or space key is pressed down.
|
@@ -184,9 +194,11 @@ class ListItem extends DisabledMixin(TabIndexMixin(Component)) {
|
|
184
194
|
[...this.leadingControlsSlot, ...this.trailingControlsSlot].forEach(element => {
|
185
195
|
if (disabled) {
|
186
196
|
element.setAttribute('disabled', '');
|
197
|
+
ListItemEventManager.onDisableListItem(this);
|
187
198
|
}
|
188
199
|
else {
|
189
200
|
element.removeAttribute('disabled');
|
201
|
+
ListItemEventManager.onEnableListItem(this);
|
190
202
|
}
|
191
203
|
});
|
192
204
|
// Set the aria-disabled attribute to indicate that the list item is disabled.
|
@@ -0,0 +1,34 @@
|
|
1
|
+
import type ListItem from './listitem.component';
|
2
|
+
export declare class ListItemEventManager {
|
3
|
+
/**
|
4
|
+
* Dispatches a custom event for the ListItem.
|
5
|
+
*
|
6
|
+
* @param eventName - The name of the event.
|
7
|
+
* @param instance - The LitItem instance.
|
8
|
+
*/
|
9
|
+
private static dispatchListItemEvent;
|
10
|
+
/**
|
11
|
+
* Custom event that is fired when the popover is shown.
|
12
|
+
*
|
13
|
+
* @param instance - The popover instance.
|
14
|
+
*/
|
15
|
+
static onDisableListItem(instance: ListItem): void;
|
16
|
+
/**
|
17
|
+
* Custom event that is fired when the popover is hidden.
|
18
|
+
*
|
19
|
+
* @param instance - The popover instance.
|
20
|
+
*/
|
21
|
+
static onEnableListItem(instance: ListItem): void;
|
22
|
+
/**
|
23
|
+
* Custom event that is fired when the popover is created.
|
24
|
+
*
|
25
|
+
* @param instance - The popover instance.
|
26
|
+
*/
|
27
|
+
static onCreatedListItem(instance: ListItem): void;
|
28
|
+
/**
|
29
|
+
* Custom event that is fired when the popover is destroyed.
|
30
|
+
*
|
31
|
+
* @param instance - The popover instance.
|
32
|
+
*/
|
33
|
+
static onDestroyedListItem(instance: ListItem): void;
|
34
|
+
}
|
@@ -0,0 +1,45 @@
|
|
1
|
+
export class ListItemEventManager {
|
2
|
+
/**
|
3
|
+
* Dispatches a custom event for the ListItem.
|
4
|
+
*
|
5
|
+
* @param eventName - The name of the event.
|
6
|
+
* @param instance - The LitItem instance.
|
7
|
+
*/
|
8
|
+
static dispatchListItemEvent(eventName, instance) {
|
9
|
+
instance.dispatchEvent(new Event(eventName, { composed: true, bubbles: true }));
|
10
|
+
}
|
11
|
+
/**
|
12
|
+
* Custom event that is fired when the popover is shown.
|
13
|
+
*
|
14
|
+
* @param instance - The popover instance.
|
15
|
+
*/
|
16
|
+
static onDisableListItem(instance) {
|
17
|
+
this.dispatchListItemEvent('disabled', instance);
|
18
|
+
}
|
19
|
+
/**
|
20
|
+
* Custom event that is fired when the popover is hidden.
|
21
|
+
*
|
22
|
+
* @param instance - The popover instance.
|
23
|
+
*/
|
24
|
+
static onEnableListItem(instance) {
|
25
|
+
this.dispatchListItemEvent('enabled', instance);
|
26
|
+
}
|
27
|
+
/**
|
28
|
+
* Custom event that is fired when the popover is created.
|
29
|
+
*
|
30
|
+
* @param instance - The popover instance.
|
31
|
+
*/
|
32
|
+
static onCreatedListItem(instance) {
|
33
|
+
// Use setTimeout to ensure the event is dispatched after the component is fully initialized
|
34
|
+
// Inherited Element might execute its own lifecycle methods
|
35
|
+
setTimeout(() => this.dispatchListItemEvent('created', instance), 0);
|
36
|
+
}
|
37
|
+
/**
|
38
|
+
* Custom event that is fired when the popover is destroyed.
|
39
|
+
*
|
40
|
+
* @param instance - The popover instance.
|
41
|
+
*/
|
42
|
+
static onDestroyedListItem(instance) {
|
43
|
+
this.dispatchListItemEvent('destroyed', instance);
|
44
|
+
}
|
45
|
+
}
|
@@ -1,10 +1,21 @@
|
|
1
1
|
import type { ValueOf } from '../../utils/types';
|
2
2
|
import { LISTITEM_VARIANTS } from './listitem.constants';
|
3
|
-
type ListItemVariants = ValueOf<typeof LISTITEM_VARIANTS>;
|
4
|
-
interface Events {
|
3
|
+
export type ListItemVariants = ValueOf<typeof LISTITEM_VARIANTS>;
|
4
|
+
export interface Events {
|
5
5
|
onClickEvent: MouseEvent;
|
6
6
|
onKeyDownEvent: KeyboardEvent;
|
7
7
|
onKeyUpEvent: KeyboardEvent;
|
8
8
|
onFocusEvent: FocusEvent;
|
9
|
+
onEnabledEvent: Event;
|
10
|
+
onDisabledEvent: Event;
|
11
|
+
onCreatedEvent: Event;
|
12
|
+
onDestroyedEvent: Event;
|
13
|
+
}
|
14
|
+
declare global {
|
15
|
+
interface GlobalEventHandlersEventMap {
|
16
|
+
disabled: Event;
|
17
|
+
enabled: Event;
|
18
|
+
created: Event;
|
19
|
+
destroyed: Event;
|
20
|
+
}
|
9
21
|
}
|
10
|
-
export type { ListItemVariants, Events };
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { CSSResult, PropertyValues } from 'lit';
|
2
2
|
import Popover from '../popover/popover.component';
|
3
|
-
import { PopoverPlacement } from '../popover/popover.types';
|
3
|
+
import type { PopoverPlacement } from '../popover/popover.types';
|
4
4
|
/**
|
5
5
|
* A popover menu component that displays a list of menu items in a floating container.
|
6
6
|
* It's designed to work in conjunction with `mdc-menubar` and `mdc-menuitem` to create
|
@@ -129,6 +129,9 @@ declare class MenuPopover extends Popover {
|
|
129
129
|
* @param event - The mouse event that triggered the click.
|
130
130
|
*/
|
131
131
|
private handleMouseClick;
|
132
|
+
private handleItemCreation;
|
133
|
+
private handleItemChangeEvent;
|
134
|
+
private resetMenuNavigation;
|
132
135
|
/**
|
133
136
|
* Resolves the key pressed by the user based on the direction of the layout.
|
134
137
|
* This method is used to handle keyboard navigation in a right-to-left (RTL) layout.
|
@@ -120,9 +120,27 @@ class MenuPopover extends Popover {
|
|
120
120
|
this.isTriggerClicked = true;
|
121
121
|
}
|
122
122
|
};
|
123
|
+
this.handleItemChangeEvent = (event) => {
|
124
|
+
event.stopImmediatePropagation();
|
125
|
+
if (event.target && event.type === 'destroyed') {
|
126
|
+
event.target.removeEventListener('destroyed', this.handleItemChangeEvent);
|
127
|
+
event.target.removeEventListener('disabled', this.handleItemChangeEvent);
|
128
|
+
}
|
129
|
+
this.resetMenuNavigation();
|
130
|
+
};
|
131
|
+
this.resetMenuNavigation = () => {
|
132
|
+
// Re-collect menu items to ensure the list is up-to-date
|
133
|
+
this.collectMenuItems();
|
134
|
+
// Reset tab indexes to ensure at least one menu item is focusable
|
135
|
+
const focusableMenuItem = this.menuItems.find(item => item.getAttribute('tabindex') === '0');
|
136
|
+
if (!focusableMenuItem) {
|
137
|
+
this.resetTabIndexes(0);
|
138
|
+
}
|
139
|
+
};
|
123
140
|
this.addEventListener('keydown', this.handleKeyDown);
|
124
141
|
this.addEventListener('keyup', this.handleKeyUp);
|
125
142
|
this.addEventListener('click', this.handleMouseClick);
|
143
|
+
this.addEventListener('created', this.handleItemCreation);
|
126
144
|
}
|
127
145
|
/** @internal */
|
128
146
|
collectMenuItems() {
|
@@ -165,6 +183,7 @@ class MenuPopover extends Popover {
|
|
165
183
|
if (newValue) {
|
166
184
|
this.backdrop = !(this.triggerElement.tagName.toLowerCase() === MENUITEM_TAGNAME);
|
167
185
|
}
|
186
|
+
this.resetMenuNavigation();
|
168
187
|
return super.isOpenUpdated(oldValue, newValue);
|
169
188
|
}
|
170
189
|
async firstUpdated(changedProperties) {
|
@@ -183,6 +202,7 @@ class MenuPopover extends Popover {
|
|
183
202
|
if (this.menuItems.length > 0) {
|
184
203
|
this.menuItems.forEach(menuitem => menuitem.setAttribute('tabindex', '-1'));
|
185
204
|
this.menuItems[currentIndex].setAttribute('tabindex', '0');
|
205
|
+
this.menuItems[currentIndex].focus();
|
186
206
|
}
|
187
207
|
}
|
188
208
|
/**
|
@@ -267,6 +287,18 @@ class MenuPopover extends Popover {
|
|
267
287
|
this.closeMenu(target);
|
268
288
|
}
|
269
289
|
}
|
290
|
+
handleItemCreation(event) {
|
291
|
+
const item = event.target;
|
292
|
+
if (isValidMenuItem(item)) {
|
293
|
+
// Parent menu popover should not listen on nested menu items
|
294
|
+
event.stopImmediatePropagation();
|
295
|
+
// `destroyed` triggered in the `disconnectedCallback` of the item which executed when the item is removed from the DOM
|
296
|
+
// because of that the event does not bubble up to menupopover, and we need to capture the `destroyed` event on the item itself
|
297
|
+
item.addEventListener('destroyed', this.handleItemChangeEvent);
|
298
|
+
// `disabled` could bubble up, but it is more consistent to handle it the same way as `destroyed`
|
299
|
+
item.addEventListener('disabled', this.handleItemChangeEvent);
|
300
|
+
}
|
301
|
+
}
|
270
302
|
/**
|
271
303
|
* Resolves the key pressed by the user based on the direction of the layout.
|
272
304
|
* This method is used to handle keyboard navigation in a right-to-left (RTL) layout.
|