Skip to content
dev

Combobox

Client-mode comboboxes toggle entirely in the browser (no HTTP on open/select); server-mode keeps an HTMX lazy/search path for options that can't be pre-rendered.

Default Rendered example
  • Technology
  • Healthcare
  • Finance
  • Retail
  • Education

Option filtering stays internal. This form submits its record query and selected industry.

Usage Example
// Client mode: options are pre-rendered, toggling happens in the browser.
var IndustryCfg = combobox.Config{
    ID: "industry", Name: "industry", Label: "Industry",
    Mode:   combobox.ModeSingle,
    Source: combobox.Source{Static: industryOptions},
}
@combobox.Combobox(IndustryCfg, combobox.State{Options: IndustryCfg.Source.Static})

Built-in text: the development API provides expressions.Combobox for application defaults, request preferences, and individual component overrides. Read the expression guide.

Client Multi-Select

Use arrow keys to move between enabled options, Enter or Space to select, and Escape to return to the trigger. Checkbox selection supports Clear all. Option.Trailing renders supporting content without changing the selected label. DisablePersistence lets server-rendered state own the selection after navigation.

Client Multi-Select Rendered example
  • Go 12
  • Rust 3
  • TypeScript
  • Python
  • Kotlin
Client Multi-Select
var SkillsCfg = combobox.Config{
    ID: "skills", Name: "skills", Mode: combobox.ModeMultiple, EnableClearAll: true, DisablePersistence: true,
    Source: combobox.Source{Static: []combobox.Option{
        {Value: "go", Label: "Go", Trailing: skillCount("12")},
    }},
}
@combobox.Combobox(SkillsCfg, combobox.State{Options: SkillsCfg.Source.Static})

Selected and Disabled Options

Set Config.Selected for first-paint values. Disabled options stay visible but cannot be selected.

Selected and Disabled Options Rendered example
  • US East
  • EU West
  • AP South
  • Legacy region
Selected and Disabled Options
var RegionsCfg = combobox.Config{
    ID: "region", Name: "region", Label: "Region",
    Selected: []string{"us-east-1"},
    Source: combobox.Source{Static: []combobox.Option{
        {Value: "us-east-1", Label: "US East"},
        {Value: "legacy", Label: "Legacy region", Disabled: true},
    }},
}
@combobox.Combobox(RegionsCfg, RegionsCfg.InitialState())

Use a non-empty LazyEndpoint to select server mode, then set Toggle/Options/Clear endpoints for HTMX selection, search, and clearing. The current LazyEndpoint value is a mode marker; OptionsEndpoint is the URL actually requested. Updating a selection keeps the menu open and preserves your search draft.

Server Mode (lazy search) Rendered example
  • No matches found
Server Mode (lazy search)

Cascading Server Filters

DependsOn adds other fields to combobox HTMX requests. Add an hx-get on the parent field when changing it should immediately refresh the dependent options.

Cascading Server Filters Rendered example
  • No matches found
Cascading Server Filters
selectedProvider := "aws"
var ClusterCfg = combobox.Config{
    ID: "cluster", Name: "cluster", Mode: combobox.ModeSingle,
    EnableSearch: true,
    DependsOn: []string{"provider"},
    ToggleEndpoint:  "/api/.../clusters/toggle",
    OptionsEndpoint: "/api/.../clusters/options",
    ClearEndpoint:   "/api/.../clusters/clear",
    Source: combobox.Source{LazyEndpoint: "/api/.../clusters/options"},
}

// OptionsProvider receives search and deps["provider"] on the server.
clustersProvider := func(ctx context.Context, search string, deps map[string]string) ([]combobox.Option, error) {
    return clustersForProvider(deps["provider"], search)
}

<select
    name="provider"
    hx-get={ ClusterCfg.OptionsEndpoint }
    hx-trigger="change"
    hx-target="#cluster-options"
    hx-swap="outerHTML"
    hx-include="#cluster [data-combobox-search], #cluster input[type=hidden]">
    <option value={ selectedProvider }>AWS</option>
</select>
@combobox.Combobox(ClusterCfg, combobox.State{})

Go API

development

The examples above cover behavior and composition. pkg.go.dev is the canonical reference for exported types, functions, methods, and Go documentation.

github.com/araihu/goshtoso/components/combobox

An exact external API link is added to versioned builds.