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 slider (#4890)

Joaquin Corominaae9156b7b284
diff --git a/frontend/src/components/ui/slider.tsx b/frontend/src/components/ui/slider.tsx
index c602edc887..fe1d1ba6e3 100644
--- a/frontend/src/components/ui/slider.tsx
+++ b/frontend/src/components/ui/slider.tsx
@@ -28,6 +28,7 @@ const Slider = React.forwardRef<
"relative flex touch-none select-none hover:cursor-pointer",
"data-[orientation=horizontal]:w-full data-[orientation=horizontal]:items-center",
"data-[orientation=vertical]:h-full data-[orientation=vertical]:justify-center",
+ "data-[disabled]:cursor-not-allowed",
className,
)}
{...props}
@@ -46,6 +47,7 @@ const Slider = React.forwardRef<
"absolute bg-blue-500 dark:bg-primary",
"data-[orientation=horizontal]:h-full",
"data-[orientation=vertical]:w-full",
+ "data-[disabled]:opacity-50",
)}
/>
</SliderPrimitive.Track>
@@ -54,7 +56,7 @@ const Slider = React.forwardRef<
<TooltipTrigger asChild={true}>
<SliderPrimitive.Thumb
data-testid="thumb"
- className="block h-4 w-4 rounded-full shadow-xsSolid border border-blue-500 dark:border-primary dark:bg-accent bg-white hover:bg-blue-300 focus:bg-blue-300 transition-colors focus-visible:outline-none disabled:pointer-events-none disabled:opacity-50"
+ className="block h-4 w-4 rounded-full shadow-xsSolid border border-blue-500 dark:border-primary dark:bg-accent bg-white hover:bg-blue-300 focus:bg-blue-300 transition-colors focus-visible:outline-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50"
onFocus={openActions.setTrue}
onBlur={openActions.setFalse}
onMouseEnter={openActions.setTrue}
diff --git a/frontend/src/plugins/impl/SliderPlugin.tsx b/frontend/src/plugins/impl/SliderPlugin.tsx
index 9f9a4811eb..f0752d4983 100644
--- a/frontend/src/plugins/impl/SliderPlugin.tsx
+++ b/frontend/src/plugins/impl/SliderPlugin.tsx
@@ -22,6 +22,7 @@ interface Data {
showValue: boolean;
fullWidth: boolean;
includeInput: boolean;
+ disabled?: boolean;
}
export class SliderPlugin implements IPlugin<T, Data> {
@@ -39,6 +40,7 @@ export class SliderPlugin implements IPlugin<T, Data> {
showValue: z.boolean().default(false),
fullWidth: z.boolean().default(false),
includeInput: z.boolean().default(false),
+ disabled: z.boolean().optional(),
});
render(props: IPluginProps<T, Data>): JSX.Element {
@@ -81,6 +83,7 @@ const SliderComponent = ({
fullWidth,
valueMap,
includeInput,
+ disabled,
}: SliderProps): JSX.Element => {
const id = useId();
@@ -132,6 +135,7 @@ const SliderComponent = ({
}
}}
valueMap={valueMap} // Pass valueMap to Slider
+ disabled={disabled}
/>
{showValue && (
<div className="text-xs text-muted-foreground min-w-[16px]">
@@ -152,6 +156,7 @@ const SliderComponent = ({
step={step}
className="w-24"
aria-label={`${label || "Slider"} value input`}
+ isDisabled={disabled}
/>
)}
</div>
diff --git a/marimo/_plugins/ui/_impl/input.py b/marimo/_plugins/ui/_impl/input.py
index c7a791e2ed..c4037cdb78 100644
--- a/marimo/_plugins/ui/_impl/input.py
+++ b/marimo/_plugins/ui/_impl/input.py
@@ -185,6 +185,7 @@ class slider(UIElement[Numeric, Numeric]):
value (Optional[Numeric]): Default value.
debounce (bool): Whether to debounce the slider to only send the value
on mouse-up or drag-end. Defaults to False.
+ disabled (bool, optional): Whether the slider is disabled. Defaults to False.
orientation (Literal["horizontal", "vertical"]): The orientation of the
slider, either "horizontal" or "vertical". Defaults to "horizontal".
show_value (bool): Whether to display the current value of the slider.
@@ -222,6 +223,7 @@ class slider(UIElement[Numeric, Numeric]):
step: Optional[Numeric] = None,
value: Optional[Numeric] = None,
debounce: bool = False,
+ disabled: bool = False,
orientation: Literal["horizontal", "vertical"] = "horizontal",
show_value: bool = False,
include_input: bool = False,
@@ -293,6 +295,7 @@ class slider(UIElement[Numeric, Numeric]):
"step": 1,
"steps": steps,
"debounce": debounce,
+ "disabled": disabled,
"orientation": orientation,
"show-value": show_value,
"include-input": include_input,
@@ -335,6 +338,7 @@ class slider(UIElement[Numeric, Numeric]):
"step": step if step is not None else None,
"steps": [],
"debounce": debounce,
+ "disabled": disabled,
"orientation": orientation,
"show-value": show_value,
"include-input": include_input,
diff --git a/tests/_server/export/snapshots/notebook_with_outputs.ipynb.txt b/tests/_server/export/snapshots/notebook_with_outputs.ipynb.txt
index b89012b614..725dfc2d36 100644
--- a/tests/_server/export/snapshots/notebook_with_outputs.ipynb.txt
+++ b/tests/_server/export/snapshots/notebook_with_outputs.ipynb.txt
@@ -139,7 +139,7 @@
{
"data": {
"text/markdown": [
- "&lt;marimo-slider data-initial-value=&#x27;0&#x27; data-label=&#x27;null&#x27; data-start=&#x27;0&#x27; data-stop=&#x27;10&#x27; data-steps=&#x27;[]&#x27; data-debounce=&#x27;false&#x27; data-orientation=&#x27;&amp;quot;horizontal&amp;quot;&#x27; data-show-value=&#x27;false&#x27; data-include-input=&#x27;false&#x27; data-full-width=&#x27;false&#x27;&gt;&lt;/marimo-slider&gt;"
+ "&lt;marimo-slider data-initial-value=&#x27;0&#x27; data-label=&#x27;null&#x27; data-start=&#x27;0&#x27; data-stop=&#x27;10&#x27; data-steps=&#x27;[]&#x27; data-debounce=&#x27;false&#x27; data-disabled=&#x27;false&#x27; data-orientation=&#x27;&amp;quot;horizontal&amp;quot;&#x27; data-show-value=&#x27;false&#x27; data-include-input=&#x27;false&#x27; data-full-width=&#x27;false&#x27;&gt;&lt;/marimo-slider&gt;"
]
},
"metadata": {},