@momentum-design/components 0.129.42 → 0.129.44

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.
Files changed (61) hide show
  1. package/dist/browser/index.js +386 -386
  2. package/dist/browser/index.js.map +4 -4
  3. package/dist/components/accordionbutton/accordionbutton.component.d.ts +1 -1
  4. package/dist/components/accordionbutton/accordionbutton.component.js +4 -3
  5. package/dist/components/buttonsimple/buttonsimple.component.d.ts +1 -1
  6. package/dist/components/buttonsimple/buttonsimple.component.js +8 -6
  7. package/dist/components/cardcheckbox/cardcheckbox.component.d.ts +1 -1
  8. package/dist/components/cardcheckbox/cardcheckbox.component.js +7 -5
  9. package/dist/components/cardradio/cardradio.component.d.ts +1 -1
  10. package/dist/components/cardradio/cardradio.component.js +8 -7
  11. package/dist/components/checkbox/checkbox.component.d.ts +2 -1
  12. package/dist/components/checkbox/checkbox.component.js +7 -4
  13. package/dist/components/coachmark/coachmark.component.d.ts +14 -1
  14. package/dist/components/coachmark/coachmark.component.js +14 -1
  15. package/dist/components/coachmark/index.d.ts +0 -1
  16. package/dist/components/coachmark/index.js +0 -1
  17. package/dist/components/combobox/combobox.component.d.ts +1 -1
  18. package/dist/components/combobox/combobox.component.js +11 -11
  19. package/dist/components/input/input.component.d.ts +1 -1
  20. package/dist/components/input/input.component.js +3 -3
  21. package/dist/components/list/list.component.d.ts +1 -1
  22. package/dist/components/listbox/listbox.component.d.ts +1 -1
  23. package/dist/components/listitem/listitem.component.d.ts +1 -1
  24. package/dist/components/listitem/listitem.component.js +11 -5
  25. package/dist/components/menubar/menubar.component.d.ts +2 -2
  26. package/dist/components/menubar/menubar.component.js +10 -20
  27. package/dist/components/menuitem/menuitem.component.js +3 -3
  28. package/dist/components/menupopover/menupopover.component.d.ts +0 -10
  29. package/dist/components/menupopover/menupopover.component.js +15 -36
  30. package/dist/components/popover/popover.component.d.ts +26 -13
  31. package/dist/components/popover/popover.component.js +26 -12
  32. package/dist/components/popover/popover.constants.d.ts +5 -1
  33. package/dist/components/popover/popover.constants.js +6 -2
  34. package/dist/components/popover/popover.types.d.ts +3 -2
  35. package/dist/components/radio/radio.component.d.ts +1 -1
  36. package/dist/components/radio/radio.component.js +8 -7
  37. package/dist/components/searchfield/searchfield.component.d.ts +3 -0
  38. package/dist/components/searchfield/searchfield.component.js +18 -5
  39. package/dist/components/searchpopover/searchpopover.component.js +3 -4
  40. package/dist/components/select/select.component.d.ts +1 -1
  41. package/dist/components/select/select.component.js +9 -8
  42. package/dist/components/slider/slider.component.d.ts +2 -1
  43. package/dist/components/slider/slider.component.js +4 -3
  44. package/dist/components/stepperitem/stepperitem.component.d.ts +1 -1
  45. package/dist/components/stepperitem/stepperitem.component.js +8 -6
  46. package/dist/components/textarea/textarea.component.d.ts +1 -1
  47. package/dist/components/textarea/textarea.component.js +5 -4
  48. package/dist/components/toggle/toggle.component.d.ts +1 -1
  49. package/dist/components/toggle/toggle.component.js +5 -4
  50. package/dist/components/virtualizedlist/virtualizedlist.component.d.ts +1 -1
  51. package/dist/components/virtualizedlist/virtualizedlist.component.js +7 -6
  52. package/dist/custom-elements.json +1417 -1020
  53. package/dist/react/checkbox/index.d.ts +1 -0
  54. package/dist/react/checkbox/index.js +1 -0
  55. package/dist/react/coachmark/index.d.ts +14 -1
  56. package/dist/react/coachmark/index.js +14 -1
  57. package/dist/utils/mixins/KeyToActionMixin.d.ts +69 -0
  58. package/dist/utils/mixins/KeyToActionMixin.js +92 -0
  59. package/dist/utils/mixins/ListNavigationMixin.d.ts +2 -1
  60. package/dist/utils/mixins/ListNavigationMixin.js +10 -33
  61. package/package.json +1 -1
