Skip to content

Slider

A slider number input component.

Examples

Value: 0

Preact

jsx
const [value, setValue] = useState("");

return (
  <>
    <Slider
      value={value}
      min="0"
      max="100"
      step="0.1"
      onInput={(e) => setValue(e.currentTarget.value)} />
    <div style="margin-top: 0.5em">
      Value: {{value}}
    </div>
  </>
);

Vue.js x Custom Element

html
<script setup>
import { ref } from "vue";
const value = ref(0);
</script>

<phi-number-input
  :value="value"
  min="0"
  max="100"
  step="0.1"
  @input="value = $event.target.value" />
<div style="margin-top: 0.5em">
  Value: {{value}}
</div>

Vanilla JS x CSS

LIMITATION: Track color will not change in Pure-CSS installation.

html
<input
  id="input"
  type="range"
  class="phi-slider"
  min="0"
  max="100"
  step="0.1" />
<div id="value" style="margin-top: 0.5em">
  Value:
</div>

<script>
function onInput (e) {
  const value = e.currentTarget.value;
  document.getElementById("value").innerHTML = `Value: ${value}`;
}
document.getElementById("input").addEventListener("input", onInput);
</script>

Reference

Preact

Properties

PropertyTypeDefaultDescription
valuestring(required)Input value
minnumber|undefinedundefinedMinimum allowed value
maxnumber|undefinedundefinedMaximum allowed value
stepnumber|undefinedundefinedMinimum allowed step
onInputstring => voidfalseA handler function called on input change

Custom Element

Props / Attrs

SlotCategoryTypeDefault
valueProp/Attrnumber|undefinedundefined
minProp/Attrnumber|undefinedundefined
maxProp/Attrnumber|undefinedundefined
stepProp/Attrnumber|undefinedundefined

Events

Following events are confirmed to work as expected. Some other events may also work.

EventDescription
inputEmitted on input change

Pure-CSS

Classes

Class
phi-sliderCore styles