From 31e1aa806ad69dfc11399262d1a994678a9e1cbb Mon Sep 17 00:00:00 2001 From: Chris Bonser Date: Sat, 17 Mar 2018 20:49:16 -0500 Subject: [PATCH] Resolves #899; component:paper-radio-group select() should handle 0 properly --- addon/components/paper-radio-group.js | 3 ++- .../components/paper-radio-group-test.js | 26 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/addon/components/paper-radio-group.js b/addon/components/paper-radio-group.js index 6015ce15b..3c9080f4e 100644 --- a/addon/components/paper-radio-group.js +++ b/addon/components/paper-radio-group.js @@ -9,6 +9,7 @@ import { assert } from '@ember/debug'; import layout from '../templates/components/paper-radio-group'; import FocusableMixin from 'ember-paper/mixins/focusable-mixin'; import { ParentMixin } from 'ember-composability-tools'; +import { isPresent } from '@ember/utils'; /** * @class PaperRadioGroup @@ -57,7 +58,7 @@ export default Component.extend(FocusableMixin, ParentMixin, { let groupValue = this.get('groupValue'); let index = 0; - if (groupValue) { + if (isPresent(groupValue)) { index = this.get('childValues').indexOf(groupValue); index += increment; let length = this.get('childValues.length'); diff --git a/tests/integration/components/paper-radio-group-test.js b/tests/integration/components/paper-radio-group-test.js index 829ef4400..fc4cdadaf 100644 --- a/tests/integration/components/paper-radio-group-test.js +++ b/tests/integration/components/paper-radio-group-test.js @@ -173,6 +173,32 @@ test('should be possible to select next with up/left arrow in a paper-radio-grou assert.equal(this.get('groupValue'), '3'); }); +test('should be possible to select next with down/right arrow in a paper-radio-group (when group.radio value is 0)', function(assert) { + assert.expect(2); + + this.render(hbs` + {{#paper-radio-group groupValue=groupValue onChange=(action (mut groupValue)) as |group|}} + {{#group.radio value=0}} + Radio button 1 + {{/group.radio}} + {{#group.radio value="2"}} + Radio button 2 + {{/group.radio}} + {{#group.radio value="3"}} + Radio button 3 + {{/group.radio}} + {{/paper-radio-group}} + `); + + triggerKeydown(this.$('md-radio-group').get(0), 40); + + assert.equal(this.get('groupValue'), 0); + + triggerKeydown(this.$('md-radio-group').get(0), 39); + + assert.equal(this.get('groupValue'), '2'); +}); + /* test('the `onChange` action is mandatory for paper-radio-group', function(assert) { assert.expect(1);