Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
479769c
refactor(cdk/menu): fix strict property initialization errors
crisbeto Dec 15, 2025
6103182
refactor(cdk/overlay): fix strict property initialization errors
crisbeto Dec 15, 2025
e99358d
refactor(cdk/a11y): fix strict property initialization errors
crisbeto Dec 15, 2025
cd269a5
refactor(cdk/bidi): fix strict property initialization errors
crisbeto Dec 15, 2025
b0ca22b
refactor(cdk/clipboard): fix strict property initialization errors
crisbeto Dec 15, 2025
0221383
refactor(cdk/collections): fix strict property initialization errors
crisbeto Dec 15, 2025
6379048
refactor(cdk/dialog): fix strict property initialization errors
crisbeto Dec 15, 2025
21d0195
refactor(cdk/drag-drop): fix strict property initialization errors
crisbeto Dec 15, 2025
d24baaa
refactor(cdk/listbox): fix strict property initialization errors
crisbeto Dec 15, 2025
5496049
refactor(cdk/observers): fix strict property initialization errors
crisbeto Dec 15, 2025
1742fdf
refactor(cdk/portal): fix strict property initialization errors
crisbeto Dec 15, 2025
704aefe
refactor(cdk/scrolling): fix strict property initialization errors
crisbeto Dec 15, 2025
46a12c1
refactor(cdk/stepper): fix strict property initialization errors
crisbeto Dec 15, 2025
6624e14
refactor(cdk/table): fix strict property initialization errors
crisbeto Dec 15, 2025
6f200db
refactor(cdk/testing): fix strict property initialization errors
crisbeto Dec 15, 2025
c234f2c
refactor(cdk/text-field): fix strict property initialization errors
crisbeto Dec 15, 2025
6872ee3
refactor(cdk/tree): fix strict property initialization errors
crisbeto Dec 15, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion goldens/cdk/menu/index.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ export abstract class CdkMenuTriggerBase implements OnDestroy {
abstract close(): void;
readonly closed: EventEmitter<void>;
protected readonly destroyed: Subject<void>;
protected getMenuContentPortal(): TemplatePortal<any>;
protected getMenuContentPortal(): TemplatePortal<any> | undefined;
readonly injector: Injector;
protected isElementInsideMenuStack(element: Element): boolean;
isOpen(): boolean;
Expand Down
2 changes: 1 addition & 1 deletion goldens/cdk/overlay/index.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ export interface OverlayConnectionPosition {
export class OverlayContainer implements OnDestroy {
constructor(...args: unknown[]);
// (undocumented)
protected _containerElement: HTMLElement;
protected _containerElement: HTMLElement | undefined;
protected _createContainer(): void;
// (undocumented)
protected _document: Document;
Expand Down
13 changes: 5 additions & 8 deletions src/cdk/a11y/focus-monitor/focus-monitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,16 @@ export class FocusMonitor implements OnDestroy {
private _origin: FocusOrigin = null;

/** The FocusOrigin of the last focus event tracked by the FocusMonitor. */
private _lastFocusOrigin: FocusOrigin;
private _lastFocusOrigin: FocusOrigin = null;

/** Whether the window has just been focused. */
private _windowFocused = false;

/** The timeout id of the window focus timeout. */
private _windowFocusTimeoutId: ReturnType<typeof setTimeout>;
private _windowFocusTimeoutId: ReturnType<typeof setTimeout> | undefined;

/** The timeout id of the origin clearing timeout. */
private _originTimeoutId: ReturnType<typeof setTimeout>;
private _originTimeoutId: ReturnType<typeof setTimeout> | undefined;

/**
* Whether the origin was determined via a touch interaction. Necessary as properly attributing
Expand Down Expand Up @@ -617,7 +617,7 @@ export class CdkMonitorFocus implements AfterViewInit, OnDestroy {
private _elementRef = inject<ElementRef<HTMLElement>>(ElementRef);
private _focusMonitor = inject(FocusMonitor);

private _monitorSubscription: Subscription;
private _monitorSubscription: Subscription | undefined;
private _focusOrigin: FocusOrigin = null;

@Output() readonly cdkFocusChange = new EventEmitter<FocusOrigin>();
Expand All @@ -641,9 +641,6 @@ export class CdkMonitorFocus implements AfterViewInit, OnDestroy {

ngOnDestroy() {
this._focusMonitor.stopMonitoring(this._elementRef);

if (this._monitorSubscription) {
this._monitorSubscription.unsubscribe();
}
this._monitorSubscription?.unsubscribe();
}
}
9 changes: 5 additions & 4 deletions src/cdk/a11y/focus-trap/focus-trap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ import {_CdkPrivateStyleLoader, _VisuallyHiddenLoader} from '../../private';
* Things like `tabIndex > 0`, flex `order`, and shadow roots can cause the two to be misaligned.
*/
export class FocusTrap {
private _startAnchor: HTMLElement | null;
private _endAnchor: HTMLElement | null;
private _startAnchor: HTMLElement | null = null;
private _endAnchor: HTMLElement | null = null;
private _hasAttached = false;

// Event listeners for the anchors. Need to be regular functions so that we can unbind them later.
Expand Down Expand Up @@ -413,7 +413,7 @@ export class CdkTrapFocus implements OnDestroy, AfterContentInit, OnChanges, DoC
private _focusTrapFactory = inject(FocusTrapFactory);

/** Underlying FocusTrap instance. */
focusTrap: FocusTrap;
focusTrap: FocusTrap = undefined!;

/** Previously focused element to restore focus to upon destroy when using autoCapture. */
private _previouslyFocusedElement: HTMLElement | null = null;
Expand All @@ -433,7 +433,8 @@ export class CdkTrapFocus implements OnDestroy, AfterContentInit, OnChanges, DoC
* Whether the directive should automatically move focus into the trapped region upon
* initialization and return focus to the previous activeElement upon destruction.
*/
@Input({alias: 'cdkTrapFocusAutoCapture', transform: booleanAttribute}) autoCapture: boolean;
@Input({alias: 'cdkTrapFocusAutoCapture', transform: booleanAttribute})
autoCapture: boolean = false;

constructor(...args: unknown[]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class HighContrastModeDetector implements OnDestroy {
* Figuring out the high contrast mode and adding the body classes can cause
* some expensive layouts. This flag is used to ensure that we only do it once.
*/
private _hasCheckedHighContrastMode: boolean;
private _hasCheckedHighContrastMode = false;
private _document = inject(DOCUMENT);
private _breakpointSubscription: Subscription;

Expand Down
2 changes: 1 addition & 1 deletion src/cdk/a11y/key-manager/list-key-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class ListKeyManager<T extends ListKeyManagerOption> {
private _typeaheadSubscription = Subscription.EMPTY;
private _itemChangesSubscription?: Subscription;
private _vertical = true;
private _horizontal: 'ltr' | 'rtl' | null;
private _horizontal: 'ltr' | 'rtl' | null = null;
private _allowedModifierKeys: ListKeyManagerModifierKey[] = [];
private _homeAndEnd = false;
private _pageUpAndDown = {enabled: false, delta: 10};
Expand Down
12 changes: 5 additions & 7 deletions src/cdk/a11y/live-announcer/live-announcer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class LiveAnnouncer implements OnDestroy {
private _liveElement: HTMLElement;
private _document = inject(DOCUMENT);
private _sanitizer = inject(DomSanitizer);
private _previousTimeout: ReturnType<typeof setTimeout>;
private _previousTimeout: ReturnType<typeof setTimeout> | undefined;
private _currentPromise: Promise<void> | undefined;
private _currentResolve: (() => void) | undefined;

Expand Down Expand Up @@ -250,7 +250,7 @@ export class CdkAriaLive implements OnDestroy {
if (this._politeness === 'off') {
if (this._subscription) {
this._subscription.unsubscribe();
this._subscription = null;
this._subscription = undefined;
}
} else if (!this._subscription) {
this._subscription = this._ngZone.runOutsideAngular(() => {
Expand All @@ -271,10 +271,10 @@ export class CdkAriaLive implements OnDestroy {
private _politeness: AriaLivePoliteness = 'polite';

/** Time in milliseconds after which to clear out the announcer element. */
@Input('cdkAriaLiveDuration') duration: number;
@Input('cdkAriaLiveDuration') duration!: number;

private _previousAnnouncedText?: string;
private _subscription: Subscription | null;
private _subscription: Subscription | undefined;

constructor(...args: unknown[]);

Expand All @@ -283,8 +283,6 @@ export class CdkAriaLive implements OnDestroy {
}

ngOnDestroy() {
if (this._subscription) {
this._subscription.unsubscribe();
}
this._subscription?.unsubscribe();
}
}
2 changes: 1 addition & 1 deletion src/cdk/bidi/dir.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class Dir implements Directionality, AfterContentInit, OnDestroy {
private _isInitialized: boolean = false;

/** Direction as passed in by the consumer. */
_rawDir: string;
_rawDir: string = '';

/** Event emitted when the direction changes. */
@Output('dirChange') readonly change = new EventEmitter<Direction>();
Expand Down
6 changes: 3 additions & 3 deletions src/cdk/bidi/directionality.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ class InjectsDirectionality {
imports: [Dir, InjectsDirectionality],
})
class ElementWithDir {
@ViewChild(Dir) dir: Dir;
@ViewChild(Dir) dir!: Dir;
direction = signal<Direction>('rtl');
changeCount = 0;
}
Expand All @@ -180,15 +180,15 @@ class ElementWithDir {
imports: [Dir],
})
class ElementWithPredefinedAutoDir {
@ViewChild(Dir) dir: Dir;
@ViewChild(Dir) dir!: Dir;
}

@Component({
template: '<div [dir]="$any(`RTL`)"></div>',
imports: [Dir],
})
class ElementWithPredefinedUppercaseDir {
@ViewChild(Dir) dir: Dir;
@ViewChild(Dir) dir!: Dir;
}

interface FakeDocument {
Expand Down
2 changes: 1 addition & 1 deletion src/cdk/clipboard/copy-to-clipboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class CdkCopyToClipboard implements OnDestroy {
private _pending = new Set<PendingCopy>();

/** Whether the directive has been destroyed. */
private _destroyed: boolean;
private _destroyed = false;

/** Timeout for the current copy attempt. */
private _currentTimeout: any;
Expand Down
2 changes: 1 addition & 1 deletion src/cdk/collections/selection-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class SelectionModel<T> {
private _selectedToEmit: T[] = [];

/** Cache for the array value of the selected items. */
private _selected: T[] | null;
private _selected: T[] | null = null;

/** Selected values. */
get selected(): T[] {
Expand Down
2 changes: 1 addition & 1 deletion src/cdk/dialog/dialog-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export class CdkDialogContainer<C extends DialogConfig = DialogConfig>
protected _document = inject(DOCUMENT);

/** The portal outlet inside of this container into which the dialog content will be loaded. */
@ViewChild(CdkPortalOutlet, {static: true}) _portalOutlet: CdkPortalOutlet;
@ViewChild(CdkPortalOutlet, {static: true}) _portalOutlet!: CdkPortalOutlet;

_focusTrapped: Observable<void> = new Subject<void>();

Expand Down
6 changes: 3 additions & 3 deletions src/cdk/dialog/dialog-ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ export class DialogRef<R = unknown, C = unknown> {
* Instance of component opened into the dialog. Will be
* null when the dialog is opened using a `TemplateRef`.
*/
readonly componentInstance: C | null;
readonly componentInstance: C | null = null;

/**
* `ComponentRef` of the component opened into the dialog. Will be
* null when the dialog is opened using a `TemplateRef`.
*/
readonly componentRef: ComponentRef<C> | null;
readonly componentRef: ComponentRef<C> | null = null;

/** Instance of the container that is rendering out the dialog content. */
readonly containerInstance: DialogContainer;
readonly containerInstance!: DialogContainer;

/** Whether the user is allowed to close the dialog. */
disableClose: boolean | undefined;
Expand Down
2 changes: 1 addition & 1 deletion src/cdk/drag-drop/directives/drag-placeholder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class CdkDragPlaceholder<T = any> implements OnDestroy {
private _drag = inject(CDK_DRAG_PARENT, {optional: true});

/** Context data to be added to the placeholder template instance. */
@Input() data: T;
@Input() data!: T;

constructor(...args: unknown[]);

Expand Down
2 changes: 1 addition & 1 deletion src/cdk/drag-drop/directives/drag-preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class CdkDragPreview<T = any> implements OnDestroy {
private _drag = inject(CDK_DRAG_PARENT, {optional: true});

/** Context data to be added to the preview template instance. */
@Input() data: T;
@Input() data!: T;

/** Whether the preview should preserve the same size as the item that is being dragged. */
@Input({transform: booleanAttribute}) matchSize: boolean = false;
Expand Down
20 changes: 10 additions & 10 deletions src/cdk/drag-drop/directives/drag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,14 @@ export class CdkDrag<T = any> implements AfterViewInit, OnChanges, OnDestroy {

private readonly _destroyed = new Subject<void>();
private _handles = new BehaviorSubject<CdkDragHandle[]>([]);
private _previewTemplate: CdkDragPreview | null;
private _placeholderTemplate: CdkDragPlaceholder | null;
private _previewTemplate: CdkDragPreview | null = null;
private _placeholderTemplate: CdkDragPlaceholder | null = null;

/** Reference to the underlying drag instance. */
_dragRef: DragRef<CdkDrag<T>>;

/** Arbitrary data to attach to this drag instance. */
@Input('cdkDragData') data: T;
@Input('cdkDragData') data!: T;

/** Locks the position of the dragged element along the specified axis. */
@Input('cdkDragLockAxis') lockAxis: DragAxis | null = null;
Expand All @@ -98,27 +98,27 @@ export class CdkDrag<T = any> implements AfterViewInit, OnChanges, OnDestroy {
* the `cdkDrag` element and going up the DOM. Passing an alternate root element is useful
* when trying to enable dragging on an element that you might not have access to.
*/
@Input('cdkDragRootElement') rootElementSelector: string;
@Input('cdkDragRootElement') rootElementSelector!: string;

/**
* Node or selector that will be used to determine the element to which the draggable's
* position will be constrained. If a string is passed in, it'll be used as a selector that
* will be matched starting from the element's parent and going up the DOM until a match
* has been found.
*/
@Input('cdkDragBoundary') boundaryElement: string | ElementRef<HTMLElement> | HTMLElement;
@Input('cdkDragBoundary') boundaryElement!: string | ElementRef<HTMLElement> | HTMLElement;

/**
* Amount of milliseconds to wait after the user has put their
* pointer down before starting to drag the element.
*/
@Input('cdkDragStartDelay') dragStartDelay: DragStartDelay;
@Input('cdkDragStartDelay') dragStartDelay!: DragStartDelay;

/**
* Sets the position of a `CdkDrag` that is outside of a drop container.
* Can be used to restore the element's position for a returning user.
*/
@Input('cdkDragFreeDragPosition') freeDragPosition: Point;
@Input('cdkDragFreeDragPosition') freeDragPosition!: Point;

/** Whether starting to drag this element is disabled. */
@Input({alias: 'cdkDragDisabled', transform: booleanAttribute})
Expand All @@ -129,7 +129,7 @@ export class CdkDrag<T = any> implements AfterViewInit, OnChanges, OnDestroy {
this._disabled = value;
this._dragRef.disabled = this._disabled;
}
private _disabled: boolean;
private _disabled = false;

/**
* Function that can be used to customize the logic of how the position of the drag item
Expand All @@ -140,7 +140,7 @@ export class CdkDrag<T = any> implements AfterViewInit, OnChanges, OnDestroy {
@Input('cdkDragConstrainPosition') constrainPosition?: DragConstrainPosition;

/** Class to be added to the preview element. */
@Input('cdkDragPreviewClass') previewClass: string | string[];
@Input('cdkDragPreviewClass') previewClass!: string | string[];

/**
* Configures the place into which the preview of the item will be inserted. Can be configured
Expand All @@ -155,7 +155,7 @@ export class CdkDrag<T = any> implements AfterViewInit, OnChanges, OnDestroy {
* - `ElementRef<HTMLElement> | HTMLElement` - Preview will be inserted into a specific element.
* Same advantages and disadvantages as `parent`.
*/
@Input('cdkDragPreviewContainer') previewContainer: PreviewContainer;
@Input('cdkDragPreviewContainer') previewContainer!: PreviewContainer;

/**
* If the parent of the dragged element has a `scale` transform, it can throw off the
Expand Down
Loading
Loading