@@ -11,6 +11,7 @@ import type { Events } from '../../components/checkbox/checkbox.types';
11
11
  * **Note:** This component internally renders a native checkbox input element with custom styling.
12
12
  *
13
13
  * ## When to use
14
+ *
14
15
  * Use checkboxes when users can select multiple options from a list, or when a single checkbox represents a binary choice (e.g., agreeing to terms).
15
16
  *
16
17
  * ## Accessibility
@@ -12,6 +12,7 @@ import { TAG_NAME } from '../../components/checkbox/checkbox.constants';
12
12
  * **Note:** This component internally renders a native checkbox input element with custom styling.
13
13
  *
14
14
  * ## When to use
15
+ *
15
16
  * Use checkboxes when users can select multiple options from a list, or when a single checkbox represents a binary choice (e.g., agreeing to terms).
16
17
  *
17
18
  * ## Accessibility
@@ -2,8 +2,22 @@ import { type EventName } from '@lit/react';
2
2
  import Component from '../../components/coachmark';
3
3
  import type { Events as EventsInherited } from '../../components/popover/popover.types';
4
4
  /**
5
+ * A Coachmark is a contextual guidance component used to highlight a specific UI element and explain its purpose or functionality.
6
+ * It is typically shown as part of onboarding, feature discovery, or progressive education within the product.
7
+ *
5
8
  * Coachmark component based on top of the popover component,
6
9
  * with the default value of certain properties changed.
10
+ * Coachmark component will always have an arrow attached to it.
11
+ * The color of the coachmark is contrast.
12
+ *
13
+ * ## When to use
14
+ * - Introducing a new or complex feature to users.
15
+ * - Drawing attention to a UI element that might otherwise be missed.
16
+ * - Providing step-by-step guidance in an onboarding or walkthrough flow.
17
+ *
18
+ * ## Accessibility
19
+ * - The default role of coachmark is `"dialog"`, which can be changed via the `role` attribute.
20
+ * - aria-label or aria-labelledby can be provided to give the coachmark an accessible name.
7
21
  *
8
22
  * @dependency mdc-popover
9
23
  *
@@ -25,7 +39,6 @@ import type { Events as EventsInherited } from '../../components/popover/popover
25
39
  * @cssproperty --mdc-popover-elevation-3 - elevation of the popover
26
40
  *
27
41
  * @slot - Default slot for modal container
28
- *
29
42
  */
