From caed16e26fad9500ea36366cd4e3b594aa802687 Mon Sep 17 00:00:00 2001 From: jdlrobson Date: Thu, 16 Sep 2021 11:00:05 -0700 Subject: [PATCH] Allow multiple search components on the same page Styling should not depend on IDs to allow us to have multiple searches in the page. Precursor for wiring up search in the sticky header. This also tweaks performance metrics to track separate metrics for the sticky header search Change-Id: I5b4192a8f5a9f95af26c1faf904f7cc994323518 --- bundlesize.config.json | 2 +- includes/SkinVector.php | 23 +++-- includes/templates/SearchBox.mustache | 20 ++-- resources/common/components/SearchBox.less | 18 +++- resources/skins.vector.js/searchLoader.js | 77 ++++++++++----- resources/skins.vector.js/searchToggle.js | 4 +- resources/skins.vector.js/stickyHeader.js | 5 +- .../skins.vector.search.js | 96 +++++++++---------- .../components/SearchBox.less | 2 +- .../layouts/screen.less | 8 +- .../components/Header.less | 4 +- .../components/SearchBoxLoader.less | 2 +- .../components/VueEnhancedSearchBox.less | 33 +++++-- skin.json | 4 +- stories/SearchBox.stories.data.js | 19 +++- stories/SearchBox.stories.js | 2 +- stories/types.js | 7 ++ 17 files changed, 206 insertions(+), 120 deletions(-) diff --git a/bundlesize.config.json b/bundlesize.config.json index 5cccda9..edac214 100644 --- a/bundlesize.config.json +++ b/bundlesize.config.json @@ -5,7 +5,7 @@ }, { "resourceModule": "skins.vector.styles", - "maxSize": "9.8 kB" + "maxSize": "10.1 kB" }, { "resourceModule": "skins.vector.legacy.js", diff --git a/includes/SkinVector.php b/includes/SkinVector.php index 0bc56d6..739d184 100644 --- a/includes/SkinVector.php +++ b/includes/SkinVector.php @@ -411,7 +411,9 @@ class SkinVector extends SkinMustache { $commonSkinData['data-search-box'] = $this->getSearchData( $commonSkinData['data-search-box'], - !$this->isLegacy() + !$this->isLegacy(), + true, + 'searchform' ); return $commonSkinData; @@ -422,22 +424,31 @@ class SkinVector extends SkinMustache { * * @param array $searchBoxData * @param bool $isCollapsible + * @param bool $isPrimary + * @param string $formId * @return array modified version of $searchBoxData */ - private function getSearchData( array $searchBoxData, bool $isCollapsible ) { - $searchClass = 'vector-search-box'; + private function getSearchData( array $searchBoxData, bool $isCollapsible, bool $isPrimary, string $formId ) { + $searchClass = ''; + + // Determine the search widget treatment to send to the user + if ( VectorServices::getFeatureManager()->isFeatureEnabled( Constants::FEATURE_USE_WVUI_SEARCH ) ) { + $searchClass .= 'vector-search-box-vue '; + } if ( $isCollapsible ) { - $searchClass .= ' vector-search-box-collapses'; + $searchClass .= ' vector-search-box-collapses '; } if ( $this->shouldSearchExpand() ) { - $searchClass .= " " . self::SEARCH_EXPANDING_CLASS; + $searchClass .= ' ' . self::SEARCH_EXPANDING_CLASS; } // Annotate search box with a component class. - $searchBoxData['class'] = $searchClass; + $searchBoxData['class'] = trim( $searchClass ); $searchBoxData['is-collapsible'] = $isCollapsible; + $searchBoxData['is-primary'] = $isPrimary; + $searchBoxData['form-id'] = $formId; // At lower resolutions the search input is hidden search and only the submit button is shown. // It should behave like a form submit link (e.g. submit the form with no input value). diff --git a/includes/templates/SearchBox.mustache b/includes/templates/SearchBox.mustache index 52c36ed..9231856 100644 --- a/includes/templates/SearchBox.mustache +++ b/includes/templates/SearchBox.mustache @@ -1,16 +1,20 @@ {{! See @typedef SearchData }} -