Radio Group

A group of radio buttons.

Anatomy

RadioGroup do |r|
r.item
r.item
end

API Reference

RadioGroup

NameTypeDefault
name:stringnil
value:stringnil
dir:string"ltr"
include_hidden:booleantrue
Whether to include a hidden input field for form submission.
attributeskeyword arguments

RadioGroup#item

NameTypeDefault
name:stringnil
value:stringnil
checked:booleanfalse
disabled:booleanfalse
attributeskeyword arguments

RadioGroup#items (Builder)

Builder method for generating multiple radio items from a collection.

NameTypeDefault
required collectionarray
An array of objects or hashes for building radio items. Each item will generate a radio button with its associated label.
required value_method:symbol
Method called on each collection item to get the radio button value. Used for form submission and selection logic.
required text_method:symbol
Method called on each collection item to get the display text for the radio button label.
container_class:stringnil
CSS classes for the container div wrapping each radio item and its label.
disabled_items:string or arraynil
Values of radio items to disable. Can be a single value or array of values matching the value_method results.
id_prefix:stringnil
String to prefix the auto-generated radio item IDs. If not provided, uses the name attribute as prefix.

RadioGroup#label (Builder)

Builder method for setting default attributes on radio item labels when using the items builder. Must be called before items method.

NameTypeDefault
attributeskeyword arguments
Attributes to apply to all radio item labels generated by the items builder method.

RadioGroup#radio (Builder)

Builder method for setting default attributes on radio items when using the items builder. Must be called before items method.

NameTypeDefault
attributeskeyword arguments
Attributes to apply to all radio items generated by the items builder method.

Keyboard Interactions

KeyDescription
TabMoves focus to either the checked radio item or the first radio item in the group.
SpaceWhen focus is on an unchecked radio item, checks it.
ArrowDownMoves focus and checks the next radio item in the group.
ArrowRightMoves focus and checks the next radio item in the group.
ArrowUpMoves focus and checks the previous radio item in the group.
ArrowLeftMoves focus and checks the previous radio item in the group.

Examples