components icon indicating copy to clipboard operation
components copied to clipboard

MdCheckBox is behaving different to native checkbox

Open mmrath opened this issue 10 years ago • 9 comments

Bug, feature request, or proposal: Bug

Links for both native and MdCheckBox version below

What is the expected behavior?

Native Checkbox version http://plnkr.co/edit/cZbFWOlCeZuj7YdUczPm?p=preview

What is the current behavior?

This is with MdCheckBox http://plnkr.co/edit/FFpqdNhQfvbUynbPE1ZD?p=preview

What are the steps to reproduce?

  1. Click on the top select all check box for 'Write'
  2. Now click (reset) Write for one of the resource

Native version has the desired behaviour that is, unselect the top most checkbox if one of the below one is unchecked. But with MdCheckBox the change to reset top most checkbox triggers on change event, which is resetting all the below checkboxes.

I don't know which one is correct behaviour or both are correct.

Any help to get the MdCheckBox version working is appreciated.

What is the use-case or motivation for changing an existing behavior?

Get MdCheckBox behave as close to native checkbox as possible

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

alpha 5

Is there anything else we should know?

Bo

mmrath avatar May 29 '16 12:05 mmrath

Interesting also, check this out

http://plnkr.co/edit/nDWK7EmmCBgMkHIKRIg7?p=preview

the checkbox click function is called twice, why so?

sendilkumarn avatar May 30 '16 09:05 sendilkumarn

@sendilkumarn I have experienced the double fires since the last release (alpha 5).

zahlprish avatar May 30 '16 15:05 zahlprish

@jelbourn is this correct, I will submit a PR if so

Add a method for click event in checkbox. we can re use the checkbox change method itself. This kinda solves problem.

sendilkumarn avatar May 30 '16 16:05 sendilkumarn

It seems that the issue here isn't a double-firing change, but is instead caused by different behavior between native inputs and our checkbox for when change events should be fired. Native inputs only fire a change event when they have user focus. The MdCheckbox fires a change event whenever it changes for any reason. I've actually had a note written about this to discuss with the rest of the team for a couple weeks now.

jelbourn avatar Jun 02 '16 19:06 jelbourn

Yeah agree to that. But clicks firing two times is also an issue. Check #613

Aim is to prevent double firing of click event

sendilkumarn avatar Jun 02 '16 22:06 sendilkumarn

one more weird behavior with respect to checkbox. Is this even correct or am I missing out anything.

click / change one - just printing ng model value => returns true / false click / change two - just printing ng model value => returns MDCheckboxChange Object

is this expected?

sendilkumarn avatar Jun 03 '16 16:06 sendilkumarn

I've set up a simple plunkr to demonstrate the duplicate events by logging to the console - http://embed.plnkr.co/3IGFLbFEpvVldtOOosAq/

On first click one change and two click events are fired. On subsequent clicks two change and two click events are fired.

I'm having to set 10ms timeouts on all material inputs before reading model values from them - it would be great if they could update in the current digest cycle, but I presume the delays are there to avoid change after checked warnings.

matthewdenobrega avatar Jun 16 '16 06:06 matthewdenobrega

I also have this issue where I'm getting an erroneous (changed) event to fire when the [ngModel] causes the checkbox to change from checked to unchecked. This behavior does not happen for md-input.

ImAllInNow avatar Jul 11 '16 21:07 ImAllInNow

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.