oficina / estilo Public

menu: a toggle kind, Item.Controls and Item.Expanded

A row or bar action that shows and hides a region (Docs' Format, the
inspector) is a <button aria-expanded aria-controls> rendered disabled
with data-estilo-toggle, until the app's script binds it (I2 spec,
revision 2.1 C1).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by paul@keymail.dev fc949b7428aa2c765637f954500c70d4575f7699 parent f9b005d
3 files changed, +40 −9
  • menu/menu.go +16 −4
  • menu/menu_test.go +17 −0
  • menu/templates/menu.html +7 −5

CI passed — run details

diff --git a/menu/menu.go b/menu/menu.go
index 9c21d78..478fca3 100644
--- a/menu/menu.go
+++ b/menu/menu.go
@@ -30,8 +30,7 @@ func CSS() []byte { return append([]byte(nil), css...) }
func Templates() embed.FS { return templateFS }
// Item is one row rendered by estilo-menu-item. Set exactly one of Href,
-// Action and Dialog; each is a different element, and each works with
-// scripts off:
+// Action, Dialog and Controls; each is a different element:
//
// - Href: a link, <a href>, for a row that navigates.
// - Action: a one-button <form method="post"> to that path, for a row
@@ -40,9 +39,17 @@ func Templates() embed.FS { return templateFS }
// platform's invoker command (command="show-modal"), for a row that
// asks for more before anything happens ("Keyboard shortcuts…").
// chrome.js opens it where the engine has no invoker commands.
+// - Controls: a toggle, <button aria-expanded aria-controls>, for a row
+// or bar action that shows and hides a region of the page (Docs'
+// Format, which shows the inspector). It is rendered disabled, with
+// data-estilo-toggle, and stays so until the app's own script binds
+// it: with scripts off nothing can toggle the region, and a disabled
+// control does not claim to.
//
-// Action and Dialog came with Sheets, the second adopter: Docs' rows were
-// all links, and Sheets' Help moved into the account menu as a dialog.
+// The first three work with scripts off. Action and Dialog came with
+// Sheets, the second adopter: Docs' rows were all links, and Sheets' Help
+// moved into the account menu as a dialog. Controls came with Docs' I2
+// editor (spec 2026-11-11, revision 2.1 C1).
type Item struct {
Href, Label string
// Key is an already-formatted shortcut, from Shortcut. Optional.
@@ -51,6 +58,11 @@ type Item struct {
Action string
// Dialog is the id of the <dialog> a button row opens.
Dialog string
+ // Controls is the id of the region a toggle shows and hides
+ // (aria-controls); Expanded is whether that region is shown now, as
+ // the server rendered it (aria-expanded).
+ Controls string
+ Expanded bool
// Danger draws a destructive row in the negative tone
// (estilo-menu-item="danger"). Calls, the fifth adopter, was the
// first with one in a menu: "End meeting for everyone". The row still
diff --git a/menu/menu_test.go b/menu/menu_test.go
index 40b50c2..b06d4e8 100644
--- a/menu/menu_test.go
+++ b/menu/menu_test.go
@@ -187,3 +187,20 @@ func TestADangerItemIsDrawnInTheNegativeTone(t *testing.T) {
}
}
}
+
+// A toggle row shows and hides a region (Docs' Format, the inspector). It
+// is a button that says which region and whether it is shown, and it is
+// disabled as rendered: with scripts off nothing can toggle the region,
+// and a disabled control does not claim to. The app's script enables it.
+func TestAToggleRowNamesItsRegionAndStartsDisabled(t *testing.T) {
+ for _, expanded := range []bool{true, false} {
+ html := render(t, "estilo-menu-item", Item{Controls: "docs-inspector", Expanded: expanded, Label: "Format"})
+ want := `<button estilo-menu-item type="button" aria-expanded="false" aria-controls="docs-inspector" disabled data-estilo-toggle><span estilo-menu-label>Format</span></button>`
+ if expanded {
+ want = strings.Replace(want, `"false"`, `"true"`, 1)
+ }
+ if html != want {
+ t.Errorf("expanded=%v:\ngot %s\nwant %s", expanded, html, want)
+ }
+ }
+}
diff --git a/menu/templates/menu.html b/menu/templates/menu.html
index dd668ae..0f3cd43 100644
--- a/menu/templates/menu.html
+++ b/menu/templates/menu.html
@@ -1,12 +1,14 @@
{{/* estilo-menu-item: one row in any estilo-menu. Data: menu.Item, with
- exactly one of Href (a link), Action (a one-button POST form) or
- Dialog (a button opening the <dialog> with that id through the
- platform's invoker command). All three work with scripts off; chrome.js
- only adds the dialog for engines without invoker commands. Callers
+ exactly one of Href (a link), Action (a one-button POST form), Dialog
+ (a button opening the <dialog> with that id through the platform's
+ invoker command) or Controls (a toggle for the region with that id,
+ disabled until the app's script binds it). The first three work with
+ scripts off; chrome.js only adds the dialog for engines without
+ invoker commands. Callers
supply the label in their own locale; Key is an already-formatted
shortcut (menu.Shortcut). Danger marks a destructive row
(estilo-menu-item="danger"), drawn in the negative tone. */}}
-{{define "estilo-menu-item"}}{{if .Action}}<form method="post" action="{{.Action}}"><button estilo-menu-item{{if .Danger}}="danger"{{end}} type="submit">{{template "estilo-menu-item-body" .}}</button></form>{{else if .Dialog}}<button estilo-menu-item{{if .Danger}}="danger"{{end}} type="button" commandfor="{{.Dialog}}" command="show-modal">{{template "estilo-menu-item-body" .}}</button>{{else}}<a estilo-menu-item{{if .Danger}}="danger"{{end}} href="{{.Href}}">{{template "estilo-menu-item-body" .}}</a>{{end}}{{end}}
+{{define "estilo-menu-item"}}{{if .Action}}<form method="post" action="{{.Action}}"><button estilo-menu-item{{if .Danger}}="danger"{{end}} type="submit">{{template "estilo-menu-item-body" .}}</button></form>{{else if .Dialog}}<button estilo-menu-item{{if .Danger}}="danger"{{end}} type="button" commandfor="{{.Dialog}}" command="show-modal">{{template "estilo-menu-item-body" .}}</button>{{else if .Controls}}<button estilo-menu-item{{if .Danger}}="danger"{{end}} type="button" aria-expanded="{{if .Expanded}}true{{else}}false{{end}}" aria-controls="{{.Controls}}" disabled data-estilo-toggle>{{template "estilo-menu-item-body" .}}</button>{{else}}<a estilo-menu-item{{if .Danger}}="danger"{{end}} href="{{.Href}}">{{template "estilo-menu-item-body" .}}</a>{{end}}{{end}}
{{define "estilo-menu-item-body"}}<span estilo-menu-label>{{.Label}}</span>{{with .Key}}<kbd estilo-menu-key>{{.}}</kbd>{{end}}{{end}}
{{/* estilo-icon-check: the glyph inside an estilo-menu-check column.
Lucide "check" (ISC, brand/LICENSE.lucide). */}}