Skip to content

Commit 7bd5121

Browse files
committed
refactor(material/tooltip): fix strict property initialization errors
Updates the code to be compatible with strict property initialization.
1 parent 126faaa commit 7bd5121

File tree

3 files changed

+28
-28
lines changed

3 files changed

+28
-28
lines changed

src/material/tooltip/tooltip.spec.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1575,8 +1575,8 @@ class BasicTooltipDemo {
15751575
showTooltipClass = false;
15761576
tooltipDisabled = false;
15771577
touchGestures: TooltipTouchGestures = 'auto';
1578-
@ViewChild(MatTooltip) tooltip: MatTooltip;
1579-
@ViewChild('button') button: ElementRef<HTMLButtonElement>;
1578+
@ViewChild(MatTooltip) tooltip!: MatTooltip;
1579+
@ViewChild('button') button!: ElementRef<HTMLButtonElement>;
15801580
}
15811581

15821582
@Component({
@@ -1596,7 +1596,7 @@ class ScrollableTooltipDemo {
15961596
message: string = initialTooltipMessage;
15971597
showButton: boolean = true;
15981598

1599-
@ViewChild(CdkScrollable) scrollingContainer: CdkScrollable;
1599+
@ViewChild(CdkScrollable) scrollingContainer!: CdkScrollable;
16001600

16011601
scrollDown() {
16021602
const scrollingContainerEl = this.scrollingContainer.getElementRef().nativeElement;
@@ -1658,8 +1658,8 @@ class DataBoundAriaLabelTooltip {
16581658
imports: [MatTooltipModule, OverlayModule],
16591659
})
16601660
class TooltipOnTextFields {
1661-
@ViewChild('input') input: ElementRef<HTMLInputElement>;
1662-
@ViewChild('textarea') textarea: ElementRef<HTMLTextAreaElement>;
1661+
@ViewChild('input') input!: ElementRef<HTMLInputElement>;
1662+
@ViewChild('textarea') textarea!: ElementRef<HTMLTextAreaElement>;
16631663
touchGestures: TooltipTouchGestures = 'auto';
16641664
}
16651665

@@ -1674,7 +1674,7 @@ class TooltipOnTextFields {
16741674
imports: [MatTooltipModule, OverlayModule],
16751675
})
16761676
class TooltipOnDraggableElement {
1677-
@ViewChild('button') button: ElementRef;
1677+
@ViewChild('button') button!: ElementRef;
16781678
touchGestures: TooltipTouchGestures = 'auto';
16791679
}
16801680

@@ -1684,8 +1684,8 @@ class TooltipOnDraggableElement {
16841684
})
16851685
class TooltipDemoWithoutPositionBinding {
16861686
message: string = initialTooltipMessage;
1687-
@ViewChild(MatTooltip) tooltip: MatTooltip;
1688-
@ViewChild('button') button: ElementRef<HTMLButtonElement>;
1687+
@ViewChild(MatTooltip) tooltip!: MatTooltip;
1688+
@ViewChild('button') button!: ElementRef<HTMLButtonElement>;
16891689
}
16901690

16911691
@Component({
@@ -1694,8 +1694,8 @@ class TooltipDemoWithoutPositionBinding {
16941694
})
16951695
class TooltipDemoWithoutTooltipClassBinding {
16961696
message = initialTooltipMessage;
1697-
@ViewChild(MatTooltip) tooltip: MatTooltip;
1698-
@ViewChild('button') button: ElementRef<HTMLButtonElement>;
1697+
@ViewChild(MatTooltip) tooltip!: MatTooltip;
1698+
@ViewChild('button') button!: ElementRef<HTMLButtonElement>;
16991699
}
17001700

17011701
@Component({
@@ -1706,8 +1706,8 @@ class TooltipDemoWithoutTooltipClassBinding {
17061706
})
17071707
class TooltipDemoWithTooltipClassBinding {
17081708
message: string = initialTooltipMessage;
1709-
@ViewChild(MatTooltip) tooltip: MatTooltip;
1710-
@ViewChild('button') button: ElementRef<HTMLButtonElement>;
1709+
@ViewChild(MatTooltip) tooltip!: MatTooltip;
1710+
@ViewChild('button') button!: ElementRef<HTMLButtonElement>;
17111711
}
17121712

17131713
@Component({
@@ -1717,8 +1717,8 @@ class TooltipDemoWithTooltipClassBinding {
17171717
})
17181718
class WideTooltipDemo {
17191719
message = 'Test';
1720-
@ViewChild(MatTooltip) tooltip: MatTooltip;
1721-
@ViewChild('button') button: ElementRef<HTMLButtonElement>;
1720+
@ViewChild(MatTooltip) tooltip!: MatTooltip;
1721+
@ViewChild('button') button!: ElementRef<HTMLButtonElement>;
17221722
}
17231723

17241724
/** Asserts whether a tooltip directive has a tooltip instance. */

src/material/tooltip/tooltip.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -195,22 +195,22 @@ export class MatTooltip implements OnDestroy, AfterViewInit {
195195
optional: true,
196196
});
197197

198-
_overlayRef: OverlayRef | null;
199-
_tooltipInstance: TooltipComponent | null;
198+
_overlayRef: OverlayRef | null = null;
199+
_tooltipInstance: TooltipComponent | null = null;
200200
_overlayPanelClass: string[] | undefined; // Used for styling internally.
201201

202-
private _portal: ComponentPortal<TooltipComponent>;
202+
private _portal!: ComponentPortal<TooltipComponent>;
203203
private _position: TooltipPosition = 'below';
204204
private _positionAtOrigin: boolean = false;
205205
private _disabled: boolean = false;
206-
private _tooltipClass: string | string[] | Set<string> | {[key: string]: unknown};
206+
private _tooltipClass!: string | string[] | Set<string> | {[key: string]: unknown};
207207
private _viewInitialized = false;
208208
private _pointerExitEventsInitialized = false;
209209
private readonly _tooltipComponent = TooltipComponent;
210210
private _viewportMargin = 8;
211-
private _currentPosition: TooltipPosition;
211+
private _currentPosition!: TooltipPosition;
212212
private readonly _cssClassPrefix: string = 'mat-mdc';
213-
private _ariaDescriptionPending: boolean;
213+
private _ariaDescriptionPending = false;
214214
private _dirSubscribed = false;
215215

216216
/** Allows the user to define the position of the tooltip relative to the parent element */
@@ -279,7 +279,7 @@ export class MatTooltip implements OnDestroy, AfterViewInit {
279279
this._showDelay = coerceNumberProperty(value);
280280
}
281281

282-
private _showDelay: number;
282+
private _showDelay!: number;
283283

284284
/** The default delay in ms before hiding the tooltip after hide is called */
285285
@Input('matTooltipHideDelay')
@@ -295,7 +295,7 @@ export class MatTooltip implements OnDestroy, AfterViewInit {
295295
}
296296
}
297297

298-
private _hideDelay: number;
298+
private _hideDelay!: number;
299299

300300
/**
301301
* How touch gestures should be handled by the tooltip. On touch devices the tooltip directive
@@ -970,10 +970,10 @@ export class TooltipComponent implements OnDestroy {
970970
_isMultiline = false;
971971

972972
/** Message to display in the tooltip */
973-
message: string;
973+
message!: string;
974974

975975
/** Classes to be added to the tooltip. Supports the same syntax as `ngClass`. */
976-
tooltipClass: string | string[] | Set<string> | {[key: string]: unknown};
976+
tooltipClass!: string | string[] | Set<string> | {[key: string]: unknown};
977977

978978
/** The timeout ID of any current timer set to show the tooltip */
979979
private _showTimeoutId: ReturnType<typeof setTimeout> | undefined;
@@ -982,10 +982,10 @@ export class TooltipComponent implements OnDestroy {
982982
private _hideTimeoutId: ReturnType<typeof setTimeout> | undefined;
983983

984984
/** Element that caused the tooltip to open. */
985-
_triggerElement: HTMLElement;
985+
_triggerElement!: HTMLElement;
986986

987987
/** Amount of milliseconds to delay the closing sequence. */
988-
_mouseLeaveHideDelay: number;
988+
_mouseLeaveHideDelay!: number;
989989

990990
/** Whether animations are currently disabled. */
991991
private _animationsDisabled = _animationsDisabled();
@@ -996,7 +996,7 @@ export class TooltipComponent implements OnDestroy {
996996
// the DOM which can happen before `ngAfterViewInit`.
997997
static: true,
998998
})
999-
_tooltip: ElementRef<HTMLElement>;
999+
_tooltip!: ElementRef<HTMLElement>;
10001000

10011001
/** Whether interactions on the page should close the tooltip */
10021002
private _closeOnInteraction = false;

src/material/tooltip/tooltip.zone.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class ScrollableTooltipDemo {
7272
message: string = initialTooltipMessage;
7373
showButton: boolean = true;
7474

75-
@ViewChild(CdkScrollable) scrollingContainer: CdkScrollable;
75+
@ViewChild(CdkScrollable) scrollingContainer!: CdkScrollable;
7676

7777
scrollDown() {
7878
const scrollingContainerEl = this.scrollingContainer.getElementRef().nativeElement;

0 commit comments

Comments
 (0)