diff --git a/.changeset/plain-ties-pick.md b/.changeset/plain-ties-pick.md
new file mode 100644
index 0000000000000..202c933dc8e39
--- /dev/null
+++ b/.changeset/plain-ties-pick.md
@@ -0,0 +1,7 @@
+---
+"@gradio/app": minor
+"@gradio/form": minor
+"gradio": minor
+---
+
+feat:Add `step` param to `Number`
diff --git a/gradio/components/number.py b/gradio/components/number.py
index 1b2029a7042ca..4da3d6e970934 100644
--- a/gradio/components/number.py
+++ b/gradio/components/number.py
@@ -60,6 +60,7 @@ def __init__(
precision: int | None = None,
minimum: float | None = None,
maximum: float | None = None,
+ step: float = 1,
**kwargs,
):
"""
@@ -79,10 +80,12 @@ def __init__(
precision: Precision to round input/output to. If set to 0, will round to nearest integer and convert type to int. If None, no rounding happens.
minimum: Minimum value. Only applied when component is used as an input. If a user provides a smaller value, a gr.Error exception is raised by the backend.
maximum: Maximum value. Only applied when component is used as an input. If a user provides a larger value, a gr.Error exception is raised by the backend.
+ step: The interval between allowed numbers in the component. Can be used along with optional parameters `minimum` and `maximum` to create a range of legal values starting from `minimum` and incrementing according to this parameter.
"""
self.precision = precision
self.minimum = minimum
self.maximum = maximum
+ self.step = step
IOComponent.__init__(
self,
@@ -127,6 +130,7 @@ def get_config(self):
"value": self.value,
"minimum": self.minimum,
"maximum": self.maximum,
+ "step": self.step,
"container": self.container,
**IOComponent.get_config(self),
}
@@ -136,6 +140,7 @@ def update(
value: float | Literal[_Keywords.NO_VALUE] | None = _Keywords.NO_VALUE,
minimum: float | None = None,
maximum: float | None = None,
+ step: float = 1,
label: str | None = None,
info: str | None = None,
show_label: bool | None = None,
@@ -156,6 +161,7 @@ def update(
"value": value,
"minimum": minimum,
"maximum": maximum,
+ "step": step,
"interactive": interactive,
"__type__": "update",
}
diff --git a/js/app/src/components/Number/Number.stories.svelte b/js/app/src/components/Number/Number.stories.svelte
new file mode 100644
index 0000000000000..71a0aa1978df7
--- /dev/null
+++ b/js/app/src/components/Number/Number.stories.svelte
@@ -0,0 +1,39 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/js/app/src/components/Number/Number.svelte b/js/app/src/components/Number/Number.svelte
index 0edc44e669c77..74b1845b28bf0 100644
--- a/js/app/src/components/Number/Number.svelte
+++ b/js/app/src/components/Number/Number.svelte
@@ -4,24 +4,33 @@
import StatusTracker from "../StatusTracker/StatusTracker.svelte";
import type { LoadingStatus } from "../StatusTracker/types";
- export let label: string = "Number";
+ export let label = "Number";
export let info: string | undefined = undefined;
- export let elem_id: string = "";
- export let elem_classes: Array = [];
- export let visible: boolean = true;
- export let container: boolean = true;
+ export let elem_id = "";
+ export let elem_classes: string[] = [];
+ export let visible = true;
+ export let container = true;
export let scale: number | null = null;
export let min_width: number | undefined = undefined;
- export let value: number = 0;
+ export let value = 0;
export let show_label: boolean;
export let minimum: number | undefined = undefined;
export let maximum: number | undefined = undefined;
export let loading_status: LoadingStatus;
export let mode: "static" | "dynamic";
- export let value_is_output: boolean = false;
+ export let value_is_output = false;
+ export let step: number | null = null;
-
+
();
- function handle_change() {
+ function handle_change(): void {
if (!isNaN(value) && value !== null) {
dispatch("change", value);
if (!value_is_output) {
@@ -32,7 +33,7 @@
});
$: value, handle_change();
- async function handle_keypress(e: KeyboardEvent) {
+ async function handle_keypress(e: KeyboardEvent): Promise {
await tick();
if (e.key === "Enter") {
e.preventDefault();
@@ -40,12 +41,11 @@
}
}
- function handle_blur(e: FocusEvent) {
+ function handle_blur(e: FocusEvent): void {
dispatch("blur");
}
-