From c4cb8729eb7b6612f19655f721e3f9becbb1a8bf Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Fri, 21 Jun 2013 20:08:15 -0700 Subject: [PATCH] Fix tab behavior in tag list --- js/lib/d3.combobox.js | 5 +++-- test/spec/lib/d3.combobox.js | 38 ++++++++++++++++++++++++++++-------- 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/js/lib/d3.combobox.js b/js/lib/d3.combobox.js index aa2b73ee4..b7aa9513b 100644 --- a/js/lib/d3.combobox.js +++ b/js/lib/d3.combobox.js @@ -99,7 +99,7 @@ d3.combobox = function() { break; // tab case 9: - container.selectAll('a.selected').trigger('click'); + container.selectAll('a.selected').each(event.accept); break; // return case 13: @@ -127,7 +127,8 @@ d3.combobox = function() { break; // return case 13: - container.selectAll('a.selected').trigger('click'); + container.selectAll('a.selected').each(event.accept); + hide(); break; } } diff --git a/test/spec/lib/d3.combobox.js b/test/spec/lib/d3.combobox.js index 0047a2cc2..e8893662e 100644 --- a/test/spec/lib/d3.combobox.js +++ b/test/spec/lib/d3.combobox.js @@ -30,6 +30,7 @@ describe("d3.combobox", function() { case '↑': case '↓': + case '↩': break; case '⌫': @@ -117,14 +118,6 @@ describe("d3.combobox", function() { expect(input.property('selectionEnd')).to.equal(8); }); - it("does not select on ⇥", function() { - input.call(combobox.data(data)); - input.node().focus(); - simulateKeypress('c'); - simulateKeypress('⇥'); - expect(body.selectAll('.combobox-option.selected').size()).to.equal(0); - }); - it("does not select when value is empty", function() { input.call(combobox.data(data)); input.node().focus(); @@ -180,4 +173,33 @@ describe("d3.combobox", function() { expect(body.selectAll('.combobox-option.selected').text()).to.equal('abbot'); expect(input.property('value')).to.equal('abbot'); }); + + it("emits accepted event with selected datum on ⇥", function(done) { + combobox.on('accept', function(d) { + expect(d).to.eql({title: 'abbot', value: 'abbot'}); + done(); + }); + input.call(combobox.data(data)); + input.node().focus(); + simulateKeypress('a'); + simulateKeypress('⇥'); + }); + + it("emits accepted event with selected datum on ↩", function(done) { + combobox.on('accept', function(d) { + expect(d).to.eql({title: 'abbot', value: 'abbot'}); + done(); + }); + input.call(combobox.data(data)); + input.node().focus(); + simulateKeypress('a'); + simulateKeypress('↩'); + }); + + it("hides on ↩", function() { + input.call(combobox.data(data)); + input.node().focus(); + simulateKeypress('↩'); + expect(body.selectAll('.combobox').size()).to.equal(0); + }); });