Skip to content

Fix: groupValue not updated w.r.t value on change. #150

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ The block form emits a label wrapping the input element and any elements passed
```javascript
<RadioButton
@value="blue"
@groupValue=color
@groupValue={{this.color}}
@onBeforeChange={{fn (mut this.color)}}
@changed={{this.colorChanged}}
>
<span>Blue</span>
Expand All @@ -44,6 +45,7 @@ If you want more control over the DOM, the non-block form only emits a single in
@value="green"
@groupValue={{this.color}}
@name="colors"
@onBeforeChange={{fn (mut this.color)}}
@changed={{this.colorChanged}}
/>

Expand Down Expand Up @@ -90,9 +92,10 @@ _Optional:_

_Actions:_

| name | description |
| ------- | ------------------------------------------------------------------------ |
| changed | fires when user interaction causes a radio-button to update `groupValue` |
| name | description | optional |
| ------- | ------------------------------------------------------------------------ |--------- |
| changed | fires when user interaction causes a radio-button to update `groupValue` | true |
| onBeforeChange | mutate the passed prop i.e `groupValue` with selected radio value | false |

## Installing

Expand Down
1 change: 0 additions & 1 deletion addon/components/radio-button-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export default class RadioButtonInputComponent extends Component {

@action change() {
if (this.args.groupValue !== this.args.value) {
// this.set('groupValue', value);
once(this.args, 'changed', this.args.value);
}
}
Expand Down
8 changes: 7 additions & 1 deletion addon/components/radio-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,13 @@ export default class RadioButtonComponent extends Component {
}

@action changed(newValue) {
let changedAction = this.args.changed;
let changedAction = this.args.changed,
onBeforeChangeAction = this.args.onBeforeChange;

//todo: make it required, instead of optional
if (onBeforeChangeAction) {
onBeforeChangeAction(newValue);
}

// providing a closure action is optional
if (changedAction) {
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/components/radio-button-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ module('Integration | Components | Radio Button', function (hooks) {
this.set('changed', (newValue) => {
changedActionCallCount++;
assert.strictEqual(newValue, 'component-value', 'updates groupValue');
this.set('groupValue', newValue);
});

await render(hbs`
<RadioButton
@groupValue={{this.groupValue}}
@value='component-value'
@onBeforeChange={{fn (mut this.groupValue)}}
@changed={{this.changed}}
/>
`);
Expand Down