diff --git a/common/common.scss b/common/common.scss index 57f1e9b..2d1a997 100644 --- a/common/common.scss +++ b/common/common.scss @@ -34,21 +34,21 @@ $max-width: 600px; max-width: $max-width; } - .search-menu { - position: relative; - display: flex; - flex-wrap: wrap; - .d-icon-search { - margin: 0; - } - .browser-search-tip { - display: none; - } - .search-input input#search-term[type="text"] { - margin: 0; - width: 100%; - padding-left: 2.25em; - } + .menu-panel-results .menu-panel { + position: unset; + padding: 0; + } + + .d-icon-search { + margin: 0; + } + .browser-search-tip { + display: none; + } + .search-input input#search-term[type="text"] { + margin: 0; + width: 100%; + // padding: 0; } .search-input { @@ -75,12 +75,12 @@ $max-width: 600px; } .btn.search-icon:not(.has-search-button-text) { - position: absolute; z-index: 2; background: transparent; line-height: 1; color: var(--primary-medium); height: 100%; + padding-right: 0.25em; .discourse-no-touch & { &:hover { background: transparent; @@ -97,19 +97,24 @@ $max-width: 600px; column-gap: 0.5em; background-color: var(--tertiary); color: var(--secondary); + flex: none; &:hover { background-color: var(--tertiary-hover); } .d-icon { color: var(--secondary); } - + .search-input #search-term[type="text"] { - padding-left: 0.5em; - } } - .search-input .btn.search-context { - margin: 0; + .search-input .search-context { + // margin-right: 1em !important; + } + + // hide the search icon when a search context is selected + // eg when searching in a topic + .search-input .search-context + .search-icon:not(.has-search-button-text), + .search-input .search-context ~ .search-icon:not(.has-search-button-text) { + display: none; } .results { diff --git a/javascripts/discourse/api-initializers/init-search-banner.js b/javascripts/discourse/api-initializers/init-search-banner.js index c0be64a..c3b0218 100644 --- a/javascripts/discourse/api-initializers/init-search-banner.js +++ b/javascripts/discourse/api-initializers/init-search-banner.js @@ -12,158 +12,4 @@ export default apiInitializer("1.14.0", (api) => { : "below-site-header", SearchBanner ); - - // Simplified version of header search theme component - const searchMenuWidget = api.container.factoryFor("widget:search-menu"); - const corePanelContents = searchMenuWidget.class.prototype["panelContents"]; - - api.reopenWidget("search-menu", { - buildKey(attrs) { - let type = attrs.formFactor || "menu"; - return `search-${type}`; - }, - - defaultState(attrs) { - return { - formFactor: attrs.formFactor || "menu", - showHeaderResults: false, - inTopicContext: attrs.inTopicContext, - }; - }, - - html(attrs, state) { - if (this.state.formFactor === "widget") { - return this.panelContents(); - } else { - return this._super(attrs, state); - } - }, - - clickOutside() { - const formFactor = this.state.formFactor; - if (formFactor === "menu") { - return this.sendWidgetAction("toggleSearchMenu"); - } else { - this.state.showHeaderResults = false; - this.scheduleRerender(); - } - }, - - click() { - const formFactor = this.state.formFactor; - if (formFactor === "widget") { - this.showResults(); - } - }, - - showResults() { - this.state.showHeaderResults = true; - this.scheduleRerender(); - }, - - linkClickedEvent(attrs) { - if (attrs) { - const { searchLogId, searchResultId, searchResultType } = attrs; - if (searchLogId && searchResultId && searchResultType) { - logSearchLinkClick({ - searchLogId, - searchResultId, - searchResultType, - }); - } - } - - const formFactor = this.state.formFactor; - - if (formFactor === "widget") { - this.state.showHeaderResults = false; - this.scheduleRerender(); - } - }, - - focusSearchInput() { - const searchInput = - this.state.formFactor === "widget" - ? document.querySelector(".search-widget #search-term") - : document.querySelector(".search-menu #search-term"); - - searchInput.focus(); - searchInput.select(); - }, - - clearContext() { - this.sendWidgetAction("clearSearch"); - this.sendWidgetAction("clearSearchWidgetContext"); - this.state.inTopicContext = false; - }, - - clearSearchWidgetContext() { - this.state.inTopicContext = false; - }, - - panelContents() { - const formFactor = this.state.formFactor; - let showHeaderResults = - this.state.showHeaderResults == null || - this.state.showHeaderResults === true; - let contents = []; - - let buttonClass = - I18n.t(themePrefix("search_banner.search_button_text")) === "" - ? "btn search-icon" - : "btn search-icon has-search-button-text"; - - if (formFactor === "widget") { - contents.push( - this.attach("link", { - href: this.fullSearchUrl({ expanded: true }), - contents: () => [ - iconNode("search"), - h( - "span", - I18n.t(themePrefix("search_banner.search_button_text")) - ), - ], - className: buttonClass, - title: "search.open_advanced", - }) - ); - } - - contents = contents.concat(...corePanelContents.call(this)); - if (formFactor === "menu" || showHeaderResults) { - return contents; - } else { - return contents.filter((widget) => { - return ( - widget.name !== "search-menu-results" && - widget.name !== "search-context" - ); - }); - } - }, - }); - - api.createWidget("search-widget", { - tagName: "div.search-widget", - - html() { - const searchMenuVisible = this.state.searchVisible; - - if (!searchMenuVisible && !this.attrs.topic) { - return this.attach("search-menu", { - contextEnabled: this.state.contextEnabled, - formFactor: "widget", - }); - } - }, - - clearSearchWidgetContext() { - this.state.inTopicContext = false; - }, - - setTopicContext() { - this.state.inTopicContext = true; - }, - }); }); diff --git a/javascripts/discourse/components/search-banner.hbs b/javascripts/discourse/components/search-banner.hbs index 8dbd788..3a54380 100644 --- a/javascripts/discourse/components/search-banner.hbs +++ b/javascripts/discourse/components/search-banner.hbs @@ -11,7 +11,9 @@
{{html-safe (theme-i18n "search_banner.subhead")}}
-