beta This component version is ready to be used but is still in active development.

Search github location npm version

The vf-search component is a form component that can be used for for the front-end to search your site.


Variants


Usage

Responsive Search

This is the default search component that can be used to search your site. When the viewport size is below 600px the vf-button replaces the text with an icon so that it can allow the input to use more space.

Mini Search

This is very much a work-in-progress prototype and not to be used.

Search Container

To be used when searching pages, this container should sit below the vf-hero (and related vf-navigation where applicable). The code example shows that the vf-form is wrapped in a vf-container (this sectioning component has not been created, yet, but the base CSS is available as part of vf-search).

Results

This shows how auto-suggest or autocomplete results should be displayed. There is no native HTML functionality for this and you will need to provide the JavaScript that is relevant to your project for it to work.

note: Version 2.0.0 of the vf-search has no maximum width and will fill the space of it's parent. Because of this it is recommended to make sure the component is not too wide by wrapping it in the embl-grid with the --centered-content variant. If you wish to use ths vf-search with vf-grid you will need to make use the vf-search component also has an appropraite .vf-u-grid__col--span class.

You can enable autofocus on the search element, but should only do so if most users intend to search on the page.

Nunjucks syntax

Depending on your environment you'll want to use render or include. As a rule of thumb: server-side use include, precompiled browser use render. If you're using vf-eleventy you should use include.

Using include

You'll need to pass a context object from your code or Yaml file (example), as well as the path to the Nunjucks template. Nunjucks' include is an abstraction of render and provides some additional portability.


{% set context fromYourYamlFile %}
- or -
{% set context = {
  "component-type": "block",
  "responsive": true,
  "search_action": "#",
  "search_autofocus": false,
  "search_button": "Search",
  "search_label": "Search",
  "search_placeholder": "Enter your search terms",
  "search_id": "searchitem",
  "search_value_default": ""
}
 %}
{% include "../path_to/vf-search/vf-search.njk" %}
                

Using render

This approach is best for bare-bones Nunjucks environments, such as precompiled templates with the Nunjucks slim runtime where include is not be available.

{% render '@vf-search', {
  "component-type": "block",
  "responsive": true,
  "search_action": "#",
  "search_autofocus": false,
  "search_button": "Search",
  "search_label": "Search",
  "search_placeholder": "Enter your search terms",
  "search_id": "searchitem",
  "search_value_default": ""
} %}
                
HTML
<form action="#" class="vf-form vf-form--search vf-form--search--responsive | vf-sidebar vf-sidebar--end">
  <div class="vf-sidebar__inner">

    <div class="vf-form__item">

      <label class="vf-form__label vf-u-sr-only | vf-search__label" for="searchitem">Search</label>
      <input type="search" placeholder="Enter your search terms" id="searchitem" class="vf-form__input">
    </div>

    <button type="submit" class="vf-search__button | vf-button vf-button--primary">
      <span class="vf-button__text">Search</span>

      <svg class="vf-icon vf-icon--search-btn | vf-button__icon" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" version="1.1" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svgjs="http://svgjs.com/svgjs" viewBox="0 0 140 140" width="140" height="140">
        <g transform="matrix(5.833333333333333,0,0,5.833333333333333,0,0)">
          <path d="M23.414,20.591l-4.645-4.645a10.256,10.256,0,1,0-2.828,2.829l4.645,4.644a2.025,2.025,0,0,0,2.828,0A2,2,0,0,0,23.414,20.591ZM10.25,3.005A7.25,7.25,0,1,1,3,10.255,7.258,7.258,0,0,1,10.25,3.005Z" fill="#FFFFFF" stroke="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="0"></path>
        </g>
      </svg>

    </button>
  </div>

</form>
              
Nunjucks syntax

Depending on your environment you'll want to use render or include. As a rule of thumb: server-side use include, precompiled browser use render. If you're using vf-eleventy you should use include.

Using include

You'll need to pass a context object from your code or Yaml file (example), as well as the path to the Nunjucks template. Nunjucks' include is an abstraction of render and provides some additional portability.


{% set context fromYourYamlFile %}
- or -
{% set context = {
  "component-type": "block",
  "results": true,
  "responsive": true,
  "search_action": "#",
  "search_autofocus": false,
  "search_button": "Search",
  "search_label": "Search",
  "search_placeholder": "Enter your search terms",
  "search_id": "searchitem",
  "search_value_default": ""
}
 %}
{% include "../path_to/vf-search/vf-search.njk" %}
                

