Skip to content
Open
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
1 change: 1 addition & 0 deletions src/material/core/option/option-parent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {InjectionToken, Signal} from '@angular/core';
*/
export interface MatOptionParentComponent {
disableRipple?: boolean | Signal<boolean>;
disableOptions?: boolean;
multiple?: boolean;
inertGroups?: boolean;
hideSingleSelectionIndicator?: boolean;
Expand Down
2 changes: 1 addition & 1 deletion src/material/core/option/option.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ export class MatOption<T = any> implements FocusableOption, AfterViewChecked, On
* determine if the select's view -> model callback should be invoked.`
*/
_selectViaInteraction(): void {
if (!this.disabled) {
if (!this.disabled && !this._parent?.disableOptions) {
this._selected = this.multiple ? !this._selected : true;
this._changeDetectorRef.markForCheck();
this._emitSelectionChangeEvent(true);
Expand Down
16 changes: 16 additions & 0 deletions src/material/select/select.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1932,6 +1932,22 @@ describe('MatSelect', () => {
expect(trigger.textContent!.trim()).toBe('PIZZA');
});

it('should not select an option when disabled while open', () => {
fixture.componentInstance.control.setValue('pizza-1');
fixture.detectChanges();
trigger.click();
fixture.detectChanges();
const selectionChange = jasmine.createSpy('selectionChange');
fixture.componentInstance.select.selectionChange.subscribe(selectionChange);
fixture.componentInstance.control.disable({emitEvent: false});
fixture.detectChanges();
const option = getOverlayHost(fixture)!.querySelector('mat-option') as HTMLElement;
option.click();
fixture.detectChanges();
expect(fixture.componentInstance.control.value).toBe('pizza-1');
expect(selectionChange).not.toHaveBeenCalled();
});

it('should not select disabled options', () => {
trigger.click();
fixture.detectChanges();
Expand Down
5 changes: 5 additions & 0 deletions src/material/select/select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,11 @@ export class MatSelect
@Input({transform: booleanAttribute})
disabled: boolean = false;

/** Whether options are disabled by the select. */
get disableOptions(): boolean {
return this.disabled;
}

/** Whether ripples in the select are disabled. */
@Input({transform: booleanAttribute})
get disableRipple() {
Expand Down
Loading