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.

feat: added disabled prop to checkbox and cleaned code (#4958)

Joaquin Coromina8ba689db06aa
diff --git a/frontend/src/plugins/impl/CheckboxPlugin.tsx b/frontend/src/plugins/impl/CheckboxPlugin.tsx
index b011174d27..40eb743294 100644
--- a/frontend/src/plugins/impl/CheckboxPlugin.tsx
+++ b/frontend/src/plugins/impl/CheckboxPlugin.tsx
@@ -7,17 +7,23 @@ import { Checkbox } from "../../components/ui/checkbox";
import type { CheckedState } from "@radix-ui/react-checkbox";
import { Labeled } from "./common/labeled";
-export class CheckboxPlugin
- implements IPlugin<boolean, { label: string | null }>
-{
+type T = boolean;
+
+interface Data {
+ label: string | null;
+ disabled?: boolean;
+}
+
+export class CheckboxPlugin implements IPlugin<T, Data> {
tagName = "marimo-checkbox";
validator = z.object({
initialValue: z.boolean(),
label: z.string().nullable(),
+ disabled: z.boolean().optional(),
});
- render(props: IPluginProps<boolean, { label: string | null }>): JSX.Element {
+ render(props: IPluginProps<T, Data>): JSX.Element {
return <CheckboxComponent {...props} />;
}
}
@@ -26,7 +32,7 @@ const CheckboxComponent = ({
value,
setValue,
data,
-}: IPluginProps<boolean, { label: string | null }>): JSX.Element => {
+}: IPluginProps<T, Data>): JSX.Element => {
const onClick = (newValue: CheckedState) => {
// unsupported state
if (newValue === "indeterminate") {
@@ -43,6 +49,7 @@ const CheckboxComponent = ({
checked={value}
onCheckedChange={onClick}
id={id}
+ disabled={data.disabled}
/>
</Labeled>
);
diff --git a/marimo/_plugins/ui/_impl/input.py b/marimo/_plugins/ui/_impl/input.py
index 4cca8e0f58..bc1a5ce2bf 100644
--- a/marimo/_plugins/ui/_impl/input.py
+++ b/marimo/_plugins/ui/_impl/input.py
@@ -600,6 +600,7 @@ class checkbox(UIElement[bool, bool]):
label (str, optional): Markdown label for the element. Defaults to "".
on_change (Callable[[bool], None], optional): Optional callback to run when
this element's value changes. Defaults to None.
+ disabled (bool, optional): Whether the checkbox is disabled. Defaults to False.
"""
_name: Final[str] = "marimo-checkbox"
@@ -609,13 +610,16 @@ class checkbox(UIElement[bool, bool]):
value: bool = False,
*,
label: str = "",
+ disabled: bool = False,
on_change: Optional[Callable[[bool], None]] = None,
) -> None:
super().__init__(
component_name=checkbox._name,
initial_value=value,
label=label,
- args={},
+ args={
+ "disabled": disabled,
+ },
on_change=on_change,
)