Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Selecting reset option in mat-select #10675

Closed
RandomNonameDude opened this issue Apr 3, 2018 · 10 comments · Fixed by #13598
Closed

Selecting reset option in mat-select #10675

RandomNonameDude opened this issue Apr 3, 2018 · 10 comments · Fixed by #13598
Assignees
Labels
area: material/select P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent

Comments

@RandomNonameDude
Copy link

Bug, feature request, or proposal:

When undefined (reset) option is selected in mat-select, and you open the options list and select the undefined option again, both valueChange and ngModelChange events are fired. When you do the same with non-undefined option, none of the events is fired.

What is the expected behavior?

I would expect undefined options to behave same as non-undefined ones, i. e. not to fire an event when the same option is selected twice.

What is the current behavior?

See above.

What are the steps to reproduce?

https://stackblitz.com/edit/angular-hbmfjn-wk5qdh

Small example in Stackblitz. Undefined option is set as default. Try opening the options list and select the undefined (None) option again. You can see that both valueChange and ngModelChange events are fired (see the timestamps below the mat-select).

You can try selecting any non-undefined option twice and observe the timestamps. You will see that the events are fired only once (after the first selection), but not again when you select the same option for the second time.

Which versions of Angular, Material, OS, TypeScript, browsers are affected?

Issue occurs in both Chrome and IE on Win7. Not tested anywhere else.

Is there anything else we should know?

Probably not.

@crisbeto crisbeto self-assigned this Apr 14, 2018
@crisbeto crisbeto added P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent has pr labels Apr 14, 2018
crisbeto added a commit to crisbeto/material2 that referenced this issue Apr 14, 2018
…on is selected twice in a row

Fixes the select's change events being fired when a reset option is selected twice in a row.

Fixes angular#10675.
josephperrott pushed a commit that referenced this issue May 30, 2018
…on is selected twice in a row

Fixes the select's change events being fired when a reset option is selected twice in a row.

Fixes #10675.
andrewseguin pushed a commit that referenced this issue Jun 7, 2018
…on is selected twice in a row

Fixes the select's change events being fired when a reset option is selected twice in a row.

Fixes #10675.
crisbeto added a commit to crisbeto/material2 that referenced this issue Jun 20, 2018
…on is selected twice in a row

Fixes the select's change events being fired when a reset option is selected twice in a row.

Fixes angular#10675.
crisbeto added a commit to crisbeto/material2 that referenced this issue Jun 28, 2018
…on is selected twice in a row

Fixes the select's change events being fired when a reset option is selected twice in a row.

Fixes angular#10675.
josephperrott pushed a commit that referenced this issue Jun 28, 2018
…on is selected twice in a row

Fixes the select's change events being fired when a reset option is selected twice in a row.

Fixes #10675.
crisbeto added a commit to crisbeto/material2 that referenced this issue Aug 26, 2018
…on is selected twice in a row

Fixes the select's change events being fired when a reset option is selected twice in a row.

Fixes angular#10675.
jelbourn pushed a commit that referenced this issue Aug 26, 2018
…on is selected twice in a row

Fixes the select's change events being fired when a reset option is selected twice in a row.

Fixes #10675.
vivian-hu-zz pushed a commit that referenced this issue Oct 3, 2018
…on is selected twice in a row

Fixes the select's change events being fired when a reset option is selected twice in a row.

Fixes #10675.
crisbeto added a commit to crisbeto/material2 that referenced this issue Oct 13, 2018
Fixes `mat-select` emitting its change event twice when a reset value is selected, as well as when it's selected twice in a row. This PR covers angular#10859 which would've introduced another issue.

Fixes angular#10675.
Fixes angular#13579.
crisbeto added a commit to crisbeto/material2 that referenced this issue Oct 13, 2018
Fixes `mat-select` emitting its change event twice when a reset value is selected, as well as when it's selected twice in a row. This PR covers angular#10859 which would've introduced another issue.

Fixes angular#10675.
Fixes angular#13579.
vivian-hu-zz pushed a commit that referenced this issue Nov 6, 2018
Fixes `mat-select` emitting its change event twice when a reset value is selected, as well as when it's selected twice in a row. This PR covers #10859 which would've introduced another issue.

Fixes #10675.
Fixes #13579.
@eTallang
Copy link

eTallang commented Dec 7, 2018

What's the status on this issue? Any chance it will be merged anytime soon?

crisbeto added a commit to crisbeto/material2 that referenced this issue Dec 13, 2018
Fixes `mat-select` emitting its change event twice when a reset value is selected, as well as when it's selected twice in a row. This PR covers angular#10859 which would've introduced another issue.

Fixes angular#10675.
Fixes angular#13579.
crisbeto added a commit to crisbeto/material2 that referenced this issue Dec 22, 2018
Fixes `mat-select` emitting its change event twice when a reset value is selected, as well as when it's selected twice in a row. This PR covers angular#10859 which would've introduced another issue.

Fixes angular#10675.
Fixes angular#13579.
@stayingcool
Copy link

Any update as I'm facing this issue as well.

@sakolesnikov
Copy link

sakolesnikov commented Apr 2, 2019

I am struggling with the same issue right now.
"@angular/material": "^7.3.6"

@stayingcool
Copy link

Does anyone have a workaround for this issue until we have an official fix?

@sakolesnikov
Copy link

