Skip to content

Commit

Permalink
Improve UX of non-interactive slider (#7814)
Browse files Browse the repository at this point in the history
* Fix disabled slider appearance

* add changeset

* tweaks

* add changeset

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
Co-authored-by: pngwn <hello@pngwn.io>
  • Loading branch information
3 people committed Mar 25, 2024
1 parent ff6bf3e commit f7df92f
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 9 deletions.
6 changes: 6 additions & 0 deletions .changeset/weak-shoes-judge.md
@@ -0,0 +1,6 @@
---
"@gradio/slider": minor
"gradio": minor
---

feat:Improve UX of non-interactive slider
35 changes: 29 additions & 6 deletions js/slider/Index.svelte
Expand Up @@ -24,7 +24,7 @@
export let scale: number | null = null;
export let min_width: number | undefined = undefined;
export let minimum: number;
export let maximum: number;
export let maximum = 100;
export let step: number;
export let show_label: boolean;
export let interactive: boolean;
Expand Down Expand Up @@ -61,11 +61,10 @@
numberInput.addEventListener("input", setSliderRange);
}
function setSliderRange(): void {
rangeInput.style.backgroundSize =
((Number(rangeInput.value) - Number(rangeInput.min)) /
(Number(rangeInput.max) - Number(rangeInput.min))) *
100 +
"% 100%";
const dividend = Number(rangeInput.value) - Number(rangeInput.min);
const divisor = Number(rangeInput.max) - Number(rangeInput.min);
const h = divisor === 0 ? 0 : dividend / divisor;
rangeInput.style.backgroundSize = h * 100 + "% 100%";
}
$: disabled = !interactive;
Expand Down Expand Up @@ -130,6 +129,7 @@
display: flex;
justify-content: space-between;
}
input[type="number"] {
display: block;
position: relative;
Expand All @@ -145,6 +145,7 @@
line-height: var(--line-sm);
text-align: center;
}
input:disabled {
-webkit-text-fill-color: var(--body-text-color);
-webkit-opacity: 1;
Expand Down Expand Up @@ -194,6 +195,28 @@
background: var(--neutral-50);
}
input[type="range"][disabled] {
background: var(--body-text-color-subdued);
}
input[type="range"][disabled]::-webkit-slider-thumb {
cursor: not-allowed;
background-color: var(--body-text-color-subdued);
}
input[type="range"][disabled]::-moz-range-track {
cursor: not-allowed;
background-color: var(--body-text-color-subdued);
}
input[type="range"][disabled]::-webkit-slider-thumb:hover {
background-color: var(--body-text-color-subdued);
}
input[type="range"][disabled]::-moz-range-track:hover {
background-color: var(--body-text-color-subdued);
}
input[type="range"]::-webkit-slider-runnable-track {
-webkit-appearance: none;
box-shadow: none;
Expand Down
14 changes: 11 additions & 3 deletions js/slider/Slider.stories.svelte
Expand Up @@ -6,11 +6,11 @@
<Meta title="Components/Slider" component={Slider} />

<Template let:args>
<Slider {...args} />
<Slider interactive={true} {...args} />
</Template>

<Story
name="Slider with min 0 and max 100"
name="Slider with min and max"
args={{
minimum: 0,
maximum: 100
Expand All @@ -32,10 +32,18 @@
/>

<Story
name="Slider with min 0 and max 100 and default value of 50"
name="Slider with min, max, and default value"
args={{
value: 50,
minimum: 0,
maximum: 100
}}
/>

<Story
name="Non-interactive Slider"
args={{
value: 30,
interactive: false
}}
/>

0 comments on commit f7df92f

Please sign in to comment.