Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions content/examples/shortcodes/search/en.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ With this shortcode you can embed a search results widget on the page.
## Example

```
{{</* search contentType="How-to Guides" showContentTypes=false tags="encodings,commented cue" */>}}
{{</* search contentType="Tutorials" showContentTypes=false tags="encodings,cue command" searchTerm="\"json schema\"" */>}}
```

{{< search contentType="How-to Guides" showContentTypes=false tags="encodings,commented cue" >}}
{{< search contentType="Tutorials" showContentTypes=false tags="encodings,cue command" searchTerm="\"json schema\"" >}}


## Attributes
Expand All @@ -24,3 +24,6 @@ showContentTypes

tags
: optional - Adds preselected tags

searchTerm
: optional - Prefills the search bar
6 changes: 6 additions & 0 deletions hugo/assets/ts/widgets/search-filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,12 @@ export class SearchFilter extends BaseWidget {
urlParamsChanged = true;
}

const initialSearchTerm = this.element.dataset.initialSearchTerm;
if (!query && this.parsedQuery.cleanQuery === '' && initialSearchTerm) {
this.parsedQuery.cleanQuery = initialSearchTerm;
urlParamsChanged = true;
}

// Update parsed query & save selected items
this.parsedQuery.facets[this.filterName] = selectedItems;
this.selectedItems = selectedItems;
Expand Down
7 changes: 5 additions & 2 deletions hugo/content/en/examples/shortcodes/search/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ With this shortcode you can embed a search results widget on the page.
## Example

```
{{</* search contentType="How-to Guides" showContentTypes=false tags="encodings,commented cue" */>}}
{{</* search contentType="Tutorials" showContentTypes=false tags="encodings,cue command" searchTerm="\"json schema\"" */>}}
```

{{< search contentType="How-to Guides" showContentTypes=false tags="encodings,commented cue" >}}
{{< search contentType="Tutorials" showContentTypes=false tags="encodings,cue command" searchTerm="\"json schema\"" >}}


## Attributes
Expand All @@ -24,3 +24,6 @@ showContentTypes

tags
: optional - Adds preselected tags

searchTerm
: optional - Prefills the search bar
2 changes: 2 additions & 0 deletions hugo/layouts/partials/filter.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@
{{ $inputLabel := printf "search_%s_input" $translationKey }}
{{ $noResults := printf "search_%s_no-results" $translationKey }}
{{ $preselectedItems := .preselectedItems }}
{{ $searchTerm := .searchTerm }}

<details class="filter{{ if $cssClass }} {{ $cssClass }}{{ end }} is-loading"
data-dropdown data-filter="{{ $name }}"
data-filter-items="{{ $filters | jsonify }}"
{{ if $preselectedItems }} data-preselected-items="{{ $preselectedItems }}"{{ end }}
{{ if $searchTerm }} data-initial-search-term="{{ $searchTerm }}"{{ end }}
{{ if $open }} open{{ end }}
>
<summary class="filter__title button button--small button--white">
Expand Down
2 changes: 2 additions & 0 deletions hugo/layouts/partials/search.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
{{ $contentTypes := slice }}
{{ $contentType := .contentType | default "" }}
{{ $preselectedTags := .preselectedTags | default "" }}
{{ $searchTerm := .searchTerm | default "" }}
{{ $type := .type | default "full" }}
{{ $placeholder := (T "search_placeholder" ) }}

Expand Down Expand Up @@ -48,6 +49,7 @@
"name" "tags"
"filters" .Site.Params.tags
"preselectedItems" $preselectedTags
"searchTerm" $searchTerm
) -}}

{{ if $showContentTypes }}
Expand Down
2 changes: 2 additions & 0 deletions hugo/layouts/shortcodes/search.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
{{- $contentType := .Get "contentType" | default "" -}}
{{- $showContentTypes := .Get "showContentTypes" | default true -}}
{{- $preselectedTags := .Get "tags" | default "" -}}
{{- $searchTerm := .Get "searchTerm" | default "" -}}

{{- partial "search" (dict
"type" "widget"
"contentType" $contentType
"showContentTypes" $showContentTypes
"preselectedTags" $preselectedTags
"searchTerm" $searchTerm
"context" .
) -}}
Loading