render NitroKit::RadioButtonGroup.new(
legend:"Billing currency",
description:"Contact support before the next renewal date to change currency.",
id:"gallery-radio-button-group-disabled",
name:"billing[currency]",
value:"USD",
disabled:true,
options: [ [ "United States dollar", "USD" ], [ "Euro", "EUR" ] ]
)
Rails form builder
A builder field derives the selected model value, names, IDs, descriptions, and errors.
invitation = Gallery::FormExamples.team_invitation(:invalid)
form_with(
model: invitation,
scope::invitation,
url:"#invitation-role-group",
builder:NitroKit::FormBuilder,
id:"gallery-radio-button-group-invitation-form"
) do |form|
form.group do
form.field(
:role,
as::radio_group,
id:"gallery-radio-button-group-invitation-role",
label:"Invitation role",
description:"Choose the least privileged role that supports the member's work.",
options: [ [ "Administrator", "admin" ], [ "Member", "member" ], [ "Viewer", "viewer" ] ],
required:true
)
form.submit("Send invitation", id:"gallery-radio-button-group-invitation-save")
endend
Under pressure
Thirty Gallery::Hostile badge labels as radio choices under an overlong legend and paragraph guidance, then the same choices as a horizontal segmented control and as cards with paragraph descriptions.
native fieldset[data-nk=radio-button-group]; orientations vertical horizontal; presentations list cards segmented; sizes md lg
Contract
Options are non-empty Choice values with unique values and IDs. A non-nil value: is compared by string value; value: nil selects nothing, including a choice whose value is "". A name with no id-safe characters raises instead of skipping IDs. required: true marks application state as data-required=true and every native radio required; it does not emit invalid aria-required on the fieldset. The legend and description scope the whole group, so choices do not repeat the description through aria-describedby.
Relevant patterns
Application conventions this component belongs to. Each summary is the leading section of its pattern document.
docs/patterns/resource_form.md
Resource form
One model-backed Phlex component renders initial and invalid states.
Rails owns names, values, and errors; Nitro owns presentation.
Invalid mutations render the same model with 422; success redirects with 303.
Use one primary submit: the shell toolbar owns it, or a standalone form keeps it inside form.group.
Wrap the form in a Turbo Frame only when it needs an independent lifecycle.
System rules for coding agents
Instructions for coding agents, repeated on every component page so one fetched page has enough context. Humans can usually skip this section.
test/dummy/app/components/gallery/agent_rules.rb
View agent instructions
Nitro Kit 2.0 is a gem-owned, Phlex-only UI system for Rails. Render components directly: render NitroKit::Button.new("Save", variant: :primary).
Compose Nitro components inside application-owned Phlex classes. Public initializers and declared slots are the component API; private methods are not.
Public options are explicit keywords, and enumerated options are closed vocabularies. Invalid names or values raise ArgumentError; this component's accepted options are in the contract above.
Pass native attributes through their typed boundary: html: for HTML, aria: for ARIA, and data: for application data. class and style are forbidden, including inside html:.
Nitro owns NitroKit::Component::RESERVED_DATA_ATTRIBUTES: data-nk, data-slot, data-variant, data-size, data-nk-escape, data-enhanced, data-state, data-disabled, data-required, data-orientation, data-presentation, data-placement, data-layout, data-side, data-field-type, data-dir, data-gap, data-align, data-justify, data-wrap, data-cols, data-mode, data-key. Do not pass them through data:. data-action, data-controller are additive and compose with Nitro behavior.
If an integration truly requires a class, use desperately_need_a_class:. It requires a non-blank String and marks the exception with data-nk-escape="class".
Every root emits data-nk; owned parts emit component-qualified data-slot values such as field-control or card-title. Select on those attributes, never on classes.
Customize components with documented --nk-* custom properties in an application stylesheet. Variables beginning with --_nk-* are private component mechanics.
Use NitroKit::Flex and NitroKit::Grid for layout. Parents own external placement and available width; components own their intrinsic geometry.
Preserve native elements and accessibility semantics. State is exposed through native semantics and ARIA first, and through data-state when styling or behavior also needs it.