package showcase
import "github.com/templui/templui/components/selectbox"
templ SelectBoxDefault() {
<div class="w-full max-w-sm">
@selectbox.SelectBox() {
@selectbox.Trigger() {
@selectbox.Value(selectbox.ValueProps{
Placeholder: "Select a fruit",
})
}
@selectbox.Content() {
@selectbox.Group() {
@selectbox.Label() {
Fruits
}
@selectbox.Item(selectbox.ItemProps{
Value: "apple",
}) {
Apple
}
@selectbox.Item(selectbox.ItemProps{
Value: "banana",
}) {
Banana
}
@selectbox.Item(selectbox.ItemProps{
Value: "blueberry",
}) {
Blueberry
}
@selectbox.Item(selectbox.ItemProps{
Value: "grapes",
}) {
Grapes
}
@selectbox.Item(selectbox.ItemProps{
Value: "pineapple",
}) {
Pineapple
}
}
}
}
</div>
}
Installation
templui add selectboxLoad the script once in your layout:
<head>
@selectbox.Script()
</head>import "github.com/templui/templui/components/selectbox"Load the script once in your layout:
<head>
@selectbox.Script()
</head>Examples
With Label
package showcase
import (
"github.com/templui/templui/components/label"
"github.com/templui/templui/components/selectbox"
)
templ SelectBoxWithLabel() {
<div class="space-y-2 w-full max-w-sm">
@label.Label(label.Props{
For: "select-with-label",
}) {
Fruit
}
@selectbox.SelectBox() {
@selectbox.Trigger(selectbox.TriggerProps{
ID: "select-with-label",
}) {
@selectbox.Value(selectbox.ValueProps{
Placeholder: "Select a fruit",
})
}
@selectbox.Content() {
@selectbox.Label() {
Fruits
}
@selectbox.Item(selectbox.ItemProps{
Value: "apple",
}) {
Apple
}
@selectbox.Item(selectbox.ItemProps{
Value: "banana",
}) {
Banana
}
@selectbox.Item(selectbox.ItemProps{
Value: "orange",
}) {
Orange
}
}
}
</div>
}
Multiple
package showcase
import "github.com/templui/templui/components/selectbox"
templ SelectBoxMultipleSelect() {
<div class="w-full max-w-sm">
@selectbox.SelectBox() {
@selectbox.Trigger(selectbox.TriggerProps{Multiple: true}) {
@selectbox.Value(selectbox.ValueProps{
Placeholder: "Select a fruit",
})
}
@selectbox.Content() {
@selectbox.Group() {
@selectbox.Label() {
Fruits
}
@selectbox.Item(selectbox.ItemProps{
Value: "apple",
}) {
Apple
}
@selectbox.Item(selectbox.ItemProps{
Value: "banana",
}) {
Banana
}
@selectbox.Item(selectbox.ItemProps{
Value: "blueberry",
}) {
Blueberry
}
@selectbox.Item(selectbox.ItemProps{
Value: "grapes",
}) {
Grapes
}
@selectbox.Item(selectbox.ItemProps{
Value: "pineapple",
}) {
Pineapple
}
}
}
}
</div>
}
Multiple Pills
package showcase
import "github.com/templui/templui/components/selectbox"
templ SelectBoxMultipleSelectPills() {
<div class="w-full max-w-sm">
@selectbox.SelectBox() {
@selectbox.Trigger(selectbox.TriggerProps{ShowPills: true}) {
@selectbox.Value(selectbox.ValueProps{
Placeholder: "Select a fruit",
})
}
@selectbox.Content() {
@selectbox.Group() {
@selectbox.Label() {
Fruits
}
@selectbox.Item(selectbox.ItemProps{
Value: "apple",
}) {
Apple
}
@selectbox.Item(selectbox.ItemProps{
Value: "banana",
}) {
Banana
}
@selectbox.Item(selectbox.ItemProps{
Value: "blueberry",
}) {
Blueberry
}
@selectbox.Item(selectbox.ItemProps{
Value: "grapes",
}) {
Grapes
}
@selectbox.Item(selectbox.ItemProps{
Value: "pineapple",
}) {
Pineapple
}
}
}
}
</div>
}
No Search
package showcase
import "github.com/templui/templui/components/selectbox"
templ SelectBoxNoSearch() {
<div class="w-full max-w-sm">
@selectbox.SelectBox() {
@selectbox.Trigger() {
@selectbox.Value(selectbox.ValueProps{
Placeholder: "Select a fruit",
})
}
@selectbox.Content(selectbox.ContentProps{NoSearch: true}) {
@selectbox.Group() {
@selectbox.Label() {
Fruits
}
@selectbox.Item(selectbox.ItemProps{
Value: "apple",
}) {
Apple
}
@selectbox.Item(selectbox.ItemProps{
Value: "banana",
}) {
Banana
}
@selectbox.Item(selectbox.ItemProps{
Value: "blueberry",
}) {
Blueberry
}
@selectbox.Item(selectbox.ItemProps{
Value: "grapes",
}) {
Grapes
}
@selectbox.Item(selectbox.ItemProps{
Value: "pineapple",
}) {
Pineapple
}
}
}
}
</div>
}
Disabled
package showcase
import "github.com/templui/templui/components/selectbox"
templ SelectBoxDisabled() {
<div class="space-y-2 w-full max-w-sm">
@selectbox.SelectBox() {
@selectbox.Trigger(selectbox.TriggerProps{
Disabled: true,
}) {
@selectbox.Value(selectbox.ValueProps{
Placeholder: "Select a fruit",
})
}
@selectbox.Content() {
@selectbox.Label() {
Fruits
}
@selectbox.Item(selectbox.ItemProps{
Value: "apple",
}) {
Apple
}
@selectbox.Item(selectbox.ItemProps{
Value: "banana",
}) {
Banana
}
}
}
</div>
}
Form
Select a fruit category.
A fruit selection is required.
package showcase
import (
"github.com/templui/templui/components/form"
"github.com/templui/templui/components/selectbox"
)
templ SelectBoxForm() {
<div class="w-full max-w-sm">
@form.Item() {
@form.Label(form.LabelProps{
For: "select-form",
}) {
Fruit
}
@selectbox.SelectBox() {
@selectbox.Trigger(selectbox.TriggerProps{
ID: "select-form",
Name: "fruit",
HasError: true,
}) {
@selectbox.Value(selectbox.ValueProps{
Placeholder: "Select a fruit",
})
}
@selectbox.Content() {
@selectbox.Item(selectbox.ItemProps{
Value: "apple",
}) {
Apple
}
@selectbox.Item(selectbox.ItemProps{
Value: "banana",
}) {
Banana
}
@selectbox.Item(selectbox.ItemProps{
Value: "blueberry",
Selected: true,
}) {
Blueberry
}
@selectbox.Item(selectbox.ItemProps{
Value: "grapes",
}) {
Grapes
}
@selectbox.Item(selectbox.ItemProps{
Value: "pineapple",
Disabled: true,
}) {
Pineapple (out of stock)
}
}
}
@form.Description() {
Select a fruit category.
}
@form.Message(form.MessageProps{
Variant: form.MessageVariantError,
}) {
A fruit selection is required.
}
}
</div>
}
API Reference
SelectBox
Root container for the select box component.
| Name | Type | Default |
|---|---|---|
Unique identifier for the select container. Auto-generated if not provided. | | - |
Additional CSS classes to apply to the select container. | | - |
Additional HTML attributes to apply to the select container. | | - |
Whether multiple options can be selected. | | |
Trigger
Button that opens the select dropdown when clicked.
| Name | Type | Default |
|---|---|---|
Unique identifier for the trigger element. | | - |
Additional CSS classes to apply to the trigger. | | - |
Additional HTML attributes to apply to the trigger element. | | - |
Name attribute for the hidden input field used in forms. | | - |
Whether the select is disabled and non-interactive. | | |
Whether to display error styling on the select trigger. | | |
Whether multiple selections are allowed. | | |
Whether to show selected items as pills (automatically enables Multiple). | | |
Text template for showing selected count in multiple mode. | | - |
Value
Display area for the selected value(s) or placeholder text.
| Name | Type | Default |
|---|---|---|
Unique identifier for the value element. | | - |
Additional CSS classes to apply to the value display. | | - |
Additional HTML attributes to apply to the value element. | | - |
Placeholder text shown when no option is selected. | | - |
Whether this value display supports multiple selections. | | |
Content
Dropdown container that holds the selectable options.
| Name | Type | Default |
|---|---|---|
Unique identifier for the content element. | | - |
Additional CSS classes to apply to the dropdown content. | | - |
Additional HTML attributes to apply to the content element. | | - |
Whether to hide the search input in the dropdown. | | |
Placeholder text for the search input field. | | - |
Group
Container for grouping related select options together.
| Name | Type | Default |
|---|---|---|
Unique identifier for the group element. | | - |
Additional CSS classes to apply to the group. | | - |
Additional HTML attributes to apply to the group element. | | - |
Label
Label text for a group of select options.
| Name | Type | Default |
|---|---|---|
Unique identifier for the label element. | | - |
Additional CSS classes to apply to the label. | | - |
Additional HTML attributes to apply to the label element. | | - |
Item
Individual selectable option within the dropdown.
| Name | Type | Default |
|---|---|---|
Unique identifier for the item element. | | - |
Additional CSS classes to apply to the item. | | - |
Additional HTML attributes to apply to the item element. | | - |
The value of this option that will be submitted with forms. | | - |
Whether this option is currently selected. | | |
Whether this option is disabled and cannot be selected. | | |