selectsearch

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2026 License: MIT Imports: 3 Imported by: 0

README

SelectSearch

Searchable dropdown with static options, live filtering, and optional DB search callback.

Features

  • CSS-first toggle (no JS needed for open/close)
  • Live search filtering
  • Badge descriptions for options
  • Callback for custom search (e.g., database)
  • Accessible via labels and semantic HTML

Usage

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

ss := &selectsearch.SelectSearch{
    Placeholder: "Choose an option...",
    Options: []selectsearch.Option{
        {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 []Option: Initial list of options.
  • OnSelect func(id, description string): Callback triggered when an option is selected.
  • OnSearch func(term string) []Option: Callback triggered when all local options are filtered out.
Option 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

This section is empty.

Functions

This section is empty.

Types

type Option

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

Option represents a selectable item.

type SelectSearch

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

func (*SelectSearch) IconSvg

func (c *SelectSearch) IconSvg() map[string]string

func (*SelectSearch) Render

func (c *SelectSearch) Render() *dom.Element

func (*SelectSearch) RenderCSS

func (c *SelectSearch) RenderCSS() string

Jump to

Keyboard shortcuts

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