Fix tab behavior in tag list

This commit is contained in:
John Firebaugh
2013-06-21 20:08:15 -07:00
parent 24d3333d89
commit c4cb8729eb
2 changed files with 33 additions and 10 deletions
+3 -2
View File
@@ -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;
}
}
+30 -8
View File
@@ -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);
});
});