30
43
  declare const reactWrapper: import("@lit/react").ReactWebComponent<Component, {
31
44
  onShown: EventName<EventsInherited["onShownEvent"]>;
@@ -3,8 +3,22 @@ import { createComponent } from '@lit/react';
3
3
  import Component from '../../components/coachmark';
4
4
  import { TAG_NAME } from '../../components/coachmark/coachmark.constants';
5
5
  /**
6
+ * A Coachmark is a contextual guidance component used to highlight a specific UI element and explain its purpose or functionality.
7
+ * It is typically shown as part of onboarding, feature discovery, or progressive education within the product.
8
+ *
6
9
  * Coachmark component based on top of the popover component,
7
10
  * with the default value of certain properties changed.
11
+ * Coachmark component will always have an arrow attached to it.
12
+ * The color of the coachmark is contrast.
13
+ *
14
+ * ## When to use
15
+ * - Introducing a new or complex feature to users.
16
+ * - Drawing attention to a UI element that might otherwise be missed.
17
+ * - Providing step-by-step guidance in an onboarding or walkthrough flow.
18
+ *
19
+ * ## Accessibility
20
+ * - The default role of coachmark is `"dialog"`, which can be changed via the `role` attribute.
21
+ * - aria-label or aria-labelledby can be provided to give the coachmark an accessible name.
8
22
  *
9
23
  * @dependency mdc-popover
10
24
  *
@@ -26,7 +40,6 @@ import { TAG_NAME } from '../../components/coachmark/coachmark.constants';
26
40
  * @cssproperty --mdc-popover-elevation-3 - elevation of the popover
27
41
  *
28
42
  * @slot - Default slot for modal container
29
- *
30
43
  */
31
44
  const reactWrapper = createComponent({
32
45
  tagName: TAG_NAME,
@@ -0,0 +1,69 @@
1
+ import { LitElement } from 'lit';
2
+ import type { Constructor } from './index.types';
3
+ export declare const ACTIONS: {
4
+ /** Action key, e.g., Enter */
5
+ readonly ENTER: "enter";
6
+ /** Back key, e.g., Escape/Back/Cancel */
7
+ readonly ESCAPE: "escape";
8
+ /** Navigation key up */
9
+ readonly UP: "up";
10
+ /** Navigation key down */
11
+ readonly DOWN: "down";
12
+ /** Navigation key left */
13
+ readonly LEFT: "left";
14
+ /** Navigation key right */
15
+ readonly RIGHT: "right";
16
+ /** Space key, some actions and scrolling */
17
+ readonly SPACE: "space";
18
+ /** Tab key */
19
+ readonly TAB: "tab";
20
+ /** Home key */
21
+ readonly HOME: "home";
22
+ /** End key */
23
+ readonly END: "end";
24
+ };
25
+ export type Actions = (typeof ACTIONS)[keyof typeof ACTIONS];
26
+ export interface KeyToActionInterface {
27
+ /**
28
+ * Returns a (abstract) action for the given keyboard event based on the current spatial navigation context
29
+ *
30
+ * @param evt - The keyboard event
31
+ * @param applyWritingDirection - For right-to-left writing direction, left/right actions are swapped if set to true
32
+ * @returns The mapped key or `undefined` if no mapping exists
33
+ */
34
+ getActionForKeyEvent(evt: KeyboardEvent, applyWritingDirection?: boolean): Actions | undefined;
35
+ }
36
+ /**
37
+ * Mixin to provide abstract key mapping for navigation and actions keys.
38
+ *
39
+ * Instead of using hardcoded key names this mixin provides a way to map keys to abstract actions
40
+ * and use different key mappings based on context.
41
+ *
42
+ * All components should implement this mixin if it handles keyboard events for navigation or actions,
43
+ * e.g. buttons, lists, popups, etc.
44
+ *
45
+ * Navigation keys mapped directly:
46
+ * - 'up'
47
+ * - 'down'
48
+ * - 'left'
49
+ * - 'right'
50
+ * - 'tab'
51
+ * - 'home'
52
+ * - 'end'
53
+ *
54
+ * Action keys:
55
+ * - 'action' (Enter key)
56
+ * - 'abort' (Escape/Back key)
57
+ *
58
+ * Special keys:
59
+ * - 'space' (Space key)
60
+ *
61
+ * Space is separated from action keys as it is
62
+ * - not always trigger the same action as the enter key
63
+ * - not every platform has a space key equivalent for example on a TV remote or gamepad
64
+ * - often used for scrolling as well.
65
+ *
66
+ * From the above lists only 'up', 'down', 'left', 'right', 'action' and 'abort' are mandatory to implement,
67
+ * because those are essential for spatial navigation and basic actions and all platforms have equivalents for those.
68
+ */
69
+ export declare const KeyToActionMixin: <T extends Constructor<LitElement>>(superClass: T) => Constructor<KeyToActionInterface> & T;
@@ -0,0 +1,92 @@
1
+ import { KEYS } from '../keys';
2
+ export const ACTIONS = {
3
+ /** Action key, e.g., Enter */
4
+ ENTER: 'enter',
5
+ /** Back key, e.g., Escape/Back/Cancel */
6
+ ESCAPE: 'escape',
7
+ /** Navigation key up */
8
+ UP: 'up',
9
+ /** Navigation key down */
10
+ DOWN: 'down',
11
+ /** Navigation key left */
12
+ LEFT: 'left',
13
+ /** Navigation key right */
14
+ RIGHT: 'right',
15
+ /** Space key, some actions and scrolling */
16
+ SPACE: 'space',
17
+ /** Tab key */
18
+ TAB: 'tab',
19
+ /** Home key */
20
+ HOME: 'home',
21
+ /** End key */
22
+ END: 'end',
23
+ };
24
+ /**
25
+ * Default key to action mapping if no spatial navigation context is available
26
+ */
27
+ const DEFAULT_KEY_TO_ACTION = {
28
+ [KEYS.ARROW_UP]: ACTIONS.UP,
29
+ [KEYS.ARROW_DOWN]: ACTIONS.DOWN,
30
+ [KEYS.ARROW_LEFT]: ACTIONS.LEFT,
31
+ [KEYS.ARROW_RIGHT]: ACTIONS.RIGHT,
32
+ [KEYS.ENTER]: ACTIONS.ENTER,
33
+ [KEYS.SPACE]: ACTIONS.SPACE,
34
+ [KEYS.ESCAPE]: ACTIONS.ESCAPE,
35
+ [KEYS.TAB]: ACTIONS.TAB,
36
+ [KEYS.HOME]: ACTIONS.HOME,
37
+ [KEYS.END]: ACTIONS.END,
38
+ };
39
+ /**
40
+ * Mixin to provide abstract key mapping for navigation and actions keys.
41
+ *
42
+ * Instead of using hardcoded key names this mixin provides a way to map keys to abstract actions
43
+ * and use different key mappings based on context.
44
+ *
45
+ * All components should implement this mixin if it handles keyboard events for navigation or actions,
46
+ * e.g. buttons, lists, popups, etc.
47
+ *
48
+ * Navigation keys mapped directly:
49
+ * - 'up'
50
+ * - 'down'
51
+ * - 'left'
52
+ * - 'right'
53
+ * - 'tab'
54
+ * - 'home'
55
+ * - 'end'
56
+ *
57
+ * Action keys:
58
+ * - 'action' (Enter key)
59
+ * - 'abort' (Escape/Back key)
60
+ *
61
+ * Special keys:
62
+ * - 'space' (Space key)
63
+ *
64
+ * Space is separated from action keys as it is
65
+ * - not always trigger the same action as the enter key
66
+ * - not every platform has a space key equivalent for example on a TV remote or gamepad
67
+ * - often used for scrolling as well.
68
+ *
69
+ * From the above lists only 'up', 'down', 'left', 'right', 'action' and 'abort' are mandatory to implement,
70
+ * because those are essential for spatial navigation and basic actions and all platforms have equivalents for those.
71
+ */
72
+ export const KeyToActionMixin = (superClass) => {
73
+ class InnerMixinClass extends superClass {
74
+ /** @see KeyToActionInterface.getMappedKeyFromEvent */
75
+ getActionForKeyEvent(evt, applyWritingDirection = false) {
76
+ const mapping = DEFAULT_KEY_TO_ACTION;
77
+ const key = mapping[evt.key];
78
+ if (applyWritingDirection) {
79
+ const isRtl = window.getComputedStyle(this).direction === 'rtl';
80
+ if (!isRtl)
81
+ return key;
82
+ if (key === ACTIONS.LEFT)
83
+ return ACTIONS.RIGHT;
84
+ if (key === ACTIONS.RIGHT)
85
+ return ACTIONS.LEFT;
86
+ }
87
+ return key;
88
+ }
89
+ }
90
+ // Cast return type to your mixin's interface intersected with the superClass type
91
+ return InnerMixinClass;
92
+ };
@@ -1,6 +1,7 @@
1
1
  import type { Component } from '../../models';
2
2
  import type { BaseArray } from '../virtualIndexArray';
3
3
  import type { Constructor } from './index.types';
4
+ import { KeyToActionInterface } from './KeyToActionMixin';
4
5
  export declare abstract class ListNavigationMixinInterface {
5
6
  protected loop: 'true' | 'false';
6
7
  protected propagateAllKeyEvents: boolean;
@@ -29,4 +30,4 @@ export declare abstract class ListNavigationMixinInterface {
29
30
  * ```
30
31
  * @param superClass - The class to extend with the mixin.
31
32
  */
32
- export declare const ListNavigationMixin: <T extends Constructor<Component>>(superClass: T) => Constructor<Component & ListNavigationMixinInterface> & T;
33
+ export declare const ListNavigationMixin: <T extends Constructor<Component>>(superClass: T) => Constructor<Component & ListNavigationMixinInterface & KeyToActionInterface> & T;
@@ -1,4 +1,4 @@
1
- import { KEYS } from '../keys';
1
+ import { ACTIONS, KeyToActionMixin } from './KeyToActionMixin';
2
2
  /**
3
3
  * This mixin extends the passed class with list like navigation capabilities.
4
4
  *
@@ -18,7 +18,7 @@ import { KEYS } from '../keys';
18
18
  * @param superClass - The class to extend with the mixin.
19
19
  */
20
20
  export const ListNavigationMixin = (superClass) => {
21
- class InnerMixinClass extends superClass {
21
+ class InnerMixinClass extends KeyToActionMixin(superClass) {
22
22
  constructor(...rest) {
23
23
  super(...rest);
24
24
  /**
@@ -92,10 +92,9 @@ export const ListNavigationMixin = (superClass) => {
92
92
  * @internal
93
93
  */
94
94
  handleNavigationKeyDown(event) {
95
- const keysToHandle = new Set([KEYS.ARROW_DOWN, KEYS.ARROW_UP, KEYS.HOME, KEYS.END]);
96
- const isRtl = window.getComputedStyle(this).direction === 'rtl';
97
- const targetKey = this.resolveDirectionKey(event.key, isRtl);
98
- if (!keysToHandle.has(targetKey)) {
95
+ const action = this.getActionForKeyEvent(event, true);
96
+ const actionsToHandle = new Set([ACTIONS.DOWN, ACTIONS.UP, ACTIONS.HOME, ACTIONS.END]);
97
+ if (!action || !actionsToHandle.has(action)) {
99
98
  return;
100
99
  }
101
100
  const target = event.target;
@@ -103,25 +102,25 @@ export const ListNavigationMixin = (superClass) => {
103
102
  if (currentIndex === -1)
104
103
  return;
105
104
  this.resetTabIndexes(currentIndex);
106
- switch (targetKey) {
107
- case KEYS.HOME: {
105
+ switch (action) {
106
+ case ACTIONS.HOME: {
108
107
  // Move focus to the first item
109
108
  this.resetTabIndexAndSetFocus(0, currentIndex);
110
109
  break;
111
110
  }
112
- case KEYS.END: {
111
+ case ACTIONS.END: {
113
112
  // Move focus to the last item
114
113
  this.resetTabIndexAndSetFocus(this.navItems.length - 1, currentIndex);
115
114
  break;
116
115
  }
117
- case KEYS.ARROW_DOWN: {
116
+ case ACTIONS.DOWN: {
118
117
  // Move focus to the next item
119
118
  const eolIndex = this.shouldLoop() ? 0 : currentIndex;
120
119
  const newIndex = currentIndex + 1 === this.navItems.length ? eolIndex : currentIndex + 1;
121
120
  this.resetTabIndexAndSetFocus(newIndex, currentIndex);
122
121
  break;
123
122
  }
124
- case KEYS.ARROW_UP: {
123
+ case ACTIONS.UP: {
125
124
  // Move focus to the prev item
126
125
  const eolIndex = this.shouldLoop() ? this.navItems.length - 1 : currentIndex;
127
126
  const newIndex = currentIndex - 1 === -1 ? eolIndex : currentIndex - 1;
@@ -204,28 +203,6 @@ export const ListNavigationMixin = (superClass) => {
204
203
  }
205
204
  }
206
205
  }
207
- /**
208
- * Resolves the key pressed by the user based on the direction of the layout.
209
- * This method is used to handle keyboard navigation in a right-to-left (RTL) layout.
210
- * It checks if the layout is RTL and adjusts the arrow keys accordingly.
211
- * For example, in RTL, the left arrow key behaves like the right arrow key and vice versa.
212
- *
213
- * @param key - The key pressed by the user.
214
- * @param isRtl - A boolean indicating if the layout is right-to-left (RTL).
215
- * @returns - The resolved key based on the direction.
216
- */
217
- resolveDirectionKey(key, isRtl) {
218
- if (!isRtl)
219
- return key;
220
- switch (key) {
221
- case KEYS.ARROW_LEFT:
222
- return KEYS.ARROW_RIGHT;
223
- case KEYS.ARROW_RIGHT:
224
- return KEYS.ARROW_LEFT;
225
- default:
226
- return key;
227
- }
228
- }
229
206
  shouldLoop() {
230
207
  return this.loop !== 'false';
231
208
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@momentum-design/components",
3
3
  "packageManager": "yarn@3.2.4",
4
- "version": "0.129.42",
4
+ "version": "0.129.44",
5
5
  "engines": {
6
6
  "node": ">=20.0.0",
7
7
  "npm": ">=8.0.0"