@momentum-design/components 0.66.1 → 0.66.2
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 +203 -196
- package/dist/browser/index.js.map +4 -4
- package/dist/components/formfieldgroup/formfieldgroup.component.js +1 -1
- package/dist/components/formfieldgroup/formfieldgroup.constants.d.ts +1 -5
- package/dist/components/formfieldgroup/formfieldgroup.constants.js +1 -5
- package/dist/components/list/list.component.d.ts +3 -0
- package/dist/components/list/list.component.js +5 -2
- package/dist/components/listitem/index.d.ts +1 -0
- package/dist/components/listitem/index.js +1 -0
- package/dist/components/listitem/listitem.component.d.ts +30 -1
- package/dist/components/listitem/listitem.component.js +65 -3
- package/dist/components/listitem/listitem.constants.d.ts +4 -1
- package/dist/components/listitem/listitem.constants.js +5 -1
- package/dist/components/listitem/listitem.styles.js +20 -8
- package/dist/components/menuitem/index.d.ts +1 -0
- package/dist/components/menuitem/index.js +1 -0
- package/dist/components/menuitem/menuitem.component.js +2 -1
- package/dist/components/option/option.component.d.ts +3 -14
- package/dist/components/option/option.component.js +3 -54
- package/dist/components/option/option.constants.d.ts +1 -2
- package/dist/components/option/option.constants.js +1 -2
- package/dist/components/option/option.styles.js +0 -5
- package/dist/components/tooltip/tooltip.component.d.ts +1 -1
- package/dist/components/tooltip/tooltip.component.js +7 -6
- package/dist/custom-elements.json +3647 -3402
- package/dist/react/index.d.ts +7 -7
- package/dist/react/index.js +7 -7
- package/dist/react/listitem/index.d.ts +6 -0
- package/dist/react/listitem/index.js +6 -0
- package/dist/react/option/index.d.ts +2 -0
- package/dist/react/option/index.js +2 -0
- package/dist/utils/roles.d.ts +17 -0
- package/dist/utils/roles.js +16 -0
- package/package.json +1 -1
@@ -1,8 +1,8 @@
|
|
1
1
|
import { html } from 'lit';
|
2
2
|
import { ifDefined } from 'lit/directives/if-defined.js';
|
3
3
|
import { DataAriaLabelMixin } from '../../utils/mixins/DataAriaLabelMixin';
|
4
|
+
import { ROLE } from '../../utils/roles';
|
4
5
|
import FormfieldWrapper from '../formfieldwrapper/formfieldwrapper.component';
|
5
|
-
import { ROLE } from './formfieldgroup.constants';
|
6
6
|
import { DEFAULTS as FORMFIELD_DEFAULTS } from '../formfieldwrapper/formfieldwrapper.constants';
|
7
7
|
import styles from './formfieldgroup.styles';
|
8
8
|
/**
|
@@ -1,5 +1,6 @@
|
|
1
1
|
import type { CSSResult } from 'lit';
|
2
2
|
import { Component } from '../../models';
|
3
|
+
import type { RoleType } from '../../utils/roles';
|
3
4
|
declare const List_base: import("../../utils/mixins/index.types").Constructor<import("../../utils/mixins/DataAriaLabelMixin").DataAriaLabelMixinInterface> & typeof Component;
|
4
5
|
/**
|
5
6
|
* mdc-list component is used to display a group of list items. It is used as a container to wrap other list items.
|
@@ -20,6 +21,8 @@ declare class List extends List_base {
|
|
20
21
|
* The header text of the list.
|
21
22
|
*/
|
22
23
|
headerText?: string;
|
24
|
+
/** @internal */
|
25
|
+
protected dataRole: RoleType;
|
23
26
|
constructor();
|
24
27
|
/**
|
25
28
|
* Handles the keydown event on the list element.
|
@@ -10,12 +10,13 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
10
10
|
import { html, nothing } from 'lit';
|
11
11
|
import { property, queryAssignedElements } from 'lit/decorators.js';
|
12
12
|
import { Component } from '../../models';
|
13
|
+
import { KEYS } from '../../utils/keys';
|
13
14
|
import { DataAriaLabelMixin } from '../../utils/mixins/DataAriaLabelMixin';
|
15
|
+
import { ROLE } from '../../utils/roles';
|
14
16
|
import { TAG_NAME as LISTITEM_TAGNAME } from '../listitem/listitem.constants';
|
15
17
|
import { TYPE, VALID_TEXT_TAGS } from '../text/text.constants';
|
16
18
|
import { HEADER_ID } from './list.constants';
|
17
19
|
import styles from './list.styles';
|
18
|
-
import { KEYS } from '../../utils/keys';
|
19
20
|
/**
|
20
21
|
* mdc-list component is used to display a group of list items. It is used as a container to wrap other list items.
|
21
22
|
*
|
@@ -28,6 +29,8 @@ import { KEYS } from '../../utils/keys';
|
|
28
29
|
class List extends DataAriaLabelMixin(Component) {
|
29
30
|
constructor() {
|
30
31
|
super();
|
32
|
+
/** @internal */
|
33
|
+
this.dataRole = ROLE.LIST;
|
31
34
|
this.addEventListener('keydown', this.handleKeyDown);
|
32
35
|
}
|
33
36
|
/**
|
@@ -117,7 +120,7 @@ class List extends DataAriaLabelMixin(Component) {
|
|
117
120
|
` : nothing;
|
118
121
|
return html `
|
119
122
|
<div
|
120
|
-
role="
|
123
|
+
role="${this.dataRole}"
|
121
124
|
aria-labelledby="${this.headerText ? HEADER_ID : ''}"
|
122
125
|
aria-label="${(_a = this.dataAriaLabel) !== null && _a !== void 0 ? _a : ''}"
|
123
126
|
>
|
@@ -1,7 +1,8 @@
|
|
1
1
|
import type { CSSResult, PropertyValues, TemplateResult } from 'lit';
|
2
2
|
import { nothing } from 'lit';
|
3
3
|
import { Component } from '../../models';
|
4
|
-
import {
|
4
|
+
import type { PopoverPlacement } from '../popover/popover.types';
|
5
|
+
import type { TextType } from '../text/text.types';
|
5
6
|
import type { ListItemVariants } from './listitem.types';
|
6
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;
|
7
8
|
/**
|
@@ -15,6 +16,11 @@ declare const ListItem_base: import("../../utils/mixins/index.types").Constructo
|
|
15
16
|
* Based on the leading/trailing slot, the position of the controls and text can be adjusted. <br/>
|
16
17
|
* Please use mdc-list as a parent element even when there is only listitem for a11y purpose.
|
17
18
|
*
|
19
|
+
* By providing the tooltip-text attribute, a tooltip will be displayed on hover of the listitem.
|
20
|
+
* The placement of the tooltip can be adjusted using the tooltip-placement attribute.
|
21
|
+
* This will be helpful when the listitem text is truncated or
|
22
|
+
* when you want to display additional information about the listitem.
|
23
|
+
*
|
18
24
|
* @tagname mdc-listitem
|
19
25
|
*
|
20
26
|
* @dependency mdc-text
|
@@ -36,6 +42,7 @@ declare const ListItem_base: import("../../utils/mixins/index.types").Constructo
|
|
36
42
|
* - Allows customization of the secondary and tertiary label text slot color.
|
37
43
|
* @cssproperty --mdc-listitem-disabled-color - Allows customization of the disabled color.
|
38
44
|
* @cssproperty --mdc-listitem-column-gap - Allows customization of column gap.
|
45
|
+
* @cssproperty --mdc-listitem-padding-left-and-right - Allows customization of padding left and right.
|
39
46
|
*
|
40
47
|
* @event click - (React: onClick) This event is dispatched when the listitem is clicked.
|
41
48
|
* @event keydown - (React: onKeyDown) This event is dispatched when a key is pressed down on the listitem.
|
@@ -77,7 +84,29 @@ declare class ListItem extends ListItem_base {
|
|
77
84
|
* This appears on the trailing side of the list item.
|
78
85
|
*/
|
79
86
|
sublineText?: string;
|
87
|
+
/**
|
88
|
+
* The tooltip text is displayed on hover of the list item.
|
89
|
+
*/
|
90
|
+
tooltipText?: string;
|
91
|
+
/**
|
92
|
+
* The tooltip placement of the list item. If the tooltip text is present,
|
93
|
+
* then this tooltip placement will be applied.
|
94
|
+
* @default 'top'
|
95
|
+
*/
|
96
|
+
tooltipPlacement: PopoverPlacement;
|
97
|
+
constructor();
|
80
98
|
connectedCallback(): void;
|
99
|
+
private handleClick;
|
100
|
+
/**
|
101
|
+
* Display a tooltip for the listitem.
|
102
|
+
* Create the tooltip programmatically after the nearest parent element.
|
103
|
+
*/
|
104
|
+
private displayTooltipForLongText;
|
105
|
+
/**
|
106
|
+
* Removes the dynamically created tooltip for long text label on focus or mouse leave.
|
107
|
+
* This is triggered on focusout and mouseout events.
|
108
|
+
*/
|
109
|
+
private hideTooltipOnLeave;
|
81
110
|
/**
|
82
111
|
* Generates a template for a text slot with the specified content.
|
83
112
|
*
|
@@ -12,8 +12,10 @@ import { property, queryAssignedElements } from 'lit/decorators.js';
|
|
12
12
|
import { Component } from '../../models';
|
13
13
|
import { DisabledMixin } from '../../utils/mixins/DisabledMixin';
|
14
14
|
import { TabIndexMixin } from '../../utils/mixins/TabIndexMixin';
|
15
|
+
import { ROLE } from '../../utils/roles';
|
15
16
|
import { TYPE, VALID_TEXT_TAGS } from '../text/text.constants';
|
16
|
-
import {
|
17
|
+
import { TAG_NAME as TOOLTIP_TAG_NAME } from '../tooltip/tooltip.constants';
|
18
|
+
import { DEFAULTS, LISTITEM_ID, TOOLTIP_ID } from './listitem.constants';
|
17
19
|
import styles from './listitem.styles';
|
18
20
|
/**
|
19
21
|
* mdc-listitem component is used to display a label with different types of controls.
|
@@ -26,6 +28,11 @@ import styles from './listitem.styles';
|
|
26
28
|
* Based on the leading/trailing slot, the position of the controls and text can be adjusted. <br/>
|
27
29
|
* Please use mdc-list as a parent element even when there is only listitem for a11y purpose.
|
28
30
|
*
|
31
|
+
* By providing the tooltip-text attribute, a tooltip will be displayed on hover of the listitem.
|
32
|
+
* The placement of the tooltip can be adjusted using the tooltip-placement attribute.
|
33
|
+
* This will be helpful when the listitem text is truncated or
|
34
|
+
* when you want to display additional information about the listitem.
|
35
|
+
*
|
29
36
|
* @tagname mdc-listitem
|
30
37
|
*
|
31
38
|
* @dependency mdc-text
|
@@ -47,6 +54,7 @@ import styles from './listitem.styles';
|
|
47
54
|
* - Allows customization of the secondary and tertiary label text slot color.
|
48
55
|
* @cssproperty --mdc-listitem-disabled-color - Allows customization of the disabled color.
|
49
56
|
* @cssproperty --mdc-listitem-column-gap - Allows customization of column gap.
|
57
|
+
* @cssproperty --mdc-listitem-padding-left-and-right - Allows customization of padding left and right.
|
50
58
|
*
|
51
59
|
* @event click - (React: onClick) This event is dispatched when the listitem is clicked.
|
52
60
|
* @event keydown - (React: onKeyDown) This event is dispatched when a key is pressed down on the listitem.
|
@@ -55,16 +63,62 @@ import styles from './listitem.styles';
|
|
55
63
|
*/
|
56
64
|
class ListItem extends DisabledMixin(TabIndexMixin(Component)) {
|
57
65
|
constructor() {
|
58
|
-
super(
|
66
|
+
super();
|
59
67
|
/**
|
60
68
|
* The variant of the list item. It can be a pill, rectangle or a full-width.
|
61
69
|
* @default 'full-width'
|
62
70
|
*/
|
63
71
|
this.variant = DEFAULTS.VARIANT;
|
72
|
+
/**
|
73
|
+
* The tooltip placement of the list item. If the tooltip text is present,
|
74
|
+
* then this tooltip placement will be applied.
|
75
|
+
* @default 'top'
|
76
|
+
*/
|
77
|
+
this.tooltipPlacement = DEFAULTS.TOOLTIP_PLACEMENT;
|
78
|
+
this.addEventListener('focusin', this.displayTooltipForLongText);
|
79
|
+
this.addEventListener('mouseover', this.displayTooltipForLongText);
|
80
|
+
this.addEventListener('focusout', this.hideTooltipOnLeave);
|
81
|
+
this.addEventListener('mouseout', this.hideTooltipOnLeave);
|
82
|
+
this.addEventListener('click', this.handleClick);
|
64
83
|
}
|
65
84
|
connectedCallback() {
|
66
85
|
super.connectedCallback();
|
67
|
-
this.role = this.role ||
|
86
|
+
this.role = this.role || ROLE.LISTITEM;
|
87
|
+
}
|
88
|
+
handleClick() {
|
89
|
+
// If the tooltip is open, it has to be closed first.
|
90
|
+
this.hideTooltipOnLeave();
|
91
|
+
}
|
92
|
+
/**
|
93
|
+
* Display a tooltip for the listitem.
|
94
|
+
* Create the tooltip programmatically after the nearest parent element.
|
95
|
+
*/
|
96
|
+
displayTooltipForLongText() {
|
97
|
+
var _a;
|
98
|
+
if (!this.tooltipText) {
|
99
|
+
return;
|
100
|
+
}
|
101
|
+
// Add a unique id to the listitem if it does not have one to attach the tooltip.
|
102
|
+
this.id = this.id || LISTITEM_ID;
|
103
|
+
// Create tooltip for the listitem element.
|
104
|
+
const tooltip = document.createElement(TOOLTIP_TAG_NAME);
|
105
|
+
tooltip.id = TOOLTIP_ID;
|
106
|
+
tooltip.textContent = this.tooltipText;
|
107
|
+
tooltip.setAttribute('triggerid', this.id);
|
108
|
+
tooltip.setAttribute('placement', this.tooltipPlacement);
|
109
|
+
tooltip.setAttribute('visible', '');
|
110
|
+
tooltip.setAttribute('show-arrow', '');
|
111
|
+
// Add tooltip programmatically after the parent element.
|
112
|
+
(_a = this.parentElement) === null || _a === void 0 ? void 0 : _a.after(tooltip);
|
113
|
+
}
|
114
|
+
/**
|
115
|
+
* Removes the dynamically created tooltip for long text label on focus or mouse leave.
|
116
|
+
* This is triggered on focusout and mouseout events.
|
117
|
+
*/
|
118
|
+
hideTooltipOnLeave() {
|
119
|
+
this.id = this.id === LISTITEM_ID ? '' : this.id;
|
120
|
+
const existingTooltip = document.querySelector(`#${TOOLTIP_ID}`);
|
121
|
+
existingTooltip === null || existingTooltip === void 0 ? void 0 : existingTooltip.remove();
|
68
122
|
}
|
69
123
|
/**
|
70
124
|
* Generates a template for a text slot with the specified content.
|
@@ -160,4 +214,12 @@ __decorate([
|
|
160
214
|
property({ type: String, reflect: true, attribute: 'subline-text' }),
|
161
215
|
__metadata("design:type", String)
|
162
216
|
], ListItem.prototype, "sublineText", void 0);
|
217
|
+
__decorate([
|
218
|
+
property({ type: String, reflect: true, attribute: 'tooltip-text' }),
|
219
|
+
__metadata("design:type", String)
|
220
|
+
], ListItem.prototype, "tooltipText", void 0);
|
221
|
+
__decorate([
|
222
|
+
property({ type: String, reflect: true, attribute: 'tooltip-placement' }),
|
223
|
+
__metadata("design:type", String)
|
224
|
+
], ListItem.prototype, "tooltipPlacement", void 0);
|
163
225
|
export default ListItem;
|
@@ -1,4 +1,6 @@
|
|
1
1
|
declare const TAG_NAME: "mdc-listitem";
|
2
|
+
declare const TOOLTIP_ID = "dynamic-listitem-tooltip-popover";
|
3
|
+
declare const LISTITEM_ID = "dynamic-listitem-tooltip-triggerid";
|
2
4
|
declare const LISTITEM_VARIANTS: {
|
3
5
|
readonly FULL_WIDTH: "full-width";
|
4
6
|
readonly INSET_PILL: "inset-pill";
|
@@ -6,5 +8,6 @@ declare const LISTITEM_VARIANTS: {
|
|
6
8
|
};
|
7
9
|
declare const DEFAULTS: {
|
8
10
|
readonly VARIANT: "full-width";
|
11
|
+
readonly TOOLTIP_PLACEMENT: "top";
|
9
12
|
};
|
10
|
-
export { DEFAULTS, TAG_NAME, LISTITEM_VARIANTS };
|
13
|
+
export { DEFAULTS, TAG_NAME, LISTITEM_VARIANTS, TOOLTIP_ID, LISTITEM_ID };
|
@@ -1,5 +1,8 @@
|
|
1
1
|
import utils from '../../utils/tag-name';
|
2
|
+
import { POPOVER_PLACEMENT } from '../popover/popover.constants';
|
2
3
|
const TAG_NAME = utils.constructTagName('listitem');
|
4
|
+
const TOOLTIP_ID = 'dynamic-listitem-tooltip-popover';
|
5
|
+
const LISTITEM_ID = 'dynamic-listitem-tooltip-triggerid';
|
3
6
|
const LISTITEM_VARIANTS = {
|
4
7
|
FULL_WIDTH: 'full-width',
|
5
8
|
INSET_PILL: 'inset-pill',
|
@@ -7,5 +10,6 @@ const LISTITEM_VARIANTS = {
|
|
7
10
|
};
|
8
11
|
const DEFAULTS = {
|
9
12
|
VARIANT: LISTITEM_VARIANTS.FULL_WIDTH,
|
13
|
+
TOOLTIP_PLACEMENT: POPOVER_PLACEMENT.TOP,
|
10
14
|
};
|
11
|
-
export { DEFAULTS, TAG_NAME, LISTITEM_VARIANTS };
|
15
|
+
export { DEFAULTS, TAG_NAME, LISTITEM_VARIANTS, TOOLTIP_ID, LISTITEM_ID };
|
@@ -9,6 +9,7 @@ const styles = css `
|
|
9
9
|
--mdc-listitem-secondary-label-color: var(--mds-color-theme-text-secondary-normal);
|
10
10
|
--mdc-listitem-disabled-color: var(--mds-color-theme-text-primary-disabled);
|
11
11
|
--mdc-listitem-column-gap: 0.75rem;
|
12
|
+
--mdc-listitem-padding-left-and-right: 0.75rem;
|
12
13
|
}
|
13
14
|
:host {
|
14
15
|
background-color: var(--mdc-listitem-default-background-color);
|
@@ -16,7 +17,7 @@ const styles = css `
|
|
16
17
|
cursor: pointer;
|
17
18
|
display: flex;
|
18
19
|
flex-direction: row;
|
19
|
-
padding: 0.5rem
|
20
|
+
padding: 0.5rem var(--mdc-listitem-padding-left-and-right);
|
20
21
|
width: 100%;
|
21
22
|
}
|
22
23
|
:host([variant="inset-rectangle"]) {
|
@@ -25,6 +26,20 @@ const styles = css `
|
|
25
26
|
:host([variant="inset-pill"]) {
|
26
27
|
border-radius: 3.125rem;
|
27
28
|
}
|
29
|
+
:host::part(leading-text) {
|
30
|
+
flex: 1;
|
31
|
+
/** 2x of column gap on both ends of the listitem - 100% width */
|
32
|
+
width: calc(100% - (2 * var(--mdc-listitem-padding-left-and-right)));
|
33
|
+
}
|
34
|
+
:host::part(leading-text-primary-label),
|
35
|
+
:host::part(leading-text-secondary-label),
|
36
|
+
:host::part(leading-text-tertiary-label),
|
37
|
+
:host::part(trailing-text-side-header),
|
38
|
+
:host::part(trailing-text-subline) {
|
39
|
+
overflow: hidden;
|
40
|
+
text-overflow: ellipsis;
|
41
|
+
white-space: nowrap;
|
42
|
+
}
|
28
43
|
:host([disabled]),
|
29
44
|
:host([disabled]:hover),
|
30
45
|
:host([disabled]:active),
|
@@ -43,17 +58,14 @@ const styles = css `
|
|
43
58
|
:host(:active) {
|
44
59
|
background-color: var(--mdc-listitem-background-color-active);
|
45
60
|
}
|
46
|
-
:host::part(trailing) {
|
47
|
-
margin-left: auto;
|
48
|
-
}
|
49
|
-
:host::part(trailing):dir(rtl) {
|
50
|
-
margin-left: unset;
|
51
|
-
margin-right: auto;
|
52
|
-
}
|
53
61
|
:host::part(leading), :host::part(trailing) {
|
54
62
|
align-items: center;
|
55
63
|
column-gap: var(--mdc-listitem-column-gap);
|
56
64
|
display: flex;
|
65
|
+
width: 100%;
|
66
|
+
}
|
67
|
+
:host::part(trailing) {
|
68
|
+
justify-content: flex-end;
|
57
69
|
}
|
58
70
|
:host::part(leading-text-secondary-label), :host::part(leading-text-tertiary-label) {
|
59
71
|
color: var(--mdc-listitem-secondary-label-color);
|
@@ -1,3 +1,4 @@
|
|
1
|
+
import { ROLE } from '../../utils/roles';
|
1
2
|
import ListItem from '../listitem/listitem.component';
|
2
3
|
import { LISTITEM_VARIANTS } from '../listitem/listitem.constants';
|
3
4
|
/**
|
@@ -21,7 +22,7 @@ import { LISTITEM_VARIANTS } from '../listitem/listitem.constants';
|
|
21
22
|
class MenuItem extends ListItem {
|
22
23
|
connectedCallback() {
|
23
24
|
super.connectedCallback();
|
24
|
-
this.role =
|
25
|
+
this.role = ROLE.MENUITEM;
|
25
26
|
this.variant = LISTITEM_VARIANTS.INSET_RECTANGLE;
|
26
27
|
}
|
27
28
|
}
|
@@ -1,10 +1,12 @@
|
|
1
|
-
import { CSSResult, PropertyValues } from 'lit';
|
1
|
+
import type { CSSResult, PropertyValues } from 'lit';
|
2
2
|
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
6
|
* option component, which is used as a list item in a select component.<br/>
|
7
7
|
* We can pass an icon which will be displayed in leading position of the option label text.
|
8
|
+
* We can pass a tooltip which will be displayed on hover of the option label text.
|
9
|
+
* The tooltip will be helpful for a long label text which is truncated with ellipsis.
|
8
10
|
*
|
9
11
|
* @dependency mdc-icon
|
10
12
|
* @dependency mdc-text
|
@@ -33,19 +35,6 @@ declare class Option extends Option_base {
|
|
33
35
|
*/
|
34
36
|
ariaLabel: string | null;
|
35
37
|
connectedCallback(): void;
|
36
|
-
disconnectedCallback(): void;
|
37
|
-
private handleClick;
|
38
|
-
/**
|
39
|
-
* Display a tooltip for long text label with an ellipse at the end.
|
40
|
-
* Create the tooltip programmatically after the nearest select component or the parent element.
|
41
|
-
* @param event - A focus or a mouse event.
|
42
|
-
*/
|
43
|
-
private displayTooltipForLongText;
|
44
|
-
/**
|
45
|
-
* Removes the dynamically created tooltip for long text label on focus or mouse leave.
|
46
|
-
* This is triggered on focusout and mouseout events.
|
47
|
-
*/
|
48
|
-
private hideTooltipOnLeave;
|
49
38
|
/**
|
50
39
|
* Listens to changes in the default slot and updates the label of the option accordingly.
|
51
40
|
* This is used to set the label of the option when it is not explicitly set.
|
@@ -13,14 +13,14 @@ import { ifDefined } from 'lit/directives/if-defined.js';
|
|
13
13
|
import { FormInternalsMixin } from '../../utils/mixins/FormInternalsMixin';
|
14
14
|
import ListItem from '../listitem/listitem.component';
|
15
15
|
import { LISTITEM_VARIANTS } from '../listitem/listitem.constants';
|
16
|
-
import { TAG_NAME as SELECT_TAG_NAME } from '../select/select.constants';
|
17
16
|
import { TYPE } from '../text/text.constants';
|
18
|
-
import {
|
19
|
-
import { SELECTED_ICON_NAME, TOOLTIP_ID } from './option.constants';
|
17
|
+
import { SELECTED_ICON_NAME } from './option.constants';
|
20
18
|
import styles from './option.styles';
|
21
19
|
/**
|
22
20
|
* option component, which is used as a list item in a select component.<br/>
|
23
21
|
* We can pass an icon which will be displayed in leading position of the option label text.
|
22
|
+
* We can pass a tooltip which will be displayed on hover of the option label text.
|
23
|
+
* The tooltip will be helpful for a long label text which is truncated with ellipsis.
|
24
24
|
*
|
25
25
|
* @dependency mdc-icon
|
26
26
|
* @dependency mdc-text
|
@@ -58,57 +58,6 @@ class Option extends FormInternalsMixin(ListItem) {
|
|
58
58
|
this.secondaryLabel = undefined;
|
59
59
|
this.sideHeaderText = undefined;
|
60
60
|
this.sublineText = undefined;
|
61
|
-
this.addEventListener('focusin', this.displayTooltipForLongText);
|
62
|
-
this.addEventListener('mouseover', this.displayTooltipForLongText);
|
63
|
-
this.addEventListener('focusout', this.hideTooltipOnLeave);
|
64
|
-
this.addEventListener('mouseout', this.hideTooltipOnLeave);
|
65
|
-
this.addEventListener('click', this.handleClick);
|
66
|
-
}
|
67
|
-
disconnectedCallback() {
|
68
|
-
super.disconnectedCallback();
|
69
|
-
this.removeEventListener('focusin', this.displayTooltipForLongText);
|
70
|
-
this.removeEventListener('mouseover', this.displayTooltipForLongText);
|
71
|
-
this.removeEventListener('focusout', this.hideTooltipOnLeave);
|
72
|
-
this.removeEventListener('mouseout', this.hideTooltipOnLeave);
|
73
|
-
this.removeEventListener('click', this.handleClick);
|
74
|
-
}
|
75
|
-
handleClick() {
|
76
|
-
// When the select dropdown (popover) is open,
|
77
|
-
// then if the tooltip is open, it has to be closed first.
|
78
|
-
// only then we can close the dropdown on option click/select.
|
79
|
-
this.hideTooltipOnLeave();
|
80
|
-
}
|
81
|
-
/**
|
82
|
-
* Display a tooltip for long text label with an ellipse at the end.
|
83
|
-
* Create the tooltip programmatically after the nearest select component or the parent element.
|
84
|
-
* @param event - A focus or a mouse event.
|
85
|
-
*/
|
86
|
-
displayTooltipForLongText(event) {
|
87
|
-
var _a, _b;
|
88
|
-
const dimensions = (_a = event.target.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('[part="leading-text-primary-label"]');
|
89
|
-
if (dimensions && dimensions.scrollWidth && dimensions.clientWidth
|
90
|
-
&& dimensions.scrollWidth <= (dimensions === null || dimensions === void 0 ? void 0 : dimensions.clientWidth)) {
|
91
|
-
// it means that the option label text is fully visible and we do not need to show the tooltip.
|
92
|
-
return;
|
93
|
-
}
|
94
|
-
// Create tooltip for long text label which has an ellipse at the end.
|
95
|
-
const tooltip = document.createElement(TOOLTIP_TAG_NAME);
|
96
|
-
tooltip.id = TOOLTIP_ID;
|
97
|
-
tooltip.textContent = (_b = this.label) !== null && _b !== void 0 ? _b : '';
|
98
|
-
tooltip.setAttribute('triggerid', this.id);
|
99
|
-
tooltip.setAttribute('visible', '');
|
100
|
-
tooltip.setAttribute('show-arrow', '');
|
101
|
-
// Add tooltip programmatically after the nearest select component or the parent element.
|
102
|
-
const parent = this.closest(SELECT_TAG_NAME) || this.parentElement;
|
103
|
-
parent === null || parent === void 0 ? void 0 : parent.after(tooltip);
|
104
|
-
}
|
105
|
-
/**
|
106
|
-
* Removes the dynamically created tooltip for long text label on focus or mouse leave.
|
107
|
-
* This is triggered on focusout and mouseout events.
|
108
|
-
*/
|
109
|
-
hideTooltipOnLeave() {
|
110
|
-
const existingTooltip = document.querySelector(`#${TOOLTIP_ID}`);
|
111
|
-
existingTooltip === null || existingTooltip === void 0 ? void 0 : existingTooltip.remove();
|
112
61
|
}
|
113
62
|
/**
|
114
63
|
* Listens to changes in the default slot and updates the label of the option accordingly.
|
@@ -1,5 +1,4 @@
|
|
1
1
|
import type { IconNames } from '../icon/icon.types';
|
2
2
|
declare const SELECTED_ICON_NAME: Extract<IconNames, 'check-bold'>;
|
3
|
-
declare const TOOLTIP_ID = "dynamic-option-tooltip-popover";
|
4
3
|
declare const TAG_NAME: "mdc-option";
|
5
|
-
export { SELECTED_ICON_NAME, TAG_NAME
|
4
|
+
export { SELECTED_ICON_NAME, TAG_NAME };
|
@@ -1,5 +1,4 @@
|
|
1
1
|
import utils from '../../utils/tag-name';
|
2
2
|
const SELECTED_ICON_NAME = 'check-bold';
|
3
|
-
const TOOLTIP_ID = 'dynamic-option-tooltip-popover';
|
4
3
|
const TAG_NAME = utils.constructTagName('option');
|
5
|
-
export { SELECTED_ICON_NAME, TAG_NAME
|
4
|
+
export { SELECTED_ICON_NAME, TAG_NAME };
|
@@ -23,10 +23,5 @@ const styles = css `
|
|
23
23
|
/** 2x of leading and trailing icon width + 2x of column gap on both sides of the label text */
|
24
24
|
width: calc(100% - (2 * var(--mdc-option-icon-width)) - (2 * var(--mdc-listitem-column-gap)));
|
25
25
|
}
|
26
|
-
:host::part(leading-text-primary-label) {
|
27
|
-
overflow: hidden;
|
28
|
-
text-overflow: ellipsis;
|
29
|
-
white-space: nowrap;
|
30
|
-
}
|
31
26
|
`;
|
32
27
|
export default [styles];
|
@@ -9,10 +9,11 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
9
|
};
|
10
10
|
import { property, queryAssignedNodes } from 'lit/decorators.js';
|
11
11
|
import { v4 as uuidv4 } from 'uuid';
|
12
|
-
import {
|
12
|
+
import { ROLE } from '../../utils/roles';
|
13
13
|
import Popover from '../popover/popover.component';
|
14
|
-
import styles from './tooltip.styles';
|
15
14
|
import { POPOVER_PLACEMENT } from '../popover/popover.constants';
|
15
|
+
import { DEFAULTS, TOOLTIP_TYPES } from './tooltip.constants';
|
16
|
+
import styles from './tooltip.styles';
|
16
17
|
/**
|
17
18
|
* A tooltip is triggered by mouse hover or by keyboard focus
|
18
19
|
* and will disappear upon mouse exit or focus change.
|
@@ -47,14 +48,14 @@ class Tooltip extends Popover {
|
|
47
48
|
connectedCallback() {
|
48
49
|
super.connectedCallback();
|
49
50
|
this.backdrop = false;
|
50
|
-
this.delay = DEFAULTS.DELAY;
|
51
|
+
this.delay = this.delay || DEFAULTS.DELAY;
|
51
52
|
this.focusTrap = false;
|
52
53
|
this.hideOnBlur = true;
|
53
54
|
this.hideOnEscape = true;
|
54
55
|
this.interactive = false;
|
55
|
-
this.offset = DEFAULTS.OFFSET;
|
56
|
-
this.placement = DEFAULTS.PLACEMENT;
|
57
|
-
this.role =
|
56
|
+
this.offset = this.offset || DEFAULTS.OFFSET;
|
57
|
+
this.placement = this.placement || DEFAULTS.PLACEMENT;
|
58
|
+
this.role = ROLE.TOOLTIP;
|
58
59
|
this.trigger = 'mouseenter focusin';
|
59
60
|
this.enabledFocusTrap = false;
|
60
61
|
this.enabledPreventScroll = false;
|