FIX: Make it a tad bit harder to accidentally redirect to full page search while autocomplete is open

This commit is contained in:
cpradio 2017-03-03 22:48:28 -05:00
parent e1bdc841ec
commit 3eb51f0d77
1 changed files with 8 additions and 2 deletions

View File

@ -6,9 +6,11 @@ createWidget('search-term', {
tagName: 'input', tagName: 'input',
buildId: () => 'search-term', buildId: () => 'search-term',
buildKey: (attrs) => `search-term-${attrs.id}`, buildKey: (attrs) => `search-term-${attrs.id}`,
KEYCODE_AT_SIGN: 50,
KEYCODE_POUND_SIGN: 51,
defaultState() { defaultState() {
return { autocompleteIsOpen: false }; return { autocompleteIsOpen: false, shiftKeyEntry: false };
}, },
buildAttributes(attrs) { buildAttributes(attrs) {
@ -19,6 +21,9 @@ createWidget('search-term', {
keyDown(e) { keyDown(e) {
const state = this.state; const state = this.state;
state.shiftKeyEntry = e.shiftKey &&
(e.keyCode === this.KEYCODE_AT_SIGN || e.keyCode === this.KEYCODE_POUND_SIGN);
if ($(`#${this.buildId()}`).parent().find('.autocomplete').length !== 0) { if ($(`#${this.buildId()}`).parent().find('.autocomplete').length !== 0) {
state.autocompleteIsOpen = true; state.autocompleteIsOpen = true;
} else { } else {
@ -27,7 +32,8 @@ createWidget('search-term', {
}, },
keyUp(e) { keyUp(e) {
if (e.which === 13 && !this.state.autocompleteIsOpen) { const state = this.state;
if (e.which === 13 && !state.shiftKeyEntry && !state.autocompleteIsOpen) {
return this.sendWidgetAction('fullSearch'); return this.sendWidgetAction('fullSearch');
} }