Skip to content

Commit 5b0803a

Browse files
committed
code review
1 parent 07baff2 commit 5b0803a

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

src/cdk/a11y/aria-describer/aria-describer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export class AriaDescriber implements OnDestroy {
7979

8080
/** Removes the host element's aria-describedby reference to the message element. */
8181
removeDescription(hostElement: Element, message: string|HTMLElement) {
82-
if (!this._isElementNode(hostElement)) {
82+
if (!message || !this._isElementNode(hostElement)) {
8383
return;
8484
}
8585

src/material/tooltip/tooltip.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,7 @@ export class MatTooltip implements OnDestroy, AfterViewInit {
206206
@Input('matTooltip')
207207
get message() { return this._message; }
208208
set message(value: string) {
209-
if (this._message) {
210-
this._ariaDescriber.removeDescription(this._elementRef.nativeElement, this._message);
211-
}
209+
this._ariaDescriber.removeDescription(this._elementRef.nativeElement, this._message);
212210

213211
// If the message is not a string (e.g. number), convert it to a string and trim it.
214212
this._message = value != null ? `${value}`.trim() : '';
@@ -560,7 +558,7 @@ export class MatTooltip implements OnDestroy, AfterViewInit {
560558

561559
// The mouse events shouldn't be bound on mobile devices, because they can prevent the
562560
// first tap from firing its click event or can cause the tooltip to open for clicks.
563-
if (!this._platform.IOS && !this._platform.ANDROID) {
561+
if (this._platformSupportsMouseEvents()) {
564562
this._passiveListeners
565563
.push(['mouseenter', () => {
566564
this._setupPointerExitEventsIfNeeded();
@@ -579,7 +577,7 @@ export class MatTooltip implements OnDestroy, AfterViewInit {
579577
}]);
580578
}
581579

582-
this._hookupListeners(this._passiveListeners);
580+
this._addListeners(this._passiveListeners);
583581
}
584582

585583
private _setupPointerExitEventsIfNeeded() {
@@ -589,7 +587,7 @@ export class MatTooltip implements OnDestroy, AfterViewInit {
589587
this._pointerExitEventsInitialized = true;
590588

591589
const exitListeners: (readonly [string, EventListenerOrEventListenerObject])[] = [];
592-
if (!this._platform.IOS && !this._platform.ANDROID) {
590+
if (this._platformSupportsMouseEvents()) {
593591
exitListeners.push(['mouseleave', () => this.hide()]);
594592
} else if (this.touchGestures !== 'off') {
595593
this._disableNativeGesturesIfNecessary();
@@ -604,11 +602,11 @@ export class MatTooltip implements OnDestroy, AfterViewInit {
604602
);
605603
}
606604

607-
this._hookupListeners(exitListeners);
605+
this._addListeners(exitListeners);
608606
this._passiveListeners.push(...exitListeners);
609607
}
610608

611-
private _hookupListeners(
609+
private _addListeners(
612610
listeners: ReadonlyArray<readonly [string, EventListenerOrEventListenerObject]>) {
613611
listeners.forEach(([event, listener]) => {
614612
this._elementRef.nativeElement.addEventListener(event, listener, passiveListenerOptions);
@@ -752,6 +750,10 @@ export class TooltipComponent implements OnDestroy {
752750
this._onHide.complete();
753751
}
754752

753+
private _platformSupportsMouseEvents() {
754+
return !this._platform.IOS && !this._platform.ANDROID;
755+
}
756+
755757
_animationStart() {
756758
this._closeOnInteraction = false;
757759
}

0 commit comments

Comments
 (0)