searchbar

package
v0.4.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 4, 2026 License: MIT Imports: 7 Imported by: 0

README

A one-control filter bar: a magnifier cap followed by a text field, both sized by --control-height so the bar lines up with any other control in the ecosystem. It holds no list and filters nothing itself — it reports each keystroke and the host decides what that means.

Usage

import "github.com/tinywasm/components/searchbar"

bar := &searchbar.SearchBar{Placeholder: "Buscar..."}
bar.OnFilterChange(func(term string) { /* filter your list */ })

API

SearchBar Struct
  • Placeholder string: Text shown in the field when it is empty. If left empty, the bar falls back to "Search…".

Filterable

SearchBar implements widget.Filterable. The bar reports the term and nothing else, so any control that can produce a term — a calendar, a select — can replace it in the same host slot without the host changing.

Parts

Class Element Role
searchbar root the bar as one rounded, clipped control
searchbar__icon <label> the square primary cap holding the magnifier
searchbar__glyph <svg> the magnifier itself, currentColor
searchbar__input <input type="search"> the text field, the bar's body

The root and the input both answer to --control-height, so cap and body can never drift apart vertically.

Documentation

Index

Constants

View Source
const (
	PartIcon  = widget.Part("icon")  // the square coloured cap holding the magnifier
	PartGlyph = widget.Part("glyph") // the magnifier <svg> itself
	PartInput = widget.Part("input") // the text field, the body of the bar
)
View Source
const NameSearchBar = widget.Name("searchbar")

NameSearchBar is the widget identity; it produces the class prefix "searchbar" and the part classes "searchbar__icon", "searchbar__glyph", "searchbar__input".

Variables

This section is empty.

Functions

This section is empty.

Types

type SearchBar struct {
	Element // value embed — NEVER *dom.Element (TinyGo heap constraint)

	// Placeholder is the field's placeholder text. Empty uses defaultPlaceholder.
	Placeholder string
	// contains filtered or unexported fields
}

SearchBar is a single-control filter bar: a magnifier cap followed by a text field. It holds no list and knows nothing about what it filters — it reports the term and the host decides what that means.

It satisfies widget.Filterable, which is the whole reason it is swappable: a host holds the seam, not this type, so a calendar or a select that also implements Filterable takes its place with no change to the host.

func (*SearchBar) IconSvg

func (s *SearchBar) IconSvg() *sprite.Sprite

IconSvg registers the bar's magnifier. Method receiver (not a free function) so tinywasm/ssr detects a single receiver type for the package and emits RenderCSS + IconSvg together.

func (*SearchBar) OnFilterChange

func (s *SearchBar) OnFilterChange(fn func(term string))

OnFilterChange implements widget.Filterable: it registers the sink for every keystroke. The host calls it once while wiring its filter slot; passing nil clears the sink.

The signature is fixed by widget.Filterable — do not add a parameter, do not return anything, do not add a companion getter.

func (*SearchBar) Render

func (s *SearchBar) Render() *Element

func (*SearchBar) RenderCSS

func (s *SearchBar) RenderCSS() *css.Stylesheet

RenderCSS defines the search bar's visual contract using the style DSL.

func (*SearchBar) WidgetKind

func (s *SearchBar) WidgetKind() widget.Kind

Form, not Combobox: the bar has no popup and no options list. Combobox would license Open/Selected states this control can never be in.

func (*SearchBar) WidgetName

func (s *SearchBar) WidgetName() widget.Name

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL