selectsearch

package
v0.1.10 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2026 License: MIT Imports: 6 Imported by: 0

README

SelectSearch

Signal-driven searchable dropdown with static options, live filtering, and optional DB search callback.

Features

  • Signal-driven open/close state using Show.
  • Live search filtering with BindChildren for surgical list updates.
  • Badge descriptions for options.
  • Callback for custom search (e.g., database).
  • Two-way bound search input with .Autofocus().
  • Accessible via labels and semantic HTML.

Usage

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

ss := &selectsearch.SelectSearch{
    Placeholder: "Choose an option...",
    Options: []selectsearch.SsOption{
        {ID: "1", Label: "Option 1", Description: "First option"},
        {ID: "2", Label: "Option 2", Description: "Second option"},
    },
    OnSelect: func(id, description string) {
        fmt.Printf("Selected: %s\n", id)
    },
}

API

SelectSearch Struct
  • Placeholder string: Text shown when no option is selected.
  • Options []SsOption: Initial list of options.
  • OnSelect func(id, description string): Callback triggered when an option is selected.
  • OnSearch func(term string) []SsOption: Callback triggered when all local options are filtered out.
SsOption Struct
  • ID string: Unique identifier for the option.
  • Label string: Visible text for the option.
  • Description string: Optional secondary text (badge).

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ClsSsBox      Class = "ss-box"
	ClsSsToggle   Class = "ss-toggle"
	ClsSsDropdown Class = "ss-dropdown"
	ClsSsHeader   Class = "ss-header"
	ClsSsIcon     Class = "ss-icon"
	ClsSsSearch   Class = "ss-search"
	ClsSsOptions  Class = "ss-options"
	ClsSsOption   Class = "ss-option"
	ClsSsLabel    Class = "ss-label"
	ClsSsDesc     Class = "ss-desc"
)

Functions

This section is empty.

Types

type SelectSearch

type SelectSearch struct {
	Element                                  // value embed — NEVER pointer (TinyGo heap constraint)
	Placeholder string                       // text shown when nothing is selected
	Options     []SsOption                   // initial static options
	OnSelect    func(id, description string) // called when user picks an option
	OnSearch    func(term string) []SsOption // called when ALL local options are filtered out
	// contains filtered or unexported fields
}

func (*SelectSearch) IconSvg

func (c *SelectSearch) IconSvg() *sprite.Sprite

func (*SelectSearch) Init added in v0.1.7

func (c *SelectSearch) Init(_ Ctx)

func (*SelectSearch) Render

func (c *SelectSearch) Render() *Element

func (*SelectSearch) RenderCSS

func (c *SelectSearch) RenderCSS() *Stylesheet

func (*SelectSearch) SetOptions added in v0.1.7

func (c *SelectSearch) SetOptions(options []SsOption)

SetOptions replaces the option list — safe to call after Init/Render, e.g. once options from an async source (fetch, MCP call) arrive. Preserves the current search query filter, if any.

type SsOption added in v0.1.4

type SsOption struct {
	ID          string // unique identifier, returned in OnSelect
	Label       string // visible text
	Description string // optional badge shown on the right
}

SsOption represents a selectable item.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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