From 4840fea0bcb4da9991e341262e2fcfa8fbc6bb03 Mon Sep 17 00:00:00 2001 From: Bryan Housel Date: Tue, 27 Mar 2018 22:15:19 -0400 Subject: [PATCH] Don't autocomplete numeric values in the combobox (closes #4935) --- modules/lib/d3.combobox.js | 3 +++ test/spec/lib/d3.combobox.js | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/modules/lib/d3.combobox.js b/modules/lib/d3.combobox.js index a33ba9e1c..c424b797c 100644 --- a/modules/lib/d3.combobox.js +++ b/modules/lib/d3.combobox.js @@ -211,6 +211,9 @@ export function d3combobox() { idx = -1; if (!v) return; + // Don't autocomplete if user is typing a number - #4935 + if (!isNaN(parseFloat(v)) && isFinite(v)) return; + var best = -1; var suggestion, compare; diff --git a/test/spec/lib/d3.combobox.js b/test/spec/lib/d3.combobox.js index 7cc633ca5..9a803f004 100644 --- a/test/spec/lib/d3.combobox.js +++ b/test/spec/lib/d3.combobox.js @@ -160,6 +160,18 @@ describe('d3.combobox', function() { expect(body.selectAll('.combobox-option.selected').text()).to.equal('foo'); // skip foobar }); + it('does not autocomplete numeric options', function() { + var numeric = [ + {title: '100', value: '100'}, + {title: '110', value: '110'} + ]; + input.call(combobox.data(numeric)); + focusTypeahead(input); + simulateKeypress('1'); + simulateKeypress('0'); + expect(body.selectAll('.combobox-option.selected').size()).to.equal(0); + }); + it('selects the completed portion of the value', function() { input.call(combobox.data(data)); focusTypeahead(input);