Is there a way to limit a slider knob to a range?
So Im creating a slider which im limiting to 50. how do i ensure that the knob even when dragged with the mouse won't exceed the value? Thanks in advance!:)
minmaxmaxmaxmaxrangeonInputimport { Signal } from "@preact/signals";
export default function SynchronizedSlider(props: { slider: Signal<number> }) {
return (
<input
class="w-full"
type="range"
min={1} // Set the minimum value of the slider
max={50} // Set the maximum value of the slider to 50
value={props.slider.value}
onInput={(e) => {
const newValue = Number(e.currentTarget.value);
props.slider.value = newValue > 50 ? 50 : newValue; // Ensure the value does not exceed 50
}}
/>
);
}