sakolesnikov commented Apr 10, 2019

I solved this issue with additional checking
onChangeFilter(matSelectChange: MatSelectChange) {
if (JSON.stringify(this.filter) != JSON.stringify(this.lastFilter)) {
...
}
this.lastFilter = JSON.parse(JSON.stringify(this.filter));
}
so I have to remember the last state of my filter and then compare it with new one. If there is difference I let pass executing further if there is no changes I just skip this invocation.
It works perfectly for me.

crisbeto added a commit to crisbeto/material2 that referenced this issue Jun 19, 2019
Fixes `mat-select` emitting its change event twice when a reset value is selected, as well as when it's selected twice in a row. This PR covers angular#10859 which would've introduced another issue.

Fixes angular#10675.
Fixes angular#13579.
@stayingcool
Copy link

Thanks!

I used this flag to bypass this problem:

'event.isUserInput'

Template

<mat-select placeholder="Assign Order"
       formControlName="selectFormControl">
      <mat-option (onSelectionChange)="assignOrder($event)">None</mat-option>
      <mat-option *ngFor="let u of users" [value]="u 
           (onSelectionChange)="assignOrder($event)">{{u.value}}</mat-option>
</mat-select>

TS

assignOrder($event){
  if (event.isUserInput) {
    // Do what you want here. This will be invoked only once!
  }
}

@soraky
Copy link

soraky commented Aug 27, 2019

Is there any thing new with this issue? Every other work around isn't really a solution.

crisbeto added a commit to crisbeto/material2 that referenced this issue Dec 29, 2019
Fixes `mat-select` emitting its change event twice when a reset value is selected, as well as when it's selected twice in a row. This PR covers angular#10859 which would've introduced another issue.

Fixes angular#10675.
Fixes angular#13579.
@FTello31
Copy link

FTello31 commented Feb 7, 2020

Is there any thing new with this issue? x2

@FTello31
Copy link

FTello31 commented Feb 7, 2020

I develop this work around (I'm was working with forms too so...), setting the value to undefined to reset the mat-select.

HTML

<mat-form-field>
          <mat-label>Add roles</mat-label>
          <mat-select formControlName="rolesFormCtrlStepper3" (selectionChange)="createRole($event.value)">
                <mat-option *ngFor="let roleComboBox of rolesComboBox" [value]="roleComboBox">
                             {{roleComboBox}}
                </mat-option>
           </mat-select>
</mat-form-field>

TS

createRole(r) {
...
...
    this.formArray.get([2]).get('rolesFormCtrlStepper3').setValue(undefined);
}

mmalerba pushed a commit that referenced this issue Apr 7, 2020
Fixes `mat-select` emitting its change event twice when a reset value is selected, as well as when it's selected twice in a row. This PR covers #10859 which would've introduced another issue.

Fixes #10675.
Fixes #13579.
andrewseguin pushed a commit that referenced this issue Jul 11, 2020
Fixes `mat-select` emitting its change event twice when a reset value is selected, as well as when it's selected twice in a row. This PR covers #10859 which would've introduced another issue.

Fixes #10675.
Fixes #13579.
andrewseguin pushed a commit to andrewseguin/components that referenced this issue Jul 18, 2020
Fixes `mat-select` emitting its change event twice when a reset value is selected, as well as when it's selected twice in a row. This PR covers angular#10859 which would've introduced another issue.

Fixes angular#10675.
Fixes angular#13579.
crisbeto added a commit to crisbeto/material2 that referenced this issue Jul 21, 2020
Fixes `mat-select` emitting its change event twice when a reset value is selected, as well as when it's selected twice in a row. This PR covers angular#10859 which would've introduced another issue.

Fixes angular#10675.
Fixes angular#13579.
crisbeto added a commit to crisbeto/material2 that referenced this issue Jul 21, 2020
Fixes `mat-select` emitting its change event twice when a reset value is selected, as well as when it's selected twice in a row. This PR covers angular#10859 which would've introduced another issue.

Fixes angular#10675.
Fixes angular#13579.
crisbeto added a commit to crisbeto/material2 that referenced this issue Jul 23, 2020
Fixes `mat-select` emitting its change event twice when a reset value is selected, as well as when it's selected twice in a row. This PR covers angular#10859 which would've introduced another issue.

Fixes angular#10675.
Fixes angular#13579.
jelbourn pushed a commit that referenced this issue Jul 29, 2020
Fixes `mat-select` emitting its change event twice when a reset value is selected, as well as when it's selected twice in a row. This PR covers #10859 which would've introduced another issue.

Fixes #10675.
Fixes #13579.
jelbourn pushed a commit that referenced this issue Jul 29, 2020
Fixes `mat-select` emitting its change event twice when a reset value is selected, as well as when it's selected twice in a row. This PR covers #10859 which would've introduced another issue.

Fixes #10675.
Fixes #13579.

(cherry picked from commit 77b11f4)
@angular-automatic-lock-bot
Copy link

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Aug 29, 2020
wagnermaciel pushed a commit to wagnermaciel/components that referenced this issue Jan 14, 2021
)

Fixes `mat-select` emitting its change event twice when a reset value is selected, as well as when it's selected twice in a row. This PR covers angular#10859 which would've introduced another issue.

Fixes angular#10675.
Fixes angular#13579.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: material/select P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent
Projects
None yet
8 participants