@momentum-design/components 0.129.43 → 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.
- package/dist/browser/index.js +386 -386
- package/dist/browser/index.js.map +4 -4
- package/dist/components/accordionbutton/accordionbutton.component.d.ts +1 -1
- package/dist/components/accordionbutton/accordionbutton.component.js +4 -3
- package/dist/components/buttonsimple/buttonsimple.component.d.ts +1 -1
- package/dist/components/buttonsimple/buttonsimple.component.js +8 -6
- package/dist/components/cardcheckbox/cardcheckbox.component.d.ts +1 -1
- package/dist/components/cardcheckbox/cardcheckbox.component.js +7 -5
- package/dist/components/cardradio/cardradio.component.d.ts +1 -1
- package/dist/components/cardradio/cardradio.component.js +8 -7
- package/dist/components/checkbox/checkbox.component.d.ts +2 -1
- package/dist/components/checkbox/checkbox.component.js +7 -4
- package/dist/components/combobox/combobox.component.d.ts +1 -1
- package/dist/components/combobox/combobox.component.js +11 -11
- package/dist/components/input/input.component.d.ts +1 -1
- package/dist/components/input/input.component.js +3 -3
- package/dist/components/list/list.component.d.ts +1 -1
- package/dist/components/listbox/listbox.component.d.ts +1 -1
- package/dist/components/listitem/listitem.component.d.ts +1 -1
- package/dist/components/listitem/listitem.component.js +11 -5
- package/dist/components/menubar/menubar.component.d.ts +2 -2
- package/dist/components/menubar/menubar.component.js +10 -20
- package/dist/components/menuitem/menuitem.component.js +3 -3
- package/dist/components/menupopover/menupopover.component.d.ts +0 -10
- package/dist/components/menupopover/menupopover.component.js +15 -36
- package/dist/components/popover/popover.component.d.ts +1 -1
- package/dist/components/popover/popover.component.js +3 -2
- package/dist/components/radio/radio.component.d.ts +1 -1
- package/dist/components/radio/radio.component.js +8 -7
- package/dist/components/searchfield/searchfield.component.d.ts +3 -0
- package/dist/components/searchfield/searchfield.component.js +18 -5
- package/dist/components/searchpopover/searchpopover.component.js +3 -4
- package/dist/components/select/select.component.d.ts +1 -1
- package/dist/components/select/select.component.js +9 -8
- package/dist/components/slider/slider.component.d.ts +2 -1
- package/dist/components/slider/slider.component.js +4 -3
- package/dist/components/stepperitem/stepperitem.component.d.ts +1 -1
- package/dist/components/stepperitem/stepperitem.component.js +8 -6
- package/dist/components/textarea/textarea.component.d.ts +1 -1
- package/dist/components/textarea/textarea.component.js +5 -4
- package/dist/components/toggle/toggle.component.d.ts +1 -1
- package/dist/components/toggle/toggle.component.js +5 -4
- package/dist/components/virtualizedlist/virtualizedlist.component.d.ts +1 -1
- package/dist/components/virtualizedlist/virtualizedlist.component.js +7 -6
- package/dist/custom-elements.json +1343 -202
- package/dist/react/checkbox/index.d.ts +1 -0
- package/dist/react/checkbox/index.js +1 -0
- package/dist/utils/mixins/KeyToActionMixin.d.ts +69 -0
- package/dist/utils/mixins/KeyToActionMixin.js +92 -0
- package/dist/utils/mixins/ListNavigationMixin.d.ts +2 -1
- package/dist/utils/mixins/ListNavigationMixin.js +10 -33
- 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
|
|
@@ -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 {
|
|
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
|
|
96
|
-
const
|
|
97
|
-
|
|
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 (
|
|
107
|
-
case
|
|
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
|
|
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
|
|
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
|
|
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
|
}
|