Using render

This approach is best for bare-bones Nunjucks environments, such as precompiled templates with the Nunjucks slim runtime where include is not be available.

{% render '@vf-search', {
  "component-type": "block",
  "results": true,
  "responsive": true,
  "search_action": "#",
  "search_autofocus": false,
  "search_button": "Search",
  "search_label": "Search",
  "search_placeholder": "Enter your search terms",
  "search_id": "searchitem",
  "search_value_default": ""
} %}
                
HTML
<form action="#" class="vf-form vf-form--search vf-form--search--responsive | vf-sidebar vf-sidebar--end">
  <div class="vf-sidebar__inner">

    <div class="vf-form__item">

      <label class="vf-form__label vf-u-sr-only | vf-search__label" for="searchitem">Search</label>
      <input type="search" placeholder="Enter your search terms" id="searchitem" class="vf-form__input" aria-owns="vf-form--search__results-list">
      <ul id="vf-form--search__results-list" class="vf-list | vf-form--search__results-list | vf-stack vf-stack--custom" aria-labelledby="searchitem">
        <li id="vf-form--search__results-list--01" class="vf-list__item" role="option">
          abcdef ghijklm nopqr styuv
        </li>
        <li id="vf-form--search__results-list--02" class="vf-list__item" role="option">
          abcdef ghijklm nopqr styuv
        </li>
        <li id="vf-form--search__results-list--03" class="vf-list__item" role="option">
          abcdef ghijklm nopqr styuv
        </li>
        <li id="vf-form--search__results-list--04" class="vf-list__item" role="option">
          abcdef ghijklm nopqr styuv
        </li>
        <li id="vf-form--search__results-list--05" class="vf-list__item" role="option">
          abcdef ghijklm nopqr styuv
        </li>
      </ul>
    </div>

    <button type="submit" class="vf-search__button | vf-button vf-button--primary">
      <span class="vf-button__text">Search</span>

      <svg class="vf-icon vf-icon--search-btn | vf-button__icon" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" version="1.1" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svgjs="http://svgjs.com/svgjs" viewBox="0 0 140 140" width="140" height="140">
        <g transform="matrix(5.833333333333333,0,0,5.833333333333333,0,0)">
          <path d="M23.414,20.591l-4.645-4.645a10.256,10.256,0,1,0-2.828,2.829l4.645,4.644a2.025,2.025,0,0,0,2.828,0A2,2,0,0,0,23.414,20.591ZM10.25,3.005A7.25,7.25,0,1,1,3,10.255,7.258,7.258,0,0,1,10.25,3.005Z" fill="#FFFFFF" stroke="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="0"></path>
        </g>
      </svg>

    </button>
  </div>

</form>
              
Nunjucks syntax

Depending on your environment you'll want to use render or include. As a rule of thumb: server-side use include, precompiled browser use render. If you're using vf-eleventy you should use include.

Using include

You'll need to pass a context object from your code or Yaml file (example), as well as the path to the Nunjucks template. Nunjucks' include is an abstraction of render and provides some additional portability.


{% set context fromYourYamlFile %}
- or -
{% set context = {
  "component-type": "block",
  "mini": true,
  "search_action": "#",
  "search_autofocus": false,
  "search_button": "Search",
  "search_label": "Search",
  "search_placeholder": "Enter your search terms",
  "search_id": "searchitem",
  "search_value_default": ""
}
 %}
{% include "../path_to/vf-search/vf-search.njk" %}
                

Using render

This approach is best for bare-bones Nunjucks environments, such as precompiled templates with the Nunjucks slim runtime where include is not be available.

{% render '@vf-search', {
  "component-type": "block",
  "mini": true,
  "search_action": "#",
  "search_autofocus": false,
  "search_button": "Search",
  "search_label": "Search",
  "search_placeholder": "Enter your search terms",
  "search_id": "searchitem",
  "search_value_default": ""
} %}
                
