Skip to content

Fix passive color radius and fix switch label clicks#4703

Merged
balloob merged 2 commits into
devfrom
color-radius-fix-switch-label
Feb 4, 2020
Merged

Fix passive color radius and fix switch label clicks#4703
balloob merged 2 commits into
devfrom
color-radius-fix-switch-label

Conversation

@bramkragten
Copy link
Copy Markdown
Member

Fixes #4686

private _haChangeHandler(e: Event) {
this.mdcFoundation.handleChange(e);
// catch "click" event and sync properties
this.checked = this.formElement.checked;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We shouldn't do this. This will lead to nasty bugs.

When a parent renders this element, it will diff against itself to know if it needs to change the property.

So let's say this happens:

  • Parent renders checked = true
  • User changes it, sets checked=false
  • Parent renders checked = true -> this will not update <ha-switch> because it already rendered true last time, even though the property current value is false

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This was actually a copy/paste from mwc-switch, because it was a private function

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It would be weird of the parent not to update it's value btw when the switch is changed.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Also, there is no value-changed event, just the normal change event of the native checkbox, so it would be impossible for the parent to see what the state is when we would not update the prop? ev.target.checked would no longer work.

I could rewrite it and fire the value-changed event and not do this, but that would differ us a lot from mwc-switch and means a lot of change.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ok let's keep it.

Comment thread src/panels/config/zone/dialog-zone-detail.ts Outdated
@bramkragten bramkragten force-pushed the color-radius-fix-switch-label branch from 3025bdf to 0e7ee71 Compare February 3, 2020 10:37
@bramkragten bramkragten added this to the 0.105 milestone Feb 3, 2020
@balloob balloob merged commit 42cbe86 into dev Feb 4, 2020
@delete-merged-branch delete-merged-branch Bot deleted the color-radius-fix-switch-label branch February 4, 2020 06:32
@lock lock Bot locked and limited conversation to collaborators Feb 5, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Zones editor map preview - passive zones always displayed orange instead of gray

3 participants