Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

fix(select): Do not fire change event on programmatic change #5255

Merged
merged 5 commits into from
Nov 27, 2019

Conversation

bonniezhou
Copy link
Contributor

Fixes #5234

Changes to layout-grid and textfield are purely to pass the linter.

this.foundation_.setValue(value);
// Replicate behavior of native select, which does not emit change events
// when the value is changed programmatically.
this.foundation_.setValue(value, false /* notifyChange */);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since setValue is used for programmatic change of select's value and I think we do not need notifyChange boolean.

Only handleChange() triggers event, where as setValue() does not.

WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. Removed the boolean from setValue so that it's only in handleChange.

@codecov-io
Copy link

codecov-io commented Nov 14, 2019

Codecov Report

Merging #5255 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #5255   +/-   ##
=======================================
  Coverage   98.63%   98.63%           
=======================================
  Files         122      122           
  Lines        5991     5991           
  Branches      770      768    -2     
=======================================
  Hits         5909     5909           
  Misses         81       81           
  Partials        1        1
Impacted Files Coverage Δ
packages/mdc-select/foundation.ts 98.06% <100%> (+1.44%) ⬆️
packages/mdc-select/component.ts 97.26% <0%> (-1.64%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7fd17ce...92f3893. Read the comment docs.

@mdc-web-bot
Copy link
Collaborator

All 731 screenshot tests passed for commit a98a20e vs. master! 💯🎉

@@ -227,9 +230,8 @@ export class MDCSelectFoundation extends MDCFoundation<MDCSelectAdapter> {
/**
* Handles value changes, via change event or programmatic updates.
*/
handleChange() {
handleChange(notifyChange = true) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can remove boolean from here as well and make handleChange always notify the change.

We'll need to abstract out the code from handleChange to private method so it can be reused in other places (setValue, setSelectedIndex, etc). It is a good practice to bind handle* methods to only event callbacks in component implementation so we won't break other calls when we introduce any changes to handleChange callback in future.

Currently handleChange is called in component implementation and also used has helper function within foundation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated. setValue and setSelectedIndex now both won't fire a change event since they are both programmatic changes.

@abhiomkar
Copy link
Collaborator

Please let me know when this PR is ready for review.

@mdc-web-bot
Copy link
Collaborator

All 731 screenshot tests passed for commit 92f3893 vs. master! 💯🎉

Copy link
Collaborator

@abhiomkar abhiomkar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MDCSelect 4.0.0 fires change event twice
5 participants