UI Patterns

Modal searchStatusrelease

Show and hide a modal search form.

Guidance

Use this pattern for search forms that should capture focus, take over the whole screen and prevent interaction with the rest of the page until they are closed.

Example

Open in a new tab

Dependencies and installation

PackageInstallation
@stormid/modal
npm i -S @stormid/modal

Code

<button type="button" class="modal-search__btn js-modal-search__btn" aria-label="Show or hide site search" aria-haspopup="dialog"><svg class="modal-search__btn-icon" focusable="false" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="#fff"><path d="M0 0h24v24H0z" fill="none"></path><path d="M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"></path></svg>search</button><div role="region" id="modal-search" aria-labelledby="modal-title" class="js-modal-search modal-container" data-modal-toggle="js-modal-search__btn" hidden><div class="modal" role="dialog" aria-labelledby="modal-title"><h2 id="modal-title" class="modal__title">Search this site</h2><form class="modal__form" action="#" role="search"><label class="modal__label" for="q">Input your search term</label><input class="modal__input" type="search" id="q" name="q"/><button class="modal__search-btn">search</button></form><button type="button" class="modal__close js-modal-search__btn" aria-label="Close search"><svg class="modal__close-icon" focusable="false" aria-hidden="true" height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg"><path d="M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z"></path></svg></button></div></div>
import modal from '@stormid/modal';

modal('.js-modal-search');

Acceptance criteria

The following is a list of example acceptance criteria to test against when using this pattern. These critera should test that the specific markup requirements are met, and that the search behaves visually and functionally as expected.

For validation in developer tools / web inspector

For visual validation

For functional validation

References