FIX: Don't close search menu on link clicked when context is enabled.

This commit is contained in:
Guo Xiang Tan 2017-01-17 12:35:48 +08:00
parent de6ca4f736
commit ee58c4cd94
5 changed files with 14 additions and 8 deletions

View File

@ -225,8 +225,8 @@ export default createWidget('header', {
this.state.searchVisible = false;
},
linkClickedEvent() {
this.closeAll();
linkClickedEvent(attrs) {
if (!attrs.searchContextEnabled) this.closeAll();
this.updateHighlight();
},

View File

@ -79,7 +79,7 @@ export default createWidget('link', {
e.preventDefault();
return this.sendWidgetAction(this.attrs.action, this.attrs.actionParam);
} else {
this.sendWidgetEvent('linkClicked');
this.sendWidgetEvent('linkClicked', this.attrs);
}
return DiscourseURL.routeToTag($(e.target).closest('a')[0]);

View File

@ -25,7 +25,8 @@ function createSearchResult(type, linkField, fn) {
return h('li', this.attach('link', {
href: r.get(linkField),
contents: () => fn.call(this, r, attrs.term),
className: 'search-link'
className: 'search-link',
searchContextEnabled: this.attrs.searchContextEnabled
}));
});
}
@ -98,7 +99,11 @@ createWidget('search-menu-results', {
}
return [
h('ul', this.attach(rt.componentName, { results: rt.results, term: attrs.term })),
h('ul', this.attach(rt.componentName, {
searchContextEnabled: this.attrs.searchContextEnabled,
results: rt.results,
term: attrs.term
})),
h('div.no-results', more)
];
});

View File

@ -125,7 +125,8 @@ export default createWidget('search-menu', {
results.push(this.attach('search-menu-results', { term: searchData.term,
noResults: searchData.noResults,
results: searchData.results,
invalidTerm: searchData.invalidTerm }));
invalidTerm: searchData.invalidTerm,
searchContextEnabled: searchData.contextEnabled }));
}
}

View File

@ -298,12 +298,12 @@ export default class Widget {
return result;
}
sendWidgetEvent(name) {
sendWidgetEvent(name, attrs) {
const methodName = `${name}Event`;
return this.rerenderResult(() => {
const widget = this._findAncestorWithProperty(methodName);
if (widget) {
return widget[methodName]();
return widget[methodName](attrs);
}
});
}