🔧 AI Nachrichten Major AI platforms go down in unprecedented simultaneous outage(03.09.2026 um 17:34 Uhr)
🔧 AI Nachrichten ChatGPT, Claude, and Grok Down? Users Report Widespread Outages(03.09.2026 um 19:14 Uhr)
🔧 AI Nachrichten OpenAI Launches GPT-6 Astra, Says We May Have Entered the AGI Era(03.09.2026 um 22:08 Uhr)
🔧 AI Nachrichten Claude Comes to CarPlay as Fifth Major AI Chatbot App(05.09.2026 um 05:31 Uhr)
🔧 AI Nachrichten OpenAI’s GPT-6 Astra Is AGI, Says NVIDIA CEO Jensen Huang(07.09.2026 um 06:31 Uhr)
🔧 AI Nachrichten Blame AI companies for Mac mini and Mac Studio shortage(31.08.2026 um 10:32 Uhr)
🔧 AI Nachrichten Major AI platforms go down in unprecedented simultaneous outage(03.09.2026 um 17:34 Uhr)
🔧 AI Nachrichten ChatGPT, Claude, and Grok Down? Users Report Widespread Outages(03.09.2026 um 19:14 Uhr)
🔧 AI Nachrichten OpenAI Launches GPT-6 Astra, Says We May Have Entered the AGI Era(03.09.2026 um 22:08 Uhr)
🔧 AI Nachrichten Claude Comes to CarPlay as Fifth Major AI Chatbot App(05.09.2026 um 05:31 Uhr)
🔧 AI Nachrichten OpenAI’s GPT-6 Astra Is AGI, Says NVIDIA CEO Jensen Huang(07.09.2026 um 06:31 Uhr)
🔧 AI Nachrichten Blame AI companies for Mac mini and Mac Studio shortage(31.08.2026 um 10:32 Uhr)

🔧 Programmierung 🕛 kürzlich 5 Min Lesezeit
0

Let’s create numeric range input with attached scale

↗ Quelle (dev.to)
🗣️ Stimme:
📑 Inhaltsübersicht

HTMLInputElement of type






React Component



Our goal is to render <input type="range" /> with some additional tags added to it. Here is basic implementation.




CODE
import type { ChangeEvent } from 'react';

type Props = {
/** Provide an optional label to the range input */
label?: string;
/** Set a default value. Can be value for controlled mode */
defaultValue?: number;
/** Set a minimum available value in the range */
min?: number;
/** Set a maximum available value in the range */
max?: number;
/** Set a step increment/decrement amount */
step?: number;
/**
* Configure scale below range track
* Warning! See below
*/

scale?: { label: string; value: number }[];
/** Callback to capture changes */
onChange?: (event: ChangeEvent<HTMLInputElement>) => void;
/** Disable the input */
disabled?: boolean;
};

export const RangeInput: FC<Props> = ({
max = 100,
min = 0,
step,
defaultValue = 0,
onChange,
disabled
}) => {
const handleChange = useCallback(
(event: ChangeEvent<HTMLInputElement>) => {
onChange?.(event);
},
[onChange],
);
return (
<input
className={classes.input}
type="range"
value={value}
min={min}
max={max}
step={step}
onChange={handleChange}
disabled={disabled}
defaultValue={defaultValue}
/>
);
};









Styling input



All modern browsers allow us to style range input. But we still have to use vendor prefixes. -webkit-slider-runnable-track and -webkit-slider-thumb for Blink/WebKit; -moz-range-track and -moz-range-thumb for Mozilla based browsers.



We are going to use CSS variables to store information about design we choose.




CODE

.input {
--track-height: 4px;
--slider-size: 18px;
--track-color: plum;
--track-color-active: mediumPurple;
--thumb-color: seaGreen;
--thumb-color-active: chartreuse;

/* we need this to reset browser built-in styles */
all: unset;
}






Here is how to style the track of the input.




CODE
.input::-moz-range-track {
background: var(--track-color);
height: var(--track-height);
border-radius: 6px;
cursor: col-resize;
}

.input::-webkit-slider-thumb {
background: var(--track-color);
height: var(--track-height);
border-radius: 6px;
cursor: col-resize;
}






We have to repeat two times because stacking selectors (.input::-moz-range-track, .input::-webkit-slider-thumb) doesn't work in this case.



Here are thumb styles:




CODE
.input::-moz-range-thumb {
background-color: var(--thumb-color);
border: none;
cursor: grab;
height: var(--slider-size);
width: var(--slider-size);
}

.input::-webkit-slider-thumb {
/* same styles as above and additional to fix Chrome/Safari issues */
appearance: none;
border-radius: 50%;
margin-top: calc(var(--track-height) / 2 - var(--slider-size) / 2);
}






Now we need to style different input states.




CODE
/* Disable unwanted outline when focused */
.input:focus-visible {
outline: none;
}

/* Disabled state */
.input:disabled::-moz-range-thumb {
background-color: var(--disabled-color);
cursor: not-allowed;
}

.input:disabled::-webkit-slider-thumb {
/* same as above */
}

.input:disabled::-moz-range-track {
background: var(--disabled-color);
cursor: not-allowed;
}

.input:disabled::-webkit-slider-runnable-track {
/* same as above */
}

/* Hover state */
.input:hover::-moz-range-track {
background: var(--track-color-active);
}

.input:hover::-webkit-slider-runnable-track {
/* same as above */
}


/* Active state */
.input:active:not(:disabled)::-moz-range-thumb {
cursor: grabbing;
}

.input:active:not(:disabled)::-webkit-slider-thumb {
/* same as above */
}

.input:active:not(:disabled):focus::-moz-range-thumb{
background-color: var(--thumb-color-active);
}

.input:active:not(:disabled):focus::-webkit-slider-thumb {
/* same as above */
}

.input:active:not(:disabled):focus::-moz-range-track {
background: var(--track-color-active);
}

.input:active:not(:disabled):focus::-webkit-slider-runnable-track {
/* same as above */
}









Selectors explained



.input:active:not(:disabled):focus::-moz-range-thumb consists of:




  • .input - CSS class name.


  • :active - CSS pseudo-class matching elements being interacted with.


  • :not(:disabled) - CSS pseudo-class which represents elements that do not match provided list of selectors. Not disabled in this case.


  • :focus - CSS pseudo-class matching element having browser focus.


  • ::-moz-range-thumb - CSS pseudo-element matching draggable thumb for Mozilla browsers.







Add input label and output



Now we are going to implement accessible clickable label and dynamic output element to show current value.




CODE
export const RangeInput: FC<Props> = ({
label,
max = 100,
min = 0,
step,
defaultValue = 0,
onChange,
disabled,
}) => {
// Create unique id
const id = useId();
/* The state is required to be able to display an input result */
const [value, setValue] = useState(defaultValue);
const handleChange = useCallback(
(event: ChangeEvent<HTMLInputElement>) => {
setValue(event.target.valueAsNumber);
onChange?.(event);
},
[onChange],
);
return (
<div className={classes.wrapper}>
{/* Conditionally render label element */}
{label && (
{/* We use input id to connect the label */}
<label htmlFor={id} className={classes.label}>
{label}
</label>
)}

<input
type="range"
id={id}
value={value}
min={min}
max={max}
step={step}
onChange={handleChange}
disabled={disabled}
/>

{/* We use input id to connect the output */}
<output name="result" htmlFor={id}>
{value}
</output>
</div>
);
};









Add scale




Warning: This feature is not supported by Safari browser!




Mozilla and Chromium-based browsers allow us to attach scale with tick marks into a range control with the help of <datalist> element. Each tick mark is represented by an <option>, where the value attribute corresponds to the specific range value at which the mark should appear.




CODE
type ScaleMark = {
/** Range value to attach mark to */
value: number;
/** Label to display at the provided mark */
label: string;
};

export type Props = {
//...
/** Provide an optional array of scale marks to display below range track */
scale?: ScaleMark[];
};

export const RangeInput: FC<Props> = ({
//...
scale,
}) => {
const id = useId();
// Derivative id for scale element
const scaleId = `${id}-scale`;
// ...
return (
<div className={classes.wrapper}>
{/*...*/}
<div className={classes.inputWrapper}>
<input
//...
// Here we provide scale element id
list={scale && scaleId}
/>
{/* Conditionally render scale element*/}
{scale && (
<datalist id={scaleId}>
{scale.map(({ label, value }) => (
<option key={value} value={value} label={label} />
))}
</datalist>
)}
</div>

{/*...*/}
</div>
);
};






Here are styles for scale:




CODE
.scale {
display: flex;
flex-direction: row;
/* Required to distribute marks */
justify-content: space-between;
width: 100%;
}

.scale option {
padding: 6px 0 0 0;
font-size: 16px;
user-select: none;
cursor: default;
}










Working demo



Here is working example of range input.



Happy coding!





Vollständiger Original-Bericht
Ausführliche Details, Code-Beispiele & Hersteller-Stellungnahme auf dev.to.
↗ Original-Artikel auf dev.to lesen
Wie bewertest du diesen Beitrag?
1 Klick Feedback
Teilen mit Netzwerk & Team:

Community-Analysen & Experten-Meinungen 0

Verfasse deine eigene Analyse, teile Workarounds oder diskutiere diesen Vorfall im Blog.
Noch keine Community-Analyse verfasst. Markiere einen Textabschnitt oder klicke oben auf Eigene Analyse verfassen“!
Community Pulse: Relevanz-Einschätzung
1 Klick Experten-Votum
🔴 Akute Relevanz 0%
🟡 In Evaluierung 0%
🟢 Keine Auswirkung 0%
Spannende Innovation 0%
Verwandte Story-Cluster & Quellen (Vektor-KI)
Port 8095 Engine
3 Quellen
GPT-6 Astra Release Today? OpenAI’s Next Major AI Model Is Almost Here
1 Quelle
Apple accuses OpenAI of destroying evidence as trade-secrets fight intensifies
1 Quelle
Major AI platforms go down in unprecedented simultaneous outage
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Let’s create numeric range input with attached scale

Thematisch verwandte Begriffe: Lets, create, numeric, range · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...