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

v-model on custom component behaves differently in IE and Edge #4796

Closed
andrewcourtice opened this issue Jan 26, 2017 · 12 comments
Closed

v-model on custom component behaves differently in IE and Edge #4796

andrewcourtice opened this issue Jan 26, 2017 · 12 comments

Comments

@andrewcourtice
Copy link

andrewcourtice commented Jan 26, 2017

Vue Version

2.1.10

Issue Description

Based on other examples I've seen, when embedding a checkbox in a custom component a 'proxy' value has to be used to emulate the native v-model behaviour for a checkbox or radio input.

This is particularly important when binding v-model on the custom component to an array as opposed to a boolean.

This technique works fine in Firefox and Webkit-based browsers but fails in IE and Edge.

Demonstration of Issue

http://jsfiddle.net/andrewcourtice/jgxzbbvv/

Steps to Reproduce

  1. Open the above fiddle in a Firefox or a Webkit-based browser
  2. Check the checkboxes and note the array of selected items being updated correctly
  3. Open the above fiddle in IE or Edge
  4. Check the checkboxes and note the difference in behaviour to step 2

Expected Outcome

The array of selected items (and the raw output) should be updated as each item is checked.

Actual Outcome

In IE and Edge the raw output is displaying a boolean value and the checked state of the checkboxes is inconsistent.

Thanks!

@denistsoi
Copy link

denistsoi commented Jan 27, 2017

Added IE-Edge (VirtualBox running Edge Windows 10)
screencap for reference; (no errors are popping up on the console either).

Edit: (noticing how clicking john returns false)
Extremely odd behaviour;

screen shot 2017-01-27 at 3 57 56 pm

@sqal
Copy link
Contributor

sqal commented Jan 28, 2017

It's worth pointing out this worked fine in Vue <= 2.1.8

@andrewcourtice andrewcourtice changed the title Custom checkbox component behaves differently in IE and Edge v-model on custom component behaves differently in IE and Edge Jan 31, 2017
@sunnyone
Copy link

sunnyone commented Feb 2, 2017

+1

@denistsoi
Copy link

@sunnyone, @Thijs5 - and for anyone else; don't populate the issue feed with +1; it's unhelpful and clearly, you need to use the "ADD REACTION" button if you want to drive attention to an issue.

@posva
Copy link
Member

posva commented Feb 14, 2017

Hey, sorry for the delay. Completely forgot about this.
This happens because the onChange fires before the computed setter in Edge. If you're using a computed setter, you don't need an onChange event handler, you should simply emit in the setter:

http://jsfiddle.net/bsy8ss2L/

@jdalton
Copy link

jdalton commented Feb 21, 2017

@posva Could you provide a bit more info on the "onChange fires before the computed setter in Edge". How is the computed setter fired? I'm trying to get enough info for an Edge bug report.

@yyx990803
Copy link
Member

yyx990803 commented Feb 21, 2017

@jdalton AFAIK, the problem is that when clicking on the checkbox, the order of the click and change events being fired is different in IE/Edge than that in other browsers:

https://jsfiddle.net/rj3g9j0y/

Chrome/FF: click -> change
IE/Edge/Safari: change -> click

I'm not sure if this behavior is specified anywhere in the spec though.

@jdalton
Copy link

jdalton commented Feb 21, 2017

Ah nice! Thanks for the simplified repro!

@posva
Copy link
Member

posva commented Feb 21, 2017

I'm trying to get enough info for an Edge bug report

@jdalton awesome!

@yyx990803 BTW, should we close this since it's related to the browser firing in a different order?

@jdalton
Copy link

jdalton commented Feb 21, 2017

I've reported the issue internally. I'll ping back when I get more info.

@yyx990803
Copy link
Member

yyx990803 commented Feb 22, 2017

@jdalton update: it seems PhantomJS and Safari also fire change before click.

The spec states that:

Default actions are usually performed after the event dispatch has been completed, but in exceptional cases they may also be performed immediately before the event is dispatched.

So technically, change doesn't have to be fired after click. However, imo it really should because logically, change is a result of the default action for click. For example, if I do event.preventDefault() inside a click listener on a checkbox, it should be able to prevent the change event from happening altogether (this is the current behavior in Chrome/FF, but not in Safari/IE/Edge/PhantomJS).

@jdalton
Copy link

jdalton commented Feb 22, 2017

Oh ya, not arguing for the current behavior. I think Edge should align with Chrome/FF.

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

No branches or pull requests

7 participants