Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 4 additions & 2 deletions src/cdk-experimental/combobox/combobox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
Directive,
ElementRef,
EventEmitter,
HOST_TAG_NAME,
InjectionToken,
Injector,
Input,
Expand Down Expand Up @@ -60,6 +61,7 @@ export const CDK_COMBOBOX = new InjectionToken<CdkCombobox>('CDK_COMBOBOX');
providers: [{provide: CDK_COMBOBOX, useExisting: CdkCombobox}],
})
export class CdkCombobox<T = unknown> implements OnDestroy {
private readonly _tagName = inject(HOST_TAG_NAME);
private readonly _elementRef = inject<ElementRef<HTMLElement>>(ElementRef);
private readonly _overlay = inject(Overlay);
protected readonly _viewContainerRef = inject(ViewContainerRef);
Expand Down Expand Up @@ -245,8 +247,8 @@ export class CdkCombobox<T = unknown> implements OnDestroy {

private _isTextTrigger() {
// TODO: Should check if the trigger is contenteditable.
const tagName = this._elementRef.nativeElement.tagName.toLowerCase();
return tagName === 'input' || tagName === 'textarea' ? true : false;
const tagName = this._tagName.toLowerCase();
return tagName === 'input' || tagName === 'textarea';
}

private _getOverlayConfig() {
Expand Down
6 changes: 5 additions & 1 deletion src/material/badge/badge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
OnInit,
Renderer2,
ViewEncapsulation,
HOST_TAG_NAME,
} from '@angular/core';
import {_animationsDisabled, ThemePalette} from '../core';
import {_CdkPrivateStyleLoader, _VisuallyHiddenLoader} from '@angular/cdk/private';
Expand Down Expand Up @@ -156,15 +157,18 @@ export class MatBadge implements OnInit, OnDestroy {

if (typeof ngDevMode === 'undefined' || ngDevMode) {
const nativeElement = this._elementRef.nativeElement;

if (nativeElement.nodeType !== nativeElement.ELEMENT_NODE) {
throw Error('matBadge must be attached to an element node.');
}

const tagName = inject(HOST_TAG_NAME);

// Heads-up for developers to avoid putting matBadge on <mat-icon>
// as it is aria-hidden by default docs mention this at:
// https://material.angular.io/components/badge/overview#accessibility
if (
nativeElement.tagName.toLowerCase() === 'mat-icon' &&
tagName.toLowerCase() === 'mat-icon' &&
nativeElement.getAttribute('aria-hidden') === 'true'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this always return false in SSR because of this nativeElement.getAttribute check?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nah getAttribute works during SSR.

) {
console.warn(
Expand Down
7 changes: 4 additions & 3 deletions src/material/chips/chip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
DoCheck,
ElementRef,
EventEmitter,
HOST_TAG_NAME,
Injector,
Input,
NgZone,
Expand Down Expand Up @@ -90,6 +91,7 @@ export interface MatChipEvent {
export class MatChip implements OnInit, AfterViewInit, AfterContentInit, DoCheck, OnDestroy {
_changeDetectorRef = inject(ChangeDetectorRef);
_elementRef = inject<ElementRef<HTMLElement>>(ElementRef);
private readonly _tagName = inject(HOST_TAG_NAME);
protected _ngZone = inject(NgZone);
private _focusMonitor = inject(FocusMonitor);
private _globalRippleOptions = inject<RippleGlobalOptions>(MAT_RIPPLE_GLOBAL_OPTIONS, {
Expand Down Expand Up @@ -256,10 +258,9 @@ export class MatChip implements OnInit, AfterViewInit, AfterContentInit, DoCheck
ngOnInit() {
// This check needs to happen in `ngOnInit` so the overridden value of
// `basicChipAttrName` coming from base classes can be picked up.
const element = this._elementRef.nativeElement;
this._isBasicChip =
element.hasAttribute(this.basicChipAttrName) ||
element.tagName.toLowerCase() === this.basicChipAttrName;
this._elementRef.nativeElement.hasAttribute(this.basicChipAttrName) ||
this._tagName.toLowerCase() === this.basicChipAttrName;
}

ngAfterViewInit() {
Expand Down
Loading