Components Buttons

Toggle group

Choose one display mode from a segmented group.

Live previewGo + HTML
View density

Usage

Each item accepts Label, Value, Checked, and Disabled. Native radios keep a single selection, submit the value with the form, and support arrow-key navigation.

Register toggle-group with Head and pass its properties to Render. Go setup guide

Go usage
Go usage
err := mono.UI.Render(w, "toggle-group", mono.Props{
	"Items": []any{
		map[string]any{
			"Label": "Compact",
			"Value": "compact",
		},
		map[string]any{
			"Checked": true,
			"Label":   "Default",
			"Value":   "default",
		},
		map[string]any{
			"Label": "Spacious",
			"Value": "spacious",
		},
	},
	"Label": "View density",
	"Name":  "density",
})
Rendered HTML
Rendered HTML
<fieldset id="demo-toggle-group" data-mono="toggle-group">
  <legend class="mu-label">View density</legend>
  <div class="mu-segments">
    <label><input class="mu-sr-only" type="radio" name="density" value="compact"  ><span>Compact</span></label><label><input class="mu-sr-only" type="radio" name="density" value="default" checked ><span>Default</span></label><label><input class="mu-sr-only" type="radio" name="density" value="spacious"  ><span>Spacious</span></label>
  </div>
</fieldset>
Go template
Go template
<fieldset id="{{.ID}}" data-mono="toggle-group">
  <legend class="mu-label">{{.Label}}</legend>
  <div class="mu-segments">
    {{range .Items}}<label><input class="mu-sr-only" type="radio" name="{{or $.Name $.ID}}" value="{{.Value}}" {{if .Checked}}checked{{end}} {{if .Disabled}}disabled{{end}}><span>{{.Label}}</span></label>{{end}}
  </div>
</fieldset>
Component CSS
Component CSS
[data-mono="toggle-group"] { border: 0; min-inline-size: 0; padding: 0; }
[data-mono="toggle-group"] legend { margin-bottom: .55rem; }
[data-mono="toggle-group"] .mu-segments { display: inline-flex; flex-wrap: wrap; align-items: stretch; padding: .19rem; gap: .15rem; border: 1px solid var(--mu-line,#bbb); border-radius: .5rem; }
[data-mono="toggle-group"] label { position: relative; cursor: pointer; }
[data-mono="toggle-group"] label span { display: block; padding: .42rem .7rem; border: 1px solid transparent; border-radius: .33rem; font-size: .9rem; }
[data-mono="toggle-group"] input:checked + span { background: #171717; color: white; border-color: currentColor; font-weight: 650; }
[data-mono="toggle-group"] input:focus-visible + span { outline: 2px solid currentColor; outline-offset: 2px; }
[data-mono="toggle-group"] input:disabled + span { opacity: .5; }
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 Component CSS

HTML head
<link rel="stylesheet" href="./base.css">
<link rel="stylesheet" href="./toggle-group.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 toggle-group
Example properties (JSON)
example.json
{
  "Items": [
    {
      "Label": "Compact",
      "Value": "compact"
    },
    {
      "Checked": true,
      "Label": "Default",
      "Value": "default"
    },
    {
      "Label": "Spacious",
      "Value": "spacious"
    }
  ],
  "Label": "View density",
  "Name": "density"
}