Search

Material Design 3 search bar and search view web components (lit-material-search-bar, lit-material-search-view).

  • 3.2 KB gzipped
  • @lit-material/search 0.1.0
  • Renders on the server

Example

Install

npm install @lit-material/search @lit-material/tokens
import "@lit-material/search";

Link @lit-material/tokens/css/index.css once per page for the colour, type and shape tokens. Install guide

API

Material Design 3 search bar — a pill-shaped text field meant to pair with lit-material-search-view: focusing or clicking this bar is what the view binds to (via its anchor/anchorElement) to open itself, the same way lit-material-tooltip binds to whatever anchor it's given, rather than this component knowing anything about the view itself.

Properties

PropertyAttributeTypeDefaultDescription
valuevaluestring""
placeholderplaceholderstring"Search"
labellabelstring""Accessible name for the input, when placeholder alone isn't descriptive enough. Falls back to placeholder.
disableddisabledbooleanfalse

Events

EventDescription
inputFires whenever value changes, via typing or the clear button.
searchFires when Enter is pressed in the input.

Slots

SlotDescription
leading-iconOverrides the default magnifying-glass icon (e.g. with a back arrow or a menu icon).
trailingOptional trailing content (an avatar, extra icon buttons…), shown after the clear button.

CSS parts

PartDescription
search-barThe pill container (background, shape, padding).
inputThe native <input>.
clear-buttonThe clear button, only rendered while value is non-empty.

<lit-material-search-view>

Material Design 3 (docked) search view — a suggestions panel anchored below a lit-material-search-bar, built on the native Popover API (top-layer rendering escapes clipping/overflow ancestors) the same way lit-material-menu builds on it — but popover="manual", not "auto", like lit-material-tooltip/lit-material-snackbar: an auto popover's native light-dismiss hides it the instant it opens here, because the very click that focuses the anchor (and triggers this view's own JS-driven open, below) isn't a native popovertarget invoker relationship the browser recognizes as legitimate — so this view manages its own outside- click and Escape dismissal instead.

Properties

PropertyAttributeTypeDefaultDescription
openopenbooleanfalse
anchoranchorstring | undefinednoneid of the anchor element (typically a lit-material-search-bar) to position against and bind to. See also anchorElement.
anchorElementproperty onlyHTMLElement | undefinednoneThe element this view is positioned against and bound to.

Events

EventDescription
closeFires after the view closes, for any reason (item activation, close(), Escape, or an outside click).

Slots

SlotDescription
defaultlit-material-list-item elements (or any other content, e.g. an empty-state message).

CSS parts

PartDescription
viewThe popover surface (background, padding, shape, elevation).

Source on GitHub npm