diff --git a/src/material/core/option/option.html b/src/material/core/option/option.html index cf0210e9cc04..d29859b31e12 100644 --- a/src/material/core/option/option.html +++ b/src/material/core/option/option.html @@ -1,7 +1,9 @@ - + + + ({{ group.label }}) diff --git a/src/material/core/option/option.scss b/src/material/core/option/option.scss index 9e8120c12c3a..93331759094a 100644 --- a/src/material/core/option/option.scss +++ b/src/material/core/option/option.scss @@ -46,8 +46,10 @@ } } + .mat-icon, .mat-pseudo-checkbox { margin-right: mdc-list-variables.$side-padding; + flex-shrink: 0; [dir='rtl'] & { margin-right: 0; diff --git a/src/material/core/option/option.ts b/src/material/core/option/option.ts index 6a9fe92f2fce..4183a8b6f72a 100644 --- a/src/material/core/option/option.ts +++ b/src/material/core/option/option.ts @@ -24,6 +24,7 @@ import { Output, EventEmitter, QueryList, + ViewChild, } from '@angular/core'; import {Subject} from 'rxjs'; import {MatOptgroup, MAT_OPTGROUP, _MatOptgroupBase} from './optgroup'; @@ -86,6 +87,9 @@ export class _MatOptionBase implements FocusableOption, AfterViewChecke // tslint:disable-next-line:no-output-on-prefix @Output() readonly onSelectionChange = new EventEmitter>(); + /** Element containing the option's text. */ + @ViewChild('text', {static: true}) _text: ElementRef | undefined; + /** Emits when the state of the option changes and any parents have to be notified. */ readonly _stateChanges = new Subject(); @@ -112,7 +116,7 @@ export class _MatOptionBase implements FocusableOption, AfterViewChecke */ get viewValue(): string { // TODO(kara): Add input property alternative for node envs. - return (this._getHostElement().textContent || '').trim(); + return (this._text?.nativeElement.textContent || '').trim(); } /** Selects the option. */ diff --git a/src/material/legacy-core/option/option.html b/src/material/legacy-core/option/option.html index 746e8061ac6d..747ddf2b5987 100644 --- a/src/material/legacy-core/option/option.html +++ b/src/material/legacy-core/option/option.html @@ -1,7 +1,7 @@ - + ({{ group.label }}) diff --git a/tools/public_api_guard/material/core.md b/tools/public_api_guard/material/core.md index 16d072137fa9..d593d47b9ea8 100644 --- a/tools/public_api_guard/material/core.md +++ b/tools/public_api_guard/material/core.md @@ -263,7 +263,7 @@ export class _MatOptgroupBase extends _MatOptgroupMixinBase implements CanDisabl export class MatOption extends _MatOptionBase { constructor(element: ElementRef, changeDetectorRef: ChangeDetectorRef, parent: MatOptionParentComponent, group: MatOptgroup); // (undocumented) - static ɵcmp: i0.ɵɵComponentDeclaration, "mat-option", ["matOption"], {}, {}, never, ["*"], false, never>; + static ɵcmp: i0.ɵɵComponentDeclaration, "mat-option", ["matOption"], {}, {}, never, ["mat-icon", "*"], false, never>; // (undocumented) static ɵfac: i0.ɵɵFactoryDeclaration, [null, null, { optional: true; }, { optional: true; }]>; } @@ -297,6 +297,7 @@ export class _MatOptionBase implements FocusableOption, AfterViewChecke setActiveStyles(): void; setInactiveStyles(): void; readonly _stateChanges: Subject; + _text: ElementRef | undefined; value: T; get viewValue(): string; // (undocumented)