components icon indicating copy to clipboard operation
components copied to clipboard

bug(mat-select): disabled option doesn't work in legacy version

Open mcbashie opened this issue 3 years ago • 3 comments

Is this a regression?

  • [X] Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

V13

Description

<mat-select (openedChange)="openChanged($event)" [formControl]="appselect" [disabled]="true" (selectionChange)="selectionChangedTrigger($event)">

The code above would disable the mat-select component in v13. We've switched to angular v15 but still using the legacy version of Angular Material.

What I've seen is that the 'mat-form-field-disabled' is no longer present in the generated html. <mat-form-field _ngcontent-wjb-c202="" appearance="fill" class="mat-form-field w-100 ng-tns-c112-11 mat-primary ng-star-inserted mat-form-field-type-mat-select mat-form-field-appearance-fill mat-form-field-can-float mat-form-field-has-label ng-touched ng-pristine ng-valid mat-form-field-should-float">

I know this is a legacy version, so it is unlikely that this will be fixed. But can you confirm that this indeed in a bug and that it's not me doing something wrong?

Reproduction

Steps to reproduce:

  1. Have Angular-Material V15 legacy
  2. Add a with [disabled]="true"
  3. The mat-select dropdown is not disabled in runtime

Expected Behavior

A disabled dropdown

Actual Behavior

The dropdown is still accessible

Environment

  • Angular: V15
  • CDK/Material: V15 using the legacy components
  • Browser(s): Chrome
  • Operating System (e.g. Windows, macOS, Ubuntu): Windows 11

Angular CLI: 15.1.6 Node: 18.12.1 Package Manager: npm 8.19.2 OS: win32 x64

Angular: 15.1.5 ... animations, cdk, common, compiler, compiler-cli, core, forms ... localize, material, material-moment-adapter ... platform-browser, platform-browser-dynamic, router

Package Version

@angular-devkit/architect 0.1501.6 @angular-devkit/build-angular 15.1.6 @angular-devkit/core 15.1.6 @angular-devkit/schematics 15.1.6 @angular/cli 15.1.6 @angular/flex-layout 15.0.0-beta.42 @schematics/angular 15.1.6 rxjs 6.6.7 typescript 4.9.5

mcbashie avatar May 22 '23 08:05 mcbashie

Please provide a stackblitz reproduction to show the issue so we can diagnose

andrewseguin avatar May 30 '23 15:05 andrewseguin

I've not used stackblitz before and I'm having a bit of trouble setting it up.

However in the meantime I did find this message in the console log: It looks like you're using the disabled attribute with a reactive form directive. If you set disabled to true when you set up this control in your component class, the disabled attribute will actually be set in the DOM for you. We recommend using this approach to avoid 'changed after checked' errors.

Example: // Specify the disabled property at control creation time: form = new FormGroup({ first: new FormControl({value: 'Nancy', disabled: true}, Validators.required), last: new FormControl('Drew', Validators.required) });

// Controls can also be enabled/disabled after creation: form.get('first')?.enable(); form.get('last')?.disable();

So I think the problem is in my code and not in Angular Materials. I will make the changes as specified in the console-messages.

mcbashie avatar Jun 01 '23 08:06 mcbashie

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.