Buttons
Libadwaita adds three button widgets to GTK’s own. Put an icon plus a label on a button with button content, use a split button to pair an action with a menu of alternatives, or reach for a toggle group when a row of linked buttons should act as a single-choice selector.
The plain button and the menu button belong to GTK. They are Gtk.Button and
Gtk.MenuButton, documented under Gtk Buttons with the
style classes that shape them.
Each block below is a stack of windows. The first one RUNS the widget: the preview
is the live browser port, so it follows the light and dark toggle the way a real
window would, and the HTML tab beside it holds the very markup that paints it —
one import '@gjsify/adwaita-web' registers every element in it. Then comes
one window per kind of implementation — Native TypeScript, the @girs program
that runs unchanged on GJS, Node, Bun and Deno, with the matching Blueprint
declaration beside it, UI frameworks, the same widget written in Solid, Vue and
React through @gjsify/gtk-host — or, where the widget is built imperatively rather
than declared, the recorded reason it has no such snippet — and NativeScript,
the port that runs on a phone. That last window splits the way the first one does. An
XML template holds the tree, and the TypeScript beside it is the loader.
Libadwaita is the reference here, typed by
@girs/adw-1.
@gjsify/adwaita-web
and @gjsify/adwaita-nativescript
follow its naming, and where one of them differs, its own window says so.
Button Content
Section titled “Button Content”To put an icon and text on a button, make an Adw.ButtonContent its child.
It pairs a symbolic icon with a label, so the action reads at a glance and in
words. Set can-shrink if the label may ellipsize when horizontal space runs
short.
Split Button
Section titled “Split Button”Use a split button when one action is the obvious default and the rest are
variations on it. Clicking the main half runs the default; the attached arrow
opens a menu with the alternatives. Add .flat for the variant that belongs in a
header bar or toolbar, where a raised button looks too heavy.
Toggle Group
Section titled “Toggle Group”For a small set of mutually exclusive options, such as a view mode, use a
toggle group: a linked row where exactly one toggle is active at a time. Each
toggle takes an icon, a label, or both. The style classes .flat and .round
adapt the group for a toolbar or give it a pill shape.
One divergence in the block below, and it runs the unusual way round: the third
toggle’s view-columns-symbolic is in no icon theme, so only the web pane
draws it — from a glyph @gjsify/adwaita-web hand-draws itself. The GJS and
Blueprint panes name the same icon and get GTK’s broken-image paintable. It stays
that way on purpose: dropping the hand-drawn glyph would put the web pane on
image-missing as well, which is parity bought by making both panes worse.
A toggle group is a single tab stop, the way Adw.ToggleGroup routes focus:
Tab enters on the active toggle and the next Tab leaves the group, while Left and
Right move between toggles. Up and Down stay the page’s, as they are upstream.
Home and End jump to the ends — that pair is the WAI-ARIA pattern rather than
anything GTK does, since GTK’s focus directions have no Home or End. It announces itself as a radio group with one
checked toggle — GTK_ACCESSIBLE_ROLE_RADIO_GROUP upstream — unless the element
already carries a role when it connects, which it then keeps; role="tablist"
additionally switches the toggles to tabs, the way Adw.InlineViewSwitcher does.
Set it in markup or before the element is inserted: it is read once, which is all
GTK allows too — GtkAccessible:accessible-role is documented “cannot be changed
once set”, and the only setter is class-level.
Related
Section titled “Related”- Gtk Buttons: the plain button, its style classes and the menu button.
- Boxed Lists: rows that embed these buttons and reuse the same style classes.
- Layout: the containers that arrange buttons within a window.
- Adwaita Storybook: the same widgets in a live component browser you can poke at.