HTML
<form action="#" class="vf-form vf-form--search vf-form--search--mini | vf-sidebar vf-sidebar--end">
  <div class="vf-sidebar__inner">

    <div class="vf-form__item">

      <label class="vf-form__label vf-u-sr-only | vf-search__label" for="searchitem">Search</label>
      <input type="search" placeholder="Enter your search terms" id="searchitem" class="vf-form__input">
    </div>

    <button type="submit" class="vf-search__button | vf-button vf-button--primary">
      <span class="vf-button__text | vf-u-sr-only">Search</span>

      <svg class="vf-icon vf-icon--search-btn | vf-button__icon" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" version="1.1" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svgjs="http://svgjs.com/svgjs" viewBox="0 0 140 140" width="140" height="140">
        <g transform="matrix(5.833333333333333,0,0,5.833333333333333,0,0)">
          <path d="M23.414,20.591l-4.645-4.645a10.256,10.256,0,1,0-2.828,2.829l4.645,4.644a2.025,2.025,0,0,0,2.828,0A2,2,0,0,0,23.414,20.591ZM10.25,3.005A7.25,7.25,0,1,1,3,10.255,7.258,7.258,0,0,1,10.25,3.005Z" fill="#FFFFFF" stroke="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="0"></path>
        </g>
      </svg>

    </button>
  </div>

</form>
              
Nunjucks syntax

Depending on your environment you'll want to use render or include. As a rule of thumb: server-side use include, precompiled browser use render. If you're using vf-eleventy you should use include.

Using include

You'll need to pass a context object from your code or Yaml file (example), as well as the path to the Nunjucks template. Nunjucks' include is an abstraction of render and provides some additional portability.


{% set context fromYourYamlFile %}
- or -
{% set context = {
  "component-type": "block",
  "mini": true,
  "results": true,
  "search_action": "#",
  "search_autofocus": false,
  "search_button": "Search",
  "search_label": "Search",
  "search_placeholder": "Enter your search terms",
  "search_id": "searchitem",
  "search_value_default": ""
}
 %}
{% include "../path_to/vf-search/vf-search.njk" %}
                

Using render

This approach is best for bare-bones Nunjucks environments, such as precompiled templates with the Nunjucks slim runtime where include is not be available.

{% render '@vf-search', {
  "component-type": "block",
  "mini": true,
  "results": true,
  "search_action": "#",
  "search_autofocus": false,
  "search_button": "Search",
  "search_label": "Search",
  "search_placeholder": "Enter your search terms",
  "search_id": "searchitem",
  "search_value_default": ""
} %}
                
HTML
<form action="#" class="vf-form vf-form--search vf-form--search--mini | vf-sidebar vf-sidebar--end">
  <div class="vf-sidebar__inner">

    <div class="vf-form__item">

      <label class="vf-form__label vf-u-sr-only | vf-search__label" for="searchitem">Search</label>
      <input type="search" placeholder="Enter your search terms" id="searchitem" class="vf-form__input" aria-owns="vf-form--search__results-list">
      <ul id="vf-form--search__results-list" class="vf-list | vf-form--search__results-list | vf-stack vf-stack--custom" aria-labelledby="searchitem">
        <li id="vf-form--search__results-list--01" class="vf-list__item" role="option">
          abcdef ghijklm nopqr styuv
        </li>
        <li id="vf-form--search__results-list--02" class="vf-list__item" role="option">
          abcdef ghijklm nopqr styuv
        </li>
        <li id="vf-form--search__results-list--03" class="vf-list__item" role="option">
          abcdef ghijklm nopqr styuv
        </li>
        <li id="vf-form--search__results-list--04" class="vf-list__item" role="option">
          abcdef ghijklm nopqr styuv
        </li>
        <li id="vf-form--search__results-list--05" class="vf-list__item" role="option">
          abcdef ghijklm nopqr styuv
        </li>
      </ul>
    </div>

    <button type="submit" class="vf-search__button | vf-button vf-button--primary">
      <span class="vf-button__text | vf-u-sr-only">Search</span>

      <svg class="vf-icon vf-icon--search-btn | vf-button__icon" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" version="1.1" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svgjs="http://svgjs.com/svgjs" viewBox="0 0 140 140" width="140" height="140">
        <g transform="matrix(5.833333333333333,0,0,5.833333333333333,0,0)">
          <path d="M23.414,20.591l-4.645-4.645a10.256,10.256,0,1,0-2.828,2.829l4.645,4.644a2.025,2.025,0,0,0,2.828,0A2,2,0,0,0,23.414,20.591ZM10.25,3.005A7.25,7.25,0,1,1,3,10.255,7.258,7.258,0,0,1,10.25,3.005Z" fill="#FFFFFF" stroke="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="0"></path>
        </g>
      </svg>

    </button>
  </div>

</form>
              
Nunjucks syntax

Depending on your environment you'll want to use render or include. As a rule of thumb: server-side use include, precompiled browser use render. If you're using vf-eleventy you should use include.

Using include

You'll need to pass a context object from your code or Yaml file (example), as well as the path to the Nunjucks template. Nunjucks' include is an abstraction of render and provides some additional portability.


{% set context fromYourYamlFile %}
- or -
{% set context = {
  "component-type": "block",
  "responsive": true,
  "search__background": "var(--vf-color--neutral--100)",
  "search_action": "#",
  "search_autofocus": false,
  "search_button": "Search",
  "search_label": "Search",
  "search_placeholder": "Enter your search terms",
  "search_id": "searchitem",
  "search_value_default": ""
}
 %}
{% include "../path_to/vf-search/vf-search.njk" %}
                

Using render

This approach is best for bare-bones Nunjucks environments, such as precompiled templates with the Nunjucks slim runtime where include is not be available.

{% render '@vf-search', {
  "component-type": "block",
  "responsive": true,
  "search__background": "var(--vf-color--neutral--100)",
  "search_action": "#",
  "search_autofocus": false,
  "search_button": "Search",
  "search_label": "Search",
  "search_placeholder": "Enter your search terms",
  "search_id": "searchitem",
  "search_value_default": ""
} %}
                
HTML
<div class="vf-container vf-container--search | vf-u-fullbleed" style="--vf-container--search__background-color: var(--vf-color--neutral--100);">

  <form action="#" class="vf-form vf-form--search vf-form--search--responsive | vf-sidebar vf-sidebar--end">
    <div class="vf-sidebar__inner">

      <div class="vf-form__item">

        <label class="vf-form__label vf-u-sr-only | vf-search__label" for="searchitem">Search</label>
        <input type="search" placeholder="Enter your search terms" id="searchitem" class="vf-form__input">
      </div>

      <button type="submit" class="vf-search__button | vf-button vf-button--primary">
        <span class="vf-button__text">Search</span>

        <svg class="vf-icon vf-icon--search-btn | vf-button__icon" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" version="1.1" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svgjs="http://svgjs.com/svgjs" viewBox="0 0 140 140" width="140" height="140">
          <g transform="matrix(5.833333333333333,0,0,5.833333333333333,0,0)">
            <path d="M23.414,20.591l-4.645-4.645a10.256,10.256,0,1,0-2.828,2.829l4.645,4.644a2.025,2.025,0,0,0,2.828,0A2,2,0,0,0,23.414,20.591ZM10.25,3.005A7.25,7.25,0,1,1,3,10.255,7.258,7.258,0,0,1,10.25,3.005Z" fill="#FFFFFF" stroke="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="0"></path>
          </g>
        </svg>

      </button>
    </div>

  </form>
</div>
              
Nunjucks syntax

Depending on your environment you'll want to use render or include. As a rule of thumb: server-side use include, precompiled browser use render. If you're using vf-eleventy you should use include.

Using include

You'll need to pass a context object from your code or Yaml file (example), as well as the path to the Nunjucks template. Nunjucks' include is an abstraction of render and provides some additional portability.


{% set context fromYourYamlFile %}
- or -
{% set context = {
  "component-type": "block",
  "responsive": true,
  "results": true,
  "search__background": "var(--vf-color--neutral--100)",
  "search_action": "#",
  "search_autofocus": false,
  "search_button": "Search",
  "search_label": "Search",
  "search_placeholder": "Enter your search terms",
  "search_id": "searchitem",
  "search_value_default": ""
}
 %}
{% include "../path_to/vf-search/vf-search.njk" %}
                

Using render

This approach is best for bare-bones Nunjucks environments, such as precompiled templates with the Nunjucks slim runtime where include is not be available.

{% render '@vf-search', {
  "component-type": "block",
  "responsive": true,
  "results": true,
  "search__background": "var(--vf-color--neutral--100)",
  "search_action": "#",
  "search_autofocus": false,
  "search_button": "Search",
  "search_label": "Search",
  "search_placeholder": "Enter your search terms",
  "search_id": "searchitem",
  "search_value_default": ""
} %}
                
HTML
<div class="vf-container vf-container--search | vf-u-fullbleed" style="--vf-container--search__background-color: var(--vf-color--neutral--100);">

  <form action="#" class="vf-form vf-form--search vf-form--search--responsive | vf-sidebar vf-sidebar--end">
    <div class="vf-sidebar__inner">

      <div class="vf-form__item">

        <label class="vf-form__label vf-u-sr-only | vf-search__label" for="searchitem">Search</label>
        <input type="search" placeholder="Enter your search terms" id="searchitem" class="vf-form__input" aria-owns="vf-form--search__results-list">
        <ul id="vf-form--search__results-list" class="vf-list | vf-form--search__results-list | vf-stack vf-stack--custom" aria-labelledby="searchitem">
          <li id="vf-form--search__results-list--01" class="vf-list__item" role="option">
            abcdef ghijklm nopqr styuv
          </li>
          <li id="vf-form--search__results-list--02" class="vf-list__item" role="option">
            abcdef ghijklm nopqr styuv
          </li>
          <li id="vf-form--search__results-list--03" class="vf-list__item" role="option">
            abcdef ghijklm nopqr styuv
          </li>
          <li id="vf-form--search__results-list--04" class="vf-list__item" role="option">
            abcdef ghijklm nopqr styuv
          </li>
          <li id="vf-form--search__results-list--05" class="vf-list__item" role="option">
            abcdef ghijklm nopqr styuv
          </li>
        </ul>
      </div>

      <button type="submit" class="vf-search__button | vf-button vf-button--primary">
        <span class="vf-button__text">Search</span>

        <svg class="vf-icon vf-icon--search-btn | vf-button__icon" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" version="1.1" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svgjs="http://svgjs.com/svgjs" viewBox="0 0 140 140" width="140" height="140">
          <g transform="matrix(5.833333333333333,0,0,5.833333333333333,0,0)">
            <path d="M23.414,20.591l-4.645-4.645a10.256,10.256,0,1,0-2.828,2.829l4.645,4.644a2.025,2.025,0,0,0,2.828,0A2,2,0,0,0,23.414,20.591ZM10.25,3.005A7.25,7.25,0,1,1,3,10.255,7.258,7.258,0,0,1,10.25,3.005Z" fill="#FFFFFF" stroke="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="0"></path>
          </g>
        </svg>

      </button>
    </div>

  </form>
</div>
              
Installation info

This repository is distributed with npm. After installing npm and yarn, you can install with this command.

$ yarn add --dev @visual-framework/vf-search

Sass/CSS

The style files included are written in Sass. If you're using a VF-core project, you can import it like this:

@import "@visual-framework/vf-search/index.scss";

Make sure you import Sass requirements along with the modules. You can use a project boilerplate or the vf-sass-starter

Changelog

Changelog

1.1.2

  • Implements updated vf-search markup.
  • Changes a few pages on how it works with nunjucks and markdown.

1.1.0

  • updates Design Tokens homepage.
  • adds neutral colour tokens
  • adds 'status banners' for components in the documentation page.
  • Adds the form options as their own set of components in the list.
  • https://github.com/visual-framework/vf-core/pull/1390/files
  • Updates to use 11ty 0.12.1
  • https://github.com/visual-framework/vf-core/pull/1435

1.0.24

  • changes the vf-intro so it's a white background, removes the padding.
  • changes the links in vf-intro to be the 'correct' buttons.

1.0.23

  • small change to cards on homepage

1.0.18

  • dependency bump

1.0.17

  • dependency bump

1.0.16

  • dependency bump

1.0.13

  • dependency bump
  • adds roamap and consultation docs

1.0.12

  • design token documenation now lives in the component libary

1.0.7

  • adds updates blog

1.0.6

  • begin to make more pattern/boilerplate guidance
  • minor templating updates

1.0.5

  • dependency bump

1.0.4

  • uses vf-favicon
  • adds meta attributes

1.0.3

  • run vf-component-assets:everything on local dev
  • remove reference to removed /css/app.css

1.0.2

  • Add 404
  • Fix component CSS generation

1.0.1

  • Also generate per-component CSS with vf-css:generate-component-css

1.0.0

  • Initial release to be used with vf-core 2.2.0

Assets



File system location: components/vf-search

Find an issue on this page? Propose a change or discuss it.