From 7900f5ee226bed116bdf81b7479484bb92a464f9 Mon Sep 17 00:00:00 2001 From: Miguel Camba Date: Wed, 27 Apr 2016 15:21:42 +0100 Subject: [PATCH] Single component can be opened and closed with the spacebar (#470) --- CHANGELOG.md | 2 ++ package.json | 2 +- .../power-select/keyboard-control-test.js | 26 ++++++++++++++++--- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index be33b3d45..7b1f7ab5c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # Master +- [BUGFIX] The component can and closed with the spacebar while the trigger is focused. + # 0.10.1 - [ENHANCEMENT] Allow trigger the `onfocus` action from within the trigger component. diff --git a/package.json b/package.json index cb9602b4e..122993775 100644 --- a/package.json +++ b/package.json @@ -66,7 +66,7 @@ "dependencies": { "ember-cli-babel": "^5.1.6", "ember-cli-htmlbars": "^1.0.3", - "ember-basic-dropdown": "^0.11.0", + "ember-basic-dropdown": "^0.11.3", "ember-hash-helper-polyfill": "^0.1.0", "ember-truth-helpers": "^1.2.0" }, diff --git a/tests/integration/components/power-select/keyboard-control-test.js b/tests/integration/components/power-select/keyboard-control-test.js index 6f2d42953..7f7c6ba35 100644 --- a/tests/integration/components/power-select/keyboard-control-test.js +++ b/tests/integration/components/power-select/keyboard-control-test.js @@ -172,12 +172,12 @@ test('The component is focusable using the TAB key as any other kind of input', assert.equal(this.$('.ember-power-select-trigger').attr('tabindex'), "0", 'The trigger is reachable with TAB'); }); -test('If the component is focused, pressing ENTER opens it', function(assert) { - assert.expect(2); +test('If the component is focused, pressing ENTER toggles it', function(assert) { + assert.expect(3); this.numbers = numbers; this.render(hbs` - {{#power-select options=numbers onchange=(action (mut foo)) as |option|}} + {{#power-select options=numbers onchange=(action (mut foo)) searchEnabled=false as |option|}} {{option}} {{/power-select}} `); @@ -186,6 +186,26 @@ test('If the component is focused, pressing ENTER opens it', function(assert) { assert.equal($('.ember-power-select-dropdown').length, 0, 'The select is closed'); triggerKeydown($('.ember-power-select-trigger')[0], 13); assert.equal($('.ember-power-select-dropdown').length, 1, 'The select is opened'); + triggerKeydown($('.ember-power-select-trigger')[0], 13); + assert.equal($('.ember-power-select-dropdown').length, 0, 'The select is closed again'); +}); + +test('If the single component is focused, pressing SPACE toggles it', function(assert) { + assert.expect(3); + + this.numbers = numbers; + this.render(hbs` + {{#power-select options=numbers onchange=(action (mut foo)) searchEnabled=false as |option|}} + {{option}} + {{/power-select}} + `); + + Ember.run(() => $('.ember-power-select-trigger').focus()); + assert.equal($('.ember-power-select-dropdown').length, 0, 'The select is closed'); + triggerKeydown($('.ember-power-select-trigger')[0], 32); + assert.equal($('.ember-power-select-dropdown').length, 1, 'The select is opened'); + triggerKeydown($('.ember-power-select-trigger')[0], 32); + assert.equal($('.ember-power-select-dropdown').length, 0, 'The select is closed again'); }); test('If the single component is focused, pressing KEYDOWN opens it', function(assert) {