name: "Search"
description: "Search box"
body: |
A search box with label and attached submit button. The component must be used within an HTML form.
The search input has a name="q" attribute and a customisable ID and NAME.
It can be used on white or on govuk-blue using the on_govuk_blue option.
Markup such as heading tags can be included in the label using the label_text option. Styling is not included in the component for heading tags in labels, however this is what the search results page does.
accessibility_criteria: |
The search box should:
- be used inside a form with the role of 'search', to indicate it as a [search landmark](https://www.w3.org/TR/wai-aria-practices-1.1/#aria_lh_search)
- have a clear label to identify the search functionality, which is visible to all users
examples:
default:
data: {}
apply_custom_styling_to_the_label_and_set_search_value:
data:
inline_label: false
label_text: "
Search GOV.UK
"
value: "driving licence"
stop_the_label_appearing_inline:
data:
inline_label: false
no_border:
description: Sometimes we don't need the grey border surrounding the input field, such as when the component is used on a black background
data:
no_border: true
context:
black_background: true
for_use_on_govuk_blue_background:
data:
on_govuk_blue: true
context:
dark_background: true
change_label_text:
data:
label_text: "Search"
set_id_for_search_input:
data:
id: "my_unique_id"
large_version:
data:
size: "large"
change_field_name:
description: To be used if you need to change the default name 'q'
data:
name: "my_own_fieldname"
with_aria_controls_attribute:
description: |
The aria-controls attribute is a 'relationship attribute' which denotes which elements in a page an interactive element or set of elements has control over and affects.
For places like the finders where the page is updated dynamically after value changes to the input.
data:
aria_controls: "wrapper"
with_custom_button_text:
description: |
The search box component may be used multiple times on a page -- for example, on a [guidance and regulation finder results page](https://www.gov.uk/search/guidance-and-regulation?keywords=bananas&order=relevance) there is both the sitewide search in the header and also for the specific finder.
To avoid confusion, the text inside the button should be different for each form. This can be done by setting the `button_text` parameter.
This is visually hidden text -- to check for changes use a screen reader or inspect the button element.
data:
button_text: "Search absolutely everywhere"
with_set_label_size:
description: |
Allows the label text size to be set to `xl`, `l`, `m`, or `s`. If this is set, then `inline_label` is automatically set to `false`.
data:
label_size: "xl"