Skip to content

CSS

A search field is a role="search" container wrapping a native <input type="search">, a decorative leading icon, and any trailing controls. The states are keyed off the DOM — :hover, focus, whether the input holds a value, and whether it’s disabled — so no state classes to toggle and no JavaScript needed for the styling.

Give the input a placeholder and an accessible name.

<form class="tng-search-field" role="search">
<i
class="tng-icon icon-search tng-search-field-icon"
aria-hidden="true"
></i>
<input
class="tng-search-field-input"
type="search"
placeholder="Search for a model"
aria-label="Search for a model"
/>
<button
class="tng-search-field-button"
type="submit"
aria-label="Search"
>
<i class="tng-icon icon-search" aria-hidden="true"></i>
</button>
</form>

The input needs a placeholder — it isn’t only copy. The filled styling is selected with :placeholder-shown, so without one the field renders in its filled state while empty. Pair the input with a visible <label>, or give it an aria-label as above.

.tng-search-field-icon is decorative. Mark it aria-hidden="true" — the input’s own label carries the accessible name. Being the first child is what makes it take the leading foreground colour, so any icon works here.

.tng-search-field-button is any interactive control after the input — clear, submit, or the collapsed trigger. Each is a bare 20 px icon that picks up a 44 px touch target from the shared touch-target utility, so it clears the WCAG minimum without changing the layout.

The query stays on one line. Text past the edge ends in an ellipsis while the input isn’t focused, and the trailing controls stay put.

The search icon goes on either side. To show a second icon on Lexus, put a decorative icon first and the search button last. The first child takes the leading colour, whichever icon it holds.

<form class="tng-search-field is-contained" role="search">
<i
class="tng-icon icon-ai-sparkle tng-search-field-icon"
aria-hidden="true"
></i>
<input
class="tng-search-field-input"
type="search"
placeholder="Search"
aria-label="Search"
/>
<button
class="tng-search-field-button"
type="submit"
aria-label="Search"
>
<i class="tng-icon icon-search" aria-hidden="true"></i>
</button>
</form>

is-contained draws a full bordered box with its own fill; the default (is-divided, which you can also write explicitly) draws only a rule under the content. On Lexus, contained rounds to a pill and its copper border is a gradient.

<form class="tng-search-field is-divided" role="search">
<i
class="tng-icon icon-search tng-search-field-icon"
aria-hidden="true"
></i>
<input
class="tng-search-field-input"
type="search"
placeholder="Divided"
aria-label="Divided"
/>
</form>
<form class="tng-search-field is-contained" role="search">
<i
class="tng-icon icon-search tng-search-field-icon"
aria-hidden="true"
></i>
<input
class="tng-search-field-input"
type="search"
placeholder="Contained"
aria-label="Contained"
/>
</form>

Add the clear button once the user starts typing. hidden hides it until then.

<form class="tng-search-field is-contained" role="search">
<i
class="tng-icon icon-search tng-search-field-icon"
aria-hidden="true"
></i>
<input
class="tng-search-field-input"
type="search"
placeholder="Search for a model"
aria-label="Search for a model"
value="Privacy glass"
/>
<button
class="tng-search-field-button"
type="button"
aria-label="Clear search"
>
<i class="tng-icon icon-close" aria-hidden="true"></i>
</button>
<button
class="tng-search-field-button"
type="submit"
aria-label="Search"
>
<i class="tng-icon icon-search" aria-hidden="true"></i>
</button>
</form>

is-collapsed reduces the field to an icon-only square and hides everything after the first child, so the same markup collapses and expands by toggling one class, and the field slides between the two. It opens to the full width of its container; set --tng-search-field-max-inline-size to stop it earlier. The trigger owns aria-expanded. See the Recipe below for the focus management this needs.

<div class="tng-search-field is-contained is-collapsed">
<button
class="tng-search-field-button"
type="button"
aria-expanded="false"
aria-label="Open search"
>
<i class="tng-icon icon-search" aria-hidden="true"></i>
</button>
<input
class="tng-search-field-input"
type="search"
placeholder="Search for a model"
aria-label="Search for a model"
/>
</div>

Two sizes set the height, horizontal padding and type: is-sm (default, 44 px, body 7) and is-lg (56 px, body 6, or body 5 on Lexus).

<form class="tng-search-field is-contained is-sm" role="search">
<i
class="tng-icon icon-search tng-search-field-icon"
aria-hidden="true"
></i>
<input
class="tng-search-field-input"
type="search"
placeholder="Small"
aria-label="Small"
/>
</form>
<form class="tng-search-field is-contained is-lg" role="search">
<i
class="tng-icon icon-search tng-search-field-icon"
aria-hidden="true"
></i>
<input
class="tng-search-field-input"
type="search"
placeholder="Large"
aria-label="Large"
/>
</form>

Disable the input — the whole field follows. The styling deliberately keys off .tng-search-field-input:disabled rather than any disabled descendant, so disabling the clear button while the query is empty doesn’t dim the entire control.

<form class="tng-search-field is-contained" role="search">
<i
class="tng-icon icon-search tng-search-field-icon"
aria-hidden="true"
></i>
<input
class="tng-search-field-input"
type="search"
placeholder="Search unavailable"
aria-label="Search unavailable"
disabled
/>
</form>

The field slides open and takes focus, the clear button appears once there’s a query, and the slot shows content while typing. Escape clears the text, then collapses the field. The List in the slot is only an example, with sample data.

source code