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 input field to ui slider (#4870)

Joaquin Coromina265c6215b415
diff --git a/frontend/src/plugins/impl/SliderPlugin.tsx b/frontend/src/plugins/impl/SliderPlugin.tsx
index 4baa2b9202..9f9a4811eb 100644
--- a/frontend/src/plugins/impl/SliderPlugin.tsx
+++ b/frontend/src/plugins/impl/SliderPlugin.tsx
@@ -7,6 +7,7 @@ import { Slider } from "../../components/ui/slider";
import { Labeled } from "./common/labeled";
import { cn } from "@/utils/cn";
import { prettyScientificNumber } from "@/utils/numbers";
+import { NumberField } from "@/components/ui/number-field";
type T = number;
@@ -20,6 +21,7 @@ interface Data {
orientation: "horizontal" | "vertical";
showValue: boolean;
fullWidth: boolean;
+ includeInput: boolean;
}
export class SliderPlugin implements IPlugin<T, Data> {
@@ -36,6 +38,7 @@ export class SliderPlugin implements IPlugin<T, Data> {
orientation: z.enum(["horizontal", "vertical"]).default("horizontal"),
showValue: z.boolean().default(false),
fullWidth: z.boolean().default(false),
+ includeInput: z.boolean().default(false),
});
render(props: IPluginProps<T, Data>): JSX.Element {
@@ -77,6 +80,7 @@ const SliderComponent = ({
showValue,
fullWidth,
valueMap,
+ includeInput,
}: SliderProps): JSX.Element => {
const id = useId();
@@ -134,6 +138,22 @@ const SliderComponent = ({
{prettyScientificNumber(valueMap(internalValue))}
</div>
)}
+ {includeInput && (
+ <NumberField
+ value={valueMap(internalValue)}
+ onChange={(nextValue) => {
+ setInternalValue(nextValue);
+ if (!debounce) {
+ setValue(nextValue);
+ }
+ }}
+ minValue={start}
+ maxValue={stop}
+ step={step}
+ className="w-24"
+ aria-label={`${label || "Slider"} value input`}
+ />
+ )}
</div>
</Labeled>
);
diff --git a/marimo/_plugins/ui/_impl/input.py b/marimo/_plugins/ui/_impl/input.py
index e232ecfe70..c7a791e2ed 100644
--- a/marimo/_plugins/ui/_impl/input.py
+++ b/marimo/_plugins/ui/_impl/input.py
@@ -189,6 +189,8 @@ class slider(UIElement[Numeric, Numeric]):
slider, either "horizontal" or "vertical". Defaults to "horizontal".
show_value (bool): Whether to display the current value of the slider.
Defaults to False.
+ include_input (bool): Whether to display an editable input with the current
+ value of the slider. Defaults to False.
steps (Optional[Sequence[Numeric]]): List of steps to customize the
slider, mutually exclusive with `start`, `stop`, and `step`.
label (str): Markdown label for the element. Defaults to an empty string.
@@ -222,6 +224,7 @@ class slider(UIElement[Numeric, Numeric]):
debounce: bool = False,
orientation: Literal["horizontal", "vertical"] = "horizontal",
show_value: bool = False,
+ include_input: bool = False,
steps: Optional[Sequence[Numeric]] = None,
*,
label: str = "",
@@ -292,6 +295,7 @@ class slider(UIElement[Numeric, Numeric]):
"debounce": debounce,
"orientation": orientation,
"show-value": show_value,
+ "include-input": include_input,
"full-width": full_width,
},
on_change=on_change,
@@ -333,6 +337,7 @@ class slider(UIElement[Numeric, Numeric]):
"debounce": debounce,
"orientation": orientation,
"show-value": show_value,
+ "include-input": include_input,
"full-width": full_width,
},
on_change=on_change,