File tree Expand file tree Collapse file tree 6 files changed +22
-4
lines changed
content/examples/shortcodes/search
content/en/examples/shortcodes/search Expand file tree Collapse file tree 6 files changed +22
-4
lines changed Original file line number Diff line number Diff line change @@ -8,10 +8,10 @@ With this shortcode you can embed a search results widget on the page.
88## Example
99
1010```
11- {{</* search contentType="How-to Guides" showContentTypes=false tags="encodings,commented cue" */>}}
11+ {{</* search contentType="How-to Guides" showContentTypes=false tags="encodings,commented cue" searchTerm="json" */>}}
1212```
1313
14- {{< search contentType="How-to Guides" showContentTypes=false tags="encodings,commented cue" >}}
14+ {{< search contentType="How-to Guides" showContentTypes=false tags="encodings,commented cue" searchTerm="json" >}}
1515
1616
1717## Attributes
@@ -24,3 +24,6 @@ showContentTypes
2424
2525tags
2626: optional - Adds preselected tags
27+
28+ searchTerm
29+ : optional - Prefills the search bar
Original file line number Diff line number Diff line change @@ -168,6 +168,12 @@ export class SearchFilter extends BaseWidget {
168168 urlParamsChanged = true ;
169169 }
170170
171+ const initialSearchTerm = this . element . dataset . initialSearchTerm ;
172+ if ( ! query && this . parsedQuery . cleanQuery === '' && initialSearchTerm ) {
173+ this . parsedQuery . cleanQuery = initialSearchTerm ;
174+ urlParamsChanged = true ;
175+ }
176+
171177 // Update parsed query & save selected items
172178 this . parsedQuery . facets [ this . filterName ] = selectedItems ;
173179 this . selectedItems = selectedItems ;
Original file line number Diff line number Diff line change @@ -8,10 +8,10 @@ With this shortcode you can embed a search results widget on the page.
88## Example
99
1010```
11- {{</* search contentType="How-to Guides" showContentTypes=false tags="encodings,commented cue" */>}}
11+ {{</* search contentType="How-to Guides" showContentTypes=false tags="encodings,commented cue" searchTerm="json" */>}}
1212```
1313
14- {{< search contentType="How-to Guides" showContentTypes=false tags="encodings,commented cue" >}}
14+ {{< search contentType="How-to Guides" showContentTypes=false tags="encodings,commented cue" searchTerm="json" >}}
1515
1616
1717## Attributes
@@ -24,3 +24,6 @@ showContentTypes
2424
2525tags
2626: optional - Adds preselected tags
27+
28+ searchTerm
29+ : optional - Prefills the search bar
Original file line number Diff line number Diff line change 88{{ $inputLabel := printf "search_%s_input" $translationKey }}
99{{ $noResults := printf "search_%s_no-results" $translationKey }}
1010{{ $preselectedItems := .preselectedItems }}
11+ {{ $searchTerm := .searchTerm }}
1112
1213< details class ="filter{{ if $cssClass }} {{ $cssClass }}{{ end }} is-loading "
1314 data-dropdown data-filter ="{{ $name }} "
1415 data-filter-items ="{{ $filters | jsonify }} "
1516 {{ if $preselectedItems }} data-preselected-items ="{{ $preselectedItems }} "{{ end }}
17+ {{ if $searchTerm }} data-initial-search-term ="{{ $searchTerm }} "{{ end }}
1618 {{ if $open }} open{{ end }}
1719>
1820 < summary class ="filter__title button button--small button--white ">
Original file line number Diff line number Diff line change 33{{ $contentTypes := slice }}
44{{ $contentType := .contentType | default "" }}
55{{ $preselectedTags := .preselectedTags | default "" }}
6+ {{ $searchTerm := .searchTerm | default "" }}
67{{ $type := .type | default "full" }}
78{{ $placeholder := (T "search_placeholder" ) }}
89
4849 "name" "tags"
4950 "filters" .Site.Params.tags
5051 "preselectedItems" $preselectedTags
52+ "searchTerm" $searchTerm
5153 ) -}}
5254
5355 {{ if $showContentTypes }}
Original file line number Diff line number Diff line change 11{{- $contentType := .Get "contentType" | default "" -}}
22{{- $showContentTypes := .Get "showContentTypes" | default true -}}
33{{- $preselectedTags := .Get "tags" | default "" -}}
4+ {{- $searchTerm := .Get "searchTerm" | default "" -}}
45
56{{- partial "search" (dict
67 "type" "widget"
78 "contentType" $contentType
89 "showContentTypes" $showContentTypes
910 "preselectedTags" $preselectedTags
11+ "searchTerm" $searchTerm
1012 "context" .
1113) -}}
You can’t perform that action at this time.
0 commit comments