mirror of
https://github.com/discourse/discourse.git
synced 2025-05-15 00:03:12 +08:00
Merge branch 'autocomplete-search' of https://github.com/cpradio/discourse into autocomplete-search
This commit is contained in:
commit
e1bdc841ec
@ -5,6 +5,11 @@ import { createWidget } from 'discourse/widgets/widget';
|
|||||||
createWidget('search-term', {
|
createWidget('search-term', {
|
||||||
tagName: 'input',
|
tagName: 'input',
|
||||||
buildId: () => 'search-term',
|
buildId: () => 'search-term',
|
||||||
|
buildKey: (attrs) => `search-term-${attrs.id}`,
|
||||||
|
|
||||||
|
defaultState() {
|
||||||
|
return { autocompleteIsOpen: false };
|
||||||
|
},
|
||||||
|
|
||||||
buildAttributes(attrs) {
|
buildAttributes(attrs) {
|
||||||
return { type: 'text',
|
return { type: 'text',
|
||||||
@ -12,8 +17,17 @@ createWidget('search-term', {
|
|||||||
placeholder: attrs.contextEnabled ? "" : I18n.t('search.title') };
|
placeholder: attrs.contextEnabled ? "" : I18n.t('search.title') };
|
||||||
},
|
},
|
||||||
|
|
||||||
|
keyDown(e) {
|
||||||
|
const state = this.state;
|
||||||
|
if ($(`#${this.buildId()}`).parent().find('.autocomplete').length !== 0) {
|
||||||
|
state.autocompleteIsOpen = true;
|
||||||
|
} else {
|
||||||
|
state.autocompleteIsOpen = false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
keyUp(e) {
|
keyUp(e) {
|
||||||
if (e.which === 13) {
|
if (e.which === 13 && !this.state.autocompleteIsOpen) {
|
||||||
return this.sendWidgetAction('fullSearch');
|
return this.sendWidgetAction('fullSearch');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user