Components Forms

Native select

Offer a short list using the operating system’s selection control.

Live previewGo + HTML

Usage

Pass Items with Label, Value, Selected, and optional Disabled. The selected value is submitted under Name. Native keyboard and touch pickers work without JavaScript.

Register native-select with Head and pass its properties to Render. Go setup guide

Go usage
Go usage
err := mono.UI.Render(w, "native-select", mono.Props{
	"Items": []any{
		map[string]any{
			"Label":    "Uncoated",
			"Selected": true,
			"Value":    "uncoated",
		},
		map[string]any{
			"Label": "Matte",
			"Value": "matte",
		},
		map[string]any{
			"Label": "Gloss",
			"Value": "gloss",
		},
	},
	"Label": "Paper finish",
	"Name":  "finish",
})
Rendered HTML
Rendered HTML
<div id="demo-native-select" data-mono="native-select" class="mu-stack">
  <label for="demo-native-select-value" class="mu-label">Paper finish</label>
  <select id="demo-native-select-value" class="mu-field" name="finish"  >
    <option value="uncoated" selected >Uncoated</option><option value="matte"  >Matte</option><option value="gloss"  >Gloss</option>
  </select>
</div>
Go template
Go template
<div id="{{.ID}}" data-mono="native-select" class="mu-stack">
  <label for="{{.ID}}-value" class="mu-label">{{.Label}}</label>
  <select id="{{.ID}}-value" class="mu-field" name="{{or .Name .ID}}" {{if .Required}}required{{end}} {{if .Disabled}}disabled{{end}}>
    {{range .Items}}<option value="{{.Value}}" {{if .Selected}}selected{{end}} {{if .Disabled}}disabled{{end}}>{{.Label}}</option>{{end}}
  </select>
</div>
Use the HTML in a static site

Copy the rendered HTML above. Download these assets into the same folder as your page, then add the tags below to its head.

Shared CSS

HTML head
<link rel="stylesheet" href="./base.css">

Copy into your project

Run this command from the Mono checkout. Set -out to the component directory in your application.

Terminal
go run ./cmd/mono-ui add -out ./components native-select
Example properties (JSON)
example.json
{
  "Items": [
    {
      "Label": "Uncoated",
      "Selected": true,
      "Value": "uncoated"
    },
    {
      "Label": "Matte",
      "Value": "matte"
    },
    {
      "Label": "Gloss",
      "Value": "gloss"
    }
  ],
  "Label": "Paper finish",
  "Name": "finish"
}