trimox / angular-mdc-web

Angular wrapper for Material Design (Web) Components
https://trimox.github.io/angular-mdc-web
MIT License
517 stars 87 forks source link

Lazy Loaded Select Doesn't Set Value #2141

Closed mrp67 closed 4 years ago

mrp67 commented 4 years ago

Describe the bug When list items are lazy loaded, when clicking on a value, the select menu appears to still be empty.

To Reproduce Steps to reproduce the behavior:

  1. Go to the Lazy Load section of the Mdc Select section of the demo.
  2. Click on the "load" button
  3. Select a value
  4. No value will be populated and select menu will remain empty

Expected behavior Clicking on a value should populate the select menu and set the form value, just like the non-lazy loaded ones.

Screenshots If applicable, add screenshots to help explain your problem. image

What Angular MDC version are you using? This is in the demo which should be using the current latest version. I am also having the same issue on 5.0.5

mrp67 commented 4 years ago

I spun up the demo locally with a debug value below the select: {{ lazySelect.value | json }} It seems that the correct value is set on the form, but the appearance of the select is not updated image

mrp67 commented 4 years ago

I'm not entirely sure if this is how the issue should be fixed, but I was able to fix it by modifying the select's layout function. I'm basically doing what's happening in ngAfterViewInit in the if (this._initialized) { ... }

Before (not working):

  private layout(): void {
    if (this._initialized) {
      this._selectBuilder();

      if (this._outlined) {
        this._foundation.layout();
      }
    }
  }

After (working):

private layout(): void {
    if (this._initialized) {
      this._asyncBuildFoundation().then(() => {
        this._selectBuilder();
      });

      if (this._outlined) {
        this._foundation.layout();
      }
    }
  }
k11k2 commented 4 years ago

@trimox Any update on this ?

trimox commented 4 years ago

@AlwaysAbhl001 Resolving as part of #2125. Noticed demo was broken during testing.