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

Search block

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

github location npm version

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.

Variants

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 = { 
"exampleMultiColumns" : "false",
"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', {
  "exampleMultiColumns" : "false",
  "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 = { 
"exampleMultiColumns" : "false",
"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', {
  "exampleMultiColumns" : "false",
  "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 = { 
"exampleMultiColumns" : "false",
"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', {
  "exampleMultiColumns" : "false",
  "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 = { 
"exampleMultiColumns" : "false",
"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', {
  "exampleMultiColumns" : "false",
  "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 = { 
"exampleMultiColumns" : "false",
"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', {
  "exampleMultiColumns" : "false",
  "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 = { 
"exampleMultiColumns" : "false",
"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', {
  "exampleMultiColumns" : "false",
  "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>
              

Examples

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

3.0.0-alpha.1

  • Refine spacing when more than 1 inline vf-form__item.

3.0.0-alpha.0

  • updates to code and documentation based on consultation and decisions made.
  • introduces the 'container' version
  • notes that the 'mini' version should not be implemented.

2.0.0

  • adds a div around the form content.
  • makes changes to the CSS for --inline variant so it's responsive to the parent width.

1.2.0

  • don't allow inline search to get too large
  • add field for search description

1.1.2

  • adds support for autofocus on search input

1.1.1

  • adds support for default search value

1.1.0

  • makes vf-search.njk a real template

1.0.0

  • removes vf-u-sr-only as no longer needed
  • changes alignment of button on inline search

1.0.0-alpha.8

  • Version bump only for package @visual-framework/vf-search

1.0.0-alpha.7

  • Version bump only for package @visual-framework/vf-search

Assets



File system location: components/vf-search

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