Skip to content

Radio Group

A list of options where the player picks exactly one, for forms and settings: difficulty, server region, a report reason. Each row is the hit area, and the circle grows on touch and console.

Radio Group exampleRadio Group example
Lucy.RadioGroup.new({
    items = {
        { value = "house", label = "House" },
        { value = "disco", label = "Disco" },
        { value = "techno", label = "Techno" },
        { value = "pop", label = "Pop", disabled = true },
    },
    value = "house",
    onValueChange = function(genre)
        app.toast(`Next up: {genre}`)
    end,
    Parent = parent,
})

Props

PropTypeDefaultState keyWhat it does
itemstableThe options, in order (see below)
valueanyfalseyesThe picked value, false when nothing is picked yet
orientationstring"vertical"vertical for a column, horizontal for a row
gapspacing"Space2"Space between options
size"sm" | "md" | "lg" | "xl""md"yesThe circle, the label’s text and the row’s height, as a Switch or Button of the same size
disabledbooleanfalseyesGreys every option out and ignores clicks
visiblebooleantrueyesShows or hides it
onValueChangefunctionCalled with (value, handle) when it changes

It also takes the props every component takes.

An option is a value (shown as its text) or a table:

FieldWhat it does
valueWhat the option stands for. Required
labelIts text. Defaults to the value. text works too
childrenAnything after the label in the option’s slot, such as a badge. They take the label’s look and fade when disabled. With children and no label, the option shows no text
disabledGreys this option out

Once something is picked, the player can pick another option but cannot clear it. When the player picks one, it reports select with that value for useUiSound.

handle.items holds one table per option, in order, with its root, circle, dot and label.

Methods

NameWhat it does
group:select(value)Picks the option, as if the player clicked it

Examples

Keep the choice in app state:

Radio Group exampleRadio Group example
Lucy.RadioGroup.new({
    items = { "House", "Disco", "Hip hop", "Techno" },
    value = app.state:ref("booth.genre"),
    Parent = booth,
})

A radio group comes in the same sizes as the other controls, and each size is as tall as a Switch or Button of that size, so they line up in a settings panel. Go a size up on a phone, where the options need to be easy to tap:

Radio Group exampleRadio Group example
Lucy.Stack.new({
    gap = "Space3",
    children = {
        Lucy.Switch.new({ label = "Crowd sounds", size = "lg", checked = true }),
        Lucy.Text.new({ text = "Who can ask you to dance", variant = "large" }),
        Lucy.RadioGroup.new({
            items = { "Everyone", "Crew only", "Nobody" },
            value = "Crew only",
            orientation = "horizontal",
            size = "lg",
        }),
    },
    Parent = parent,
})

Preview

In Studio, from the command bar: Lucy.Preview.show("RadioGroup").