@momentum-design/components 0.95.0 → 0.95.1
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 +309 -309
- package/dist/browser/index.js.map +3 -3
- package/dist/components/option/option.component.d.ts +11 -11
- package/dist/components/option/option.component.js +12 -19
- package/dist/components/popover/popover.component.js +2 -1
- package/dist/components/select/select.component.d.ts +74 -68
- package/dist/components/select/select.component.js +287 -307
- package/dist/components/select/select.styles.js +6 -3
- package/dist/components/select/select.types.d.ts +8 -3
- package/dist/custom-elements.json +3038 -3083
- package/dist/react/index.d.ts +2 -2
- package/dist/react/index.js +2 -2
- package/dist/react/option/index.d.ts +11 -5
- package/dist/react/option/index.js +11 -5
- package/dist/react/select/index.d.ts +9 -3
- package/dist/react/select/index.js +3 -1
- package/package.json +1 -1
@@ -3,9 +3,17 @@ import type { IconNames } from '../icon/icon.types';
|
|
3
3
|
import ListItem from '../listitem/listitem.component';
|
4
4
|
declare const Option_base: import("../../utils/mixins/index.types").Constructor<import("../../utils/mixins/FormInternalsMixin").FormInternalsMixinInterface> & typeof ListItem;
|
5
5
|
/**
|
6
|
-
*
|
7
|
-
*
|
8
|
-
*
|
6
|
+
* Option component, which is used within Selectlistbox within Select component.
|
7
|
+
*
|
8
|
+
* The label and secondary label of the option can be set using the `label` and `secondaryLabel` properties respectively.
|
9
|
+
* The `label` is the primary text displayed in the option, while the `secondaryLabel` is the secondary text displayed below the primary label.
|
10
|
+
*
|
11
|
+
* The `selected` property is used to indicate whether the option is selected or not.
|
12
|
+
* When the `selected` property is set to true, a checkmark icon will be displayed
|
13
|
+
* on the right side of the option to indicate that it is selected.
|
14
|
+
*
|
15
|
+
* The `prefixIcon` property can be used to display an icon on the left side of the option label.
|
16
|
+
* We can show a tooltip by setting `tooltip-text` attribute. This will be displayed on hover or focus of the option.
|
9
17
|
* The tooltip will be helpful for a long label text which is truncated with ellipsis.
|
10
18
|
*
|
11
19
|
* @dependency mdc-icon
|
@@ -14,8 +22,6 @@ declare const Option_base: import("../../utils/mixins/index.types").Constructor<
|
|
14
22
|
*
|
15
23
|
* @tagname mdc-option
|
16
24
|
*
|
17
|
-
* @slot default - This is a default/unnamed slot
|
18
|
-
*
|
19
25
|
* @event click - (React: onClick) This event is dispatched when the option is clicked.
|
20
26
|
* @event keydown - (React: onKeyDown) This event is dispatched when a key is pressed down on the option.
|
21
27
|
* @event keyup - (React: onKeyUp) This event is dispatched when a key is released on the option.
|
@@ -35,12 +41,6 @@ declare class Option extends Option_base {
|
|
35
41
|
*/
|
36
42
|
ariaLabel: string | null;
|
37
43
|
connectedCallback(): void;
|
38
|
-
/**
|
39
|
-
* Listens to changes in the default slot and updates the label of the option accordingly.
|
40
|
-
* This is used to set the label of the option when it is not explicitly set.
|
41
|
-
* It is called internally when the slot is changed.
|
42
|
-
*/
|
43
|
-
private handleDefaultSlotChange;
|
44
44
|
update(changedProperties: PropertyValues): void;
|
45
45
|
render(): import("lit-html").TemplateResult<1>;
|
46
46
|
static styles: Array<CSSResult>;
|
@@ -17,9 +17,17 @@ import { TYPE } from '../text/text.constants';
|
|
17
17
|
import { SELECTED_ICON_NAME } from './option.constants';
|
18
18
|
import styles from './option.styles';
|
19
19
|
/**
|
20
|
-
*
|
21
|
-
*
|
22
|
-
*
|
20
|
+
* Option component, which is used within Selectlistbox within Select component.
|
21
|
+
*
|
22
|
+
* The label and secondary label of the option can be set using the `label` and `secondaryLabel` properties respectively.
|
23
|
+
* The `label` is the primary text displayed in the option, while the `secondaryLabel` is the secondary text displayed below the primary label.
|
24
|
+
*
|
25
|
+
* The `selected` property is used to indicate whether the option is selected or not.
|
26
|
+
* When the `selected` property is set to true, a checkmark icon will be displayed
|
27
|
+
* on the right side of the option to indicate that it is selected.
|
28
|
+
*
|
29
|
+
* The `prefixIcon` property can be used to display an icon on the left side of the option label.
|
30
|
+
* We can show a tooltip by setting `tooltip-text` attribute. This will be displayed on hover or focus of the option.
|
23
31
|
* The tooltip will be helpful for a long label text which is truncated with ellipsis.
|
24
32
|
*
|
25
33
|
* @dependency mdc-icon
|
@@ -28,8 +36,6 @@ import styles from './option.styles';
|
|
28
36
|
*
|
29
37
|
* @tagname mdc-option
|
30
38
|
*
|
31
|
-
* @slot default - This is a default/unnamed slot
|
32
|
-
*
|
33
39
|
* @event click - (React: onClick) This event is dispatched when the option is clicked.
|
34
40
|
* @event keydown - (React: onKeyDown) This event is dispatched when a key is pressed down on the option.
|
35
41
|
* @event keyup - (React: onKeyUp) This event is dispatched when a key is released on the option.
|
@@ -55,22 +61,9 @@ class Option extends FormInternalsMixin(ListItem) {
|
|
55
61
|
this.setAttribute('aria-disabled', `${!!this.disabled}`);
|
56
62
|
// Option will not contain below fields
|
57
63
|
this.name = undefined;
|
58
|
-
this.secondaryLabel = undefined;
|
59
64
|
this.sideHeaderText = undefined;
|
60
65
|
this.sublineText = undefined;
|
61
66
|
}
|
62
|
-
/**
|
63
|
-
* Listens to changes in the default slot and updates the label of the option accordingly.
|
64
|
-
* This is used to set the label of the option when it is not explicitly set.
|
65
|
-
* It is called internally when the slot is changed.
|
66
|
-
*/
|
67
|
-
handleDefaultSlotChange() {
|
68
|
-
var _a, _b, _c;
|
69
|
-
const slot = (_a = this.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('slot');
|
70
|
-
if (slot && !this.label) {
|
71
|
-
this.label = (_c = (_b = slot.assignedNodes()[0]) === null || _b === void 0 ? void 0 : _b.textContent) === null || _c === void 0 ? void 0 : _c.trim();
|
72
|
-
}
|
73
|
-
}
|
74
67
|
update(changedProperties) {
|
75
68
|
super.update(changedProperties);
|
76
69
|
if (changedProperties.has('selected')) {
|
@@ -92,9 +85,9 @@ class Option extends FormInternalsMixin(ListItem) {
|
|
92
85
|
${prefixIconContent}
|
93
86
|
<div part="leading-text">
|
94
87
|
${this.getText('leading-text-primary-label', TYPE.BODY_MIDSIZE_REGULAR, this.label)}
|
88
|
+
${this.getText('leading-text-secondary-label', TYPE.BODY_SMALL_REGULAR, this.secondaryLabel)}
|
95
89
|
</div>
|
96
90
|
<div part="trailing">${selectedIcon}</div>
|
97
|
-
<slot part="default-slot" @slotchange="${this.handleDefaultSlotChange}"></slot>
|
98
91
|
`;
|
99
92
|
}
|
100
93
|
}
|
@@ -278,7 +278,8 @@ class Popover extends PreventScrollMixin(FocusTrapMixin(Component)) {
|
|
278
278
|
return;
|
279
279
|
let insidePopoverClick = false;
|
280
280
|
const path = event.composedPath();
|
281
|
-
insidePopoverClick =
|
281
|
+
insidePopoverClick =
|
282
|
+
this.contains(event.target) || path.includes(this.triggerElement) || path.includes(this);
|
282
283
|
const clickedOnBackdrop = this.backdropElement ? path.includes(this.backdropElement) : false;
|
283
284
|
if (!insidePopoverClick || clickedOnBackdrop) {
|
284
285
|
this.hidePopover();
|
@@ -2,7 +2,7 @@ import type { PropertyValues } from 'lit';
|
|
2
2
|
import { CSSResult } from 'lit';
|
3
3
|
import { AssociatedFormControl } from '../../utils/mixins/FormInternalsMixin';
|
4
4
|
import FormfieldWrapper from '../formfieldwrapper/formfieldwrapper.component';
|
5
|
-
import type
|
5
|
+
import type Option from '../option/option.component';
|
6
6
|
import type { Placement } from './select.types';
|
7
7
|
declare const Select_base: import("../../utils/mixins/index.types").Constructor<import("../../utils/mixins/FormInternalsMixin").FormInternalsMixinInterface> & import("../../utils/mixins/index.types").Constructor<import("../../utils/mixins/DataAriaLabelMixin").DataAriaLabelMixinInterface> & typeof FormfieldWrapper;
|
8
8
|
/**
|
@@ -11,6 +11,8 @@ declare const Select_base: import("../../utils/mixins/index.types").Constructor<
|
|
11
11
|
* The component ensures accessibility and usability while handling various use cases,
|
12
12
|
* including long text truncation with tooltip support.
|
13
13
|
*
|
14
|
+
* Every mdc-option should have a `value` attribute set to ensure proper form submission.
|
15
|
+
*
|
14
16
|
* To set a default option, use the `selected` attribute on the `mdc-option` element.
|
15
17
|
*
|
16
18
|
* **Note:** Make sure to add `mdc-selectlistbox` as a child of `mdc-select` and wrap options/optgroup in it to ensure proper accessibility functionality. Read more about it in SelectListBox documentation.
|
@@ -23,7 +25,7 @@ declare const Select_base: import("../../utils/mixins/index.types").Constructor<
|
|
23
25
|
*
|
24
26
|
* @tagname mdc-select
|
25
27
|
*
|
26
|
-
* @slot default - This is a default/unnamed slot for options and/or option group.
|
28
|
+
* @slot default - This is a default/unnamed slot for Selectlistbox including options and/or option group.
|
27
29
|
*
|
28
30
|
* @event click - (React: onClick) This event is dispatched when the select is clicked.
|
29
31
|
* @event change - (React: onChange) This event is dispatched when the select is changed.
|
@@ -62,20 +64,24 @@ declare class Select extends Select_base implements AssociatedFormControl {
|
|
62
64
|
/** @internal */
|
63
65
|
slottedListboxes: Array<HTMLElement>;
|
64
66
|
/** @internal */
|
65
|
-
private
|
66
|
-
/** @internal */
|
67
|
-
selectedValueText?: string;
|
68
|
-
/** @internal */
|
69
|
-
selectedIcon?: IconNames | null;
|
67
|
+
private visualCombobox;
|
70
68
|
/** @internal */
|
71
|
-
|
69
|
+
selectedOption?: Option | null;
|
72
70
|
/** @internal */
|
73
71
|
displayPopover: boolean;
|
72
|
+
/** @internal */
|
73
|
+
private initialSelectedOption;
|
74
|
+
private getAllValidOptions;
|
75
|
+
private getFirstValidOption;
|
76
|
+
private getLastValidOption;
|
77
|
+
private getFirstSelectedOption;
|
74
78
|
/**
|
75
|
-
*
|
76
|
-
*
|
79
|
+
* Handles the first updated lifecycle event.
|
80
|
+
* If an option is selected, use that as the value.
|
81
|
+
* If not, use the placeholder if it exists, otherwise use the first option.
|
77
82
|
*/
|
78
|
-
|
83
|
+
firstUpdated(): Promise<void>;
|
84
|
+
updated(changedProperties: PropertyValues): void;
|
79
85
|
/**
|
80
86
|
* Modifies the listbox wrapper to ensure it has the correct attributes
|
81
87
|
* and IDs for accessibility.
|
@@ -86,43 +92,53 @@ declare class Select extends Select_base implements AssociatedFormControl {
|
|
86
92
|
*/
|
87
93
|
private modifyListBoxWrapper;
|
88
94
|
/**
|
89
|
-
* A
|
90
|
-
* It
|
91
|
-
*
|
95
|
+
* A private method which is called when an option is clicked.
|
96
|
+
* It sets the selected option, removes selected from other options, updates the tabindex for all options,
|
97
|
+
* closes the popover, and fires the change and input events.
|
98
|
+
* @param event - The event which triggered this function.
|
92
99
|
*/
|
93
|
-
private
|
100
|
+
private handleOptionsClick;
|
101
|
+
/**
|
102
|
+
* Sets the selected option in the component state and updates the input element's value.
|
103
|
+
* This method ensures that only the selected option is marked as selected in the DOM,
|
104
|
+
* and updates the tabindex for all options accordingly.
|
105
|
+
* It also updates the validity of the input element based on the selected option.
|
106
|
+
* This method is called when an option is selected.
|
107
|
+
*
|
108
|
+
* @param option - The option element in DOM which gets selected.
|
109
|
+
*/
|
110
|
+
private setSelectedOption;
|
94
111
|
/**
|
95
|
-
* Updates the tabindex
|
96
|
-
*
|
97
|
-
*
|
98
|
-
* @param
|
112
|
+
* Updates the tabindex of all options.
|
113
|
+
* Sets the tabindex of the selected option to '0' and others to '-1'.
|
114
|
+
*
|
115
|
+
* @param option - The option which tabIndex should be set to 0.
|
99
116
|
*/
|
100
117
|
private updateTabIndexForAllOptions;
|
101
118
|
/**
|
102
|
-
*
|
103
|
-
*
|
104
|
-
* @param event - The event which triggered this function.
|
119
|
+
* Sets selected attribute on the selected option and removes it from all options
|
120
|
+
* @param selectedOption - The option which gets selected
|
105
121
|
*/
|
106
|
-
private
|
122
|
+
private updateSelectedInChildOptions;
|
107
123
|
/**
|
108
|
-
*
|
109
|
-
* It
|
110
|
-
* otherwise it falls back to the option's text content.
|
111
|
-
* @param option - The option element from which to set the selected value.
|
124
|
+
* A private method which is called to fire the change and input events.
|
125
|
+
* It dispatches the input and change events with the selected option's value and label.
|
112
126
|
*/
|
113
|
-
private
|
127
|
+
private fireEvents;
|
114
128
|
/**
|
115
|
-
*
|
116
|
-
* If the
|
117
|
-
* it sets a custom
|
118
|
-
* If the
|
119
|
-
*
|
129
|
+
* Sets the validity of the input element based on the selected option.
|
130
|
+
* If the selected option is not set and the select is required,
|
131
|
+
* it sets a custom validation message.
|
132
|
+
* If the selected option is set or the select is not required,
|
133
|
+
* it clears the custom validation message.
|
134
|
+
* This method is called to ensure that the select component behaves correctly
|
135
|
+
* in form validation scenarios, especially when the select is required.
|
120
136
|
* @internal
|
121
137
|
*/
|
122
|
-
private
|
138
|
+
private setInputValidity;
|
123
139
|
/**
|
140
|
+
* Resets the select to its initially selected option.
|
124
141
|
* @internal
|
125
|
-
* Resets the select to its initial state.
|
126
142
|
*/
|
127
143
|
formResetCallback(): void;
|
128
144
|
/** @internal */
|
@@ -130,15 +146,12 @@ declare class Select extends Select_base implements AssociatedFormControl {
|
|
130
146
|
private dispatchChange;
|
131
147
|
private dispatchInput;
|
132
148
|
/**
|
133
|
-
* Handles the
|
134
|
-
*
|
135
|
-
*
|
136
|
-
*
|
137
|
-
*
|
138
|
-
* - ARROW_DOWN, ARROW_UP, PAGE_DOWN, PAGE_UP: Handles navigation between options.
|
139
|
-
* @param event - The keyboard event.
|
149
|
+
* Handles the click event on the visual combobox.
|
150
|
+
* If the select is disabled, soft-disabled or readonly, it does nothing.
|
151
|
+
* If the popover is already open, it closes it.
|
152
|
+
* If it is closed, it opens it.
|
153
|
+
* @param event - The mouse event which triggered this function.
|
140
154
|
*/
|
141
|
-
private handlePopoverOnOpen;
|
142
155
|
private handleClickCombobox;
|
143
156
|
/**
|
144
157
|
* Handles the keydown event on the select element when the popover is closed.
|
@@ -151,36 +164,29 @@ declare class Select extends Select_base implements AssociatedFormControl {
|
|
151
164
|
*/
|
152
165
|
private handleKeydownCombobox;
|
153
166
|
/**
|
154
|
-
* Handles the
|
155
|
-
*
|
156
|
-
*
|
167
|
+
* Handles the keydown event on the select element when the popover is open.
|
168
|
+
* The options are as follows:
|
169
|
+
* - HOME: Sets focus and tabindex on the first option.
|
170
|
+
* - END: Sets focus and tabindex on the last option.
|
171
|
+
* - ARROW_DOWN, ARROW_UP, PAGE_DOWN, PAGE_UP: Handles navigation between options.
|
172
|
+
* @param event - The keyboard event.
|
157
173
|
*/
|
158
|
-
private
|
174
|
+
private handlePopoverKeydown;
|
159
175
|
/**
|
160
|
-
*
|
161
|
-
*
|
162
|
-
*
|
163
|
-
* - ArrowUp: Moves focus to the previous option, if available.
|
164
|
-
* - PageDown: Moves focus 10 options down or to the last option.
|
165
|
-
* - PageUp: Moves focus 10 options up or to the first option.
|
166
|
-
*
|
167
|
-
* @param key - The navigation key that was pressed.
|
168
|
-
* @param currentIndex - The current index of the focused option.
|
169
|
-
* @param optionsLength - The total number of options.
|
170
|
-
* @returns The new index to focus on, or -1 if no movement is possible.
|
176
|
+
* Focuses the given option and updates the tabindex for all options.
|
177
|
+
* @param option - The option to focus.
|
178
|
+
* @internal
|
171
179
|
*/
|
172
|
-
private
|
173
|
-
private setFocusAndTabIndex;
|
174
|
-
private openPopover;
|
175
|
-
private closePopover;
|
180
|
+
private focusAndUpdateTabIndexes;
|
176
181
|
/**
|
177
|
-
*
|
178
|
-
*
|
179
|
-
*
|
182
|
+
* If the native input is focused, it will focus the visual combobox.
|
183
|
+
* This is to ensure that the visual combobox is focused when the native input is focused.
|
184
|
+
* For example when a form is submitted and the native input is focused,
|
185
|
+
* we want to focus the visual combobox so that the user can see the selected option
|
186
|
+
* and can interact with it.
|
187
|
+
* @internal
|
180
188
|
*/
|
181
|
-
|
182
|
-
updated(changedProperties: PropertyValues): void;
|
183
|
-
private handleOnChange;
|
189
|
+
private handleNativeInputFocus;
|
184
190
|
render(): import("lit-html").TemplateResult<1>;
|
185
191
|
static styles: Array<CSSResult>;
|
186
192
|
}
|