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

fix(radio): update radio group when programmatically uncheck a radio button #1561

Merged
merged 1 commit into from
Nov 1, 2016

Conversation

tinayuangao
Copy link
Contributor

  • added test cases for uncheck
  • notify all radio buttons after status change and radio group value change to avoid notify radio group twice

For issue #609

@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Oct 21, 2016
@@ -216,6 +216,42 @@ describe('MdRadio', () => {

expect(radioInstances.every(radio => !radio.checked)).toBe(true);
});

it('should set radio group to null if uncheck a checked radio button programmatically', () => {
Copy link
Member

Choose a reason for hiding this comment

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

should update the group's selected radio to null when unchecking that radio programmatically

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.


expect(changeSpy).toHaveBeenCalledTimes(2);
expect(groupInstance.value).toBeFalsy();
expect(radioInstances.every(radio => !radio.checked)).toBe(true);
Copy link
Member

Choose a reason for hiding this comment

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

Should you also expect(groupInstance.selected).toBeNull() ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

expect(radioInstances.every(radio => !radio.checked)).toBe(true);
});

it('should notify the group if check another radio button', () => {
Copy link
Member

Choose a reason for hiding this comment

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

should fire a change event from the group whenever a radio checked state changes

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

this._checked = newCheckedState;

if (newCheckedState && this.radioGroup && this.radioGroup.value != this.value) {
this.radioGroup.selected = this;
} else if (!newCheckedState && this.radioGroup && this.radioGroup.value == this.value) {
// For programmatically uncheck radio button, notify the group.
Copy link
Member

Choose a reason for hiding this comment

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

/// When unchecking the selected radio button, update the selected radio
// property on the group. 

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Contributor Author

@tinayuangao tinayuangao left a comment

Choose a reason for hiding this comment

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

Comments addressed, PTAL. Thanks!

expect(radioInstances.every(radio => !radio.checked)).toBe(true);
});

it('should notify the group if check another radio button', () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done


expect(changeSpy).toHaveBeenCalledTimes(2);
expect(groupInstance.value).toBeFalsy();
expect(radioInstances.every(radio => !radio.checked)).toBe(true);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@@ -216,6 +216,42 @@ describe('MdRadio', () => {

expect(radioInstances.every(radio => !radio.checked)).toBe(true);
});

it('should set radio group to null if uncheck a checked radio button programmatically', () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

this._checked = newCheckedState;

if (newCheckedState && this.radioGroup && this.radioGroup.value != this.value) {
this.radioGroup.selected = this;
} else if (!newCheckedState && this.radioGroup && this.radioGroup.value == this.value) {
// For programmatically uncheck radio button, notify the group.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@tinayuangao tinayuangao force-pushed the unchecked branch 3 times, most recently from 14a235b to cd66748 Compare October 28, 2016 16:37
@jelbourn
Copy link
Member

jelbourn commented Nov 1, 2016

LGTM

@jelbourn jelbourn added pr: lgtm action: merge The PR is ready for merge by the caretaker and removed pr: needs review labels Nov 1, 2016
@hansl hansl merged commit c108607 into angular:master Nov 1, 2016
@tinayuangao tinayuangao deleted the unchecked branch November 2, 2016 17:37
@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 Sep 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants