@momentum-design/components 0.120.8 → 0.120.10

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.
@@ -122,8 +122,11 @@ declare class ListItem extends ListItem_base {
122
122
  protected handleKeyDown(event: KeyboardEvent): void;
123
123
  /**
124
124
  * Triggers a click event on the list item.
125
+ *
126
+ * @param event - The event that triggered the click.
127
+ * @returns - Returns true if the click event was dispatched, false otherwise.
125
128
  */
126
- protected triggerClickEvent(): void;
129
+ protected triggerClickEvent(event: Event): boolean;
127
130
  /**
128
131
  * Generates a template for a text slot with the specified content.
129
132
  *
@@ -111,20 +111,31 @@ class ListItem extends DisabledMixin(TabIndexMixin(LifeCycleMixin(Component))) {
111
111
  */
112
112
  handleKeyDown(event) {
113
113
  if (event.key === KEYS.ENTER || event.key === KEYS.SPACE) {
114
- this.triggerClickEvent();
115
- event.preventDefault();
114
+ const eventDispatched = this.triggerClickEvent(event);
115
+ if (eventDispatched) {
116
+ event.preventDefault();
117
+ }
116
118
  }
117
119
  }
118
120
  /**
119
121
  * Triggers a click event on the list item.
122
+ *
123
+ * @param event - The event that triggered the click.
124
+ * @returns - Returns true if the click event was dispatched, false otherwise.
120
125
  */
121
- triggerClickEvent() {
126
+ triggerClickEvent(event) {
127
+ const target = event.target;
128
+ // Do not emit click event when the target is a focusable element inside the list item.
129
+ if (target !== this && document.activeElement === event.target) {
130
+ return false;
131
+ }
122
132
  const clickEvent = new MouseEvent('click', {
123
133
  bubbles: true,
124
134
  cancelable: true,
125
135
  view: window,
126
136
  });
127
137
  this.dispatchEvent(clickEvent);
138
+ return true;
128
139
  }
129
140
  /**
130
141
  * Generates a template for a text slot with the specified content.
@@ -78,7 +78,7 @@ class MenuItem extends ListItem {
78
78
  */
79
79
  handleKeyDown(event) {
80
80
  if (event.key === KEYS.ENTER) {
81
- this.triggerClickEvent();
81
+ this.triggerClickEvent(event);
82
82
  event.preventDefault();
83
83
  }
84
84
  }
@@ -96,7 +96,7 @@ class MenuItem extends ListItem {
96
96
  */
97
97
  handleKeyUp(event) {
98
98
  if (event.key === KEYS.SPACE) {
99
- this.triggerClickEvent();
99
+ this.triggerClickEvent(event);
100
100
  event.preventDefault();
101
101
  }
102
102
  }