Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

improvement: add 'inline=bool' to mo.ui.radio (#584)

Myles Scolnick249866bb7604
diff --git a/frontend/src/plugins/impl/RadioPlugin.tsx b/frontend/src/plugins/impl/RadioPlugin.tsx
index 30686fd758..85b95e0b19 100644
--- a/frontend/src/plugins/impl/RadioPlugin.tsx
+++ b/frontend/src/plugins/impl/RadioPlugin.tsx
@@ -7,6 +7,7 @@ import { Label } from "@/components/ui/label";
import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group";
import { IPlugin, IPluginProps } from "@/plugins/types";
import { Labeled } from "./common/labeled";
+import { cn } from "@/utils/cn";
/**
* Arguments for a radio group
@@ -16,6 +17,7 @@ import { Labeled } from "./common/labeled";
*/
interface Data {
label: string | null;
+ inline: boolean;
options: string[];
}
@@ -27,6 +29,7 @@ export class RadioPlugin implements IPlugin<S, Data> {
validator = z.object({
initialValue: z.string().nullable(),
+ inline: z.boolean().default(false),
label: z.string().nullable(),
options: z.array(z.string()),
});
@@ -43,18 +46,19 @@ interface RadioProps extends Data {
setValue: (value: S) => void;
}
-const Radio = (props: RadioProps): JSX.Element => {
+export const Radio = (props: RadioProps): JSX.Element => {
const id = useId();
return (
- <Labeled label={props.label} id={id} align="top">
+ <Labeled label={props.label} id={id} align={props.inline ? "left" : "top"}>
<RadioGroup
value={props.value ?? ""}
onValueChange={props.setValue}
+ className={cn(props.inline && "grid-flow-col gap-4")}
aria-label="Radio Group"
>
{props.options.map((option, i) => (
- <div className="flex items-center space-x-3" key={i}>
+ <div className="flex items-center space-x-2" key={i}>
<RadioGroupItem value={option} id={`${id}-${i.toString()}`} />
<Label
htmlFor={`${id}-${i.toString()}`}
diff --git a/marimo/_plugins/ui/_impl/input.py b/marimo/_plugins/ui/_impl/input.py
index 9d1e0d8abc..2b114dd014 100644
--- a/marimo/_plugins/ui/_impl/input.py
+++ b/marimo/_plugins/ui/_impl/input.py
@@ -285,6 +285,7 @@ class radio(UIElement[Optional[str], Any]):
self,
options: Sequence[str] | dict[str, Any],
value: Optional[str] = None,
+ inline: bool = False,
*,
label: str = "",
on_change: Optional[Callable[[Any], None]] = None,
@@ -300,6 +301,7 @@ class radio(UIElement[Optional[str], Any]):
label=label,
args={
"options": list(options.keys()),
+ "inline": inline,
},
on_change=on_change,
)
diff --git a/marimo/_smoke_tests/inputs.py b/marimo/_smoke_tests/inputs.py
index fc8918d6cd..bb543921c5 100644
--- a/marimo/_smoke_tests/inputs.py
+++ b/marimo/_smoke_tests/inputs.py
@@ -1,6 +1,6 @@
import marimo
-__generated_with = "0.1.76"
+__generated_with = "0.1.77"
app = marimo.App()
@@ -42,5 +42,17 @@ def __(mo):
return options,
+def __(mo, options):
+ mo.ui.radio(options, label="Radio buttons")
+ return
+
+
+def __(mo, options):
+ mo.ui.radio(options, label="Radio buttons", inline=True)
+ return
+
+
if __name__ == "__main__":
app.run()