Skip to content

Commit a48e3cf

Browse files
committed
Merge branch 'v2-dev' of https://github.com/materializecss/materialize into v2-dev
2 parents 7b95ab6 + e999ad0 commit a48e3cf

File tree

2 files changed

+32
-12
lines changed

2 files changed

+32
-12
lines changed

src/datepicker.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ export interface DatepickerOptions extends BaseOptions {
134134
* @default null
135135
*/
136136
onDraw: (() => void) | null;
137-
137+
138138
/** Field used for internal calculations DO NOT CHANGE IT */
139139
minYear?: any;
140140
/** Field used for internal calculations DO NOT CHANGE IT */
@@ -261,7 +261,7 @@ export class Datepicker extends Component<DatepickerOptions> {
261261
constructor(el: HTMLInputElement, options: Partial<DatepickerOptions>) {
262262
super(el, options, Datepicker);
263263
(this.el as any).M_Datepicker = this;
264-
264+
265265
this.options = {
266266
...Datepicker.defaults,
267267
...options
@@ -847,8 +847,8 @@ export class Datepicker extends Component<DatepickerOptions> {
847847
});
848848

849849
// Add change handlers for select
850-
yearSelect.addEventListener('change', () => this._handleYearChange);
851-
monthSelect.addEventListener('change', () => this._handleMonthChange);
850+
yearSelect.addEventListener('change', this._handleYearChange);
851+
monthSelect.addEventListener('change', this._handleMonthChange);
852852

853853
if (typeof this.options.onDraw === 'function') {
854854
this.options.onDraw.call(this);

src/tooltip.ts

+28-8
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { Utils } from "./utils";
44
import { Bounding } from "./bounding";
55
import { Component, BaseOptions, InitElements, MElement } from "./component";
66

7+
export type TooltipPosition = 'top' | 'right' | 'bottom' | 'left';
8+
79
export interface TooltipOptions extends BaseOptions {
810
/**
911
* Delay time before tooltip disappears.
@@ -15,6 +17,11 @@ export interface TooltipOptions extends BaseOptions {
1517
* @default 0
1618
*/
1719
enterDelay: number;
20+
/**
21+
* Element Id for the tooltip.
22+
* @default ""
23+
*/
24+
tooltipId?: string;
1825
/**
1926
* Text string for the tooltip.
2027
* @default ""
@@ -45,7 +52,7 @@ export interface TooltipOptions extends BaseOptions {
4552
* Set the direction of the tooltip.
4653
* @default 'bottom'
4754
*/
48-
position: 'top' | 'right' | 'bottom' | 'left';
55+
position: TooltipPosition;
4956
/**
5057
* Amount in px that the tooltip moves during its transition.
5158
* @default 10
@@ -60,7 +67,7 @@ const _defaults: TooltipOptions = {
6067
margin: 5,
6168
inDuration: 250,
6269
outDuration: 200,
63-
position: 'bottom',
70+
position: 'bottom' as TooltipPosition,
6471
transitionMovement: 10,
6572
opacity: 1
6673
};
@@ -90,6 +97,7 @@ export class Tooltip extends Component<TooltipOptions> {
9097

9198
this.options = {
9299
...Tooltip.defaults,
100+
...this._getAttributeOptions(),
93101
...options
94102
};
95103

@@ -139,15 +147,22 @@ export class Tooltip extends Component<TooltipOptions> {
139147
this.tooltipEl = document.createElement('div');
140148
this.tooltipEl.classList.add('material-tooltip');
141149

142-
const tooltipContentEl = document.createElement('div');
150+
const tooltipContentEl = this.options.tooltipId
151+
? document.getElementById(this.options.tooltipId)
152+
: document.createElement('div');
153+
this.tooltipEl.append( tooltipContentEl);
154+
tooltipContentEl.style.display = "";
155+
143156
tooltipContentEl.classList.add('tooltip-content');
144157
this._setTooltipContent(tooltipContentEl);
145158
this.tooltipEl.appendChild(tooltipContentEl);
146159
document.body.appendChild(this.tooltipEl);
147160
}
148161

149162
_setTooltipContent(tooltipContentEl: HTMLElement) {
150-
tooltipContentEl.innerText = this.options.text;
163+
if (this.options.tooltipId)
164+
return;
165+
tooltipContentEl.innerText = this.options.text;
151166
}
152167

153168
_updateTooltipContent() {
@@ -331,16 +346,21 @@ export class Tooltip extends Component<TooltipOptions> {
331346
this.close();
332347
}
333348

334-
_getAttributeOptions() {
335-
const attributeOptions = {};
349+
_getAttributeOptions(): Partial<TooltipOptions> {
350+
let attributeOptions: Partial<TooltipOptions> = { };
336351
const tooltipTextOption = this.el.getAttribute('data-tooltip');
352+
const tooltipId = this.el.getAttribute('data-tooltip-id');
337353
const positionOption = this.el.getAttribute('data-position');
338354
if (tooltipTextOption) {
339-
(attributeOptions as any).text = tooltipTextOption;
355+
attributeOptions.text = tooltipTextOption;
340356
}
341357
if (positionOption) {
342-
(attributeOptions as any).position = positionOption;
358+
attributeOptions.position = positionOption as TooltipPosition;
359+
}
360+
if (tooltipId) {
361+
attributeOptions.tooltipId = tooltipId;
343362
}
363+
344364
return attributeOptions;
345365
}
346366
}

0 commit comments

Comments
 (0)