Pips

Here we demonstrate the Slider’s main feature; “notches”, or as I call them; pips. These little markers sit below the Slider by default to mark regular intervals along the Slider’s length.

<script>
  let values = [50];
  let smallValues = [3];
</script>

<RangeSlider pips bind:values />
<RangeSlider pips max={6} bind:values="{smallValues}" />
Pips/Notches/Markers along the Slider
50 | 3

Control the Display

Pip display is controlled by the properties; all, first, last and rest. These properties can be set to true or false to control the display of the pips.

This is also true for labels. See more here

<RangeSlider pips bind:all bind:first bind:last bind:rest />
Controlling the Display
<RangeSlider pips all="pip" />
50

Extreme control with JS

There are scenarios whereby you may wish to only show a certain subset of pips on the slider, for this we should consider using css to hide the pips that we don’t want to show.

<script lang="ts">

  let value = 30;
  let validValues = [10, 30, 90];

  /** 
   * function to generate a random array of values. In reality
   * you would have more reasonable logic to generate the values
   */
  const randomize = () => {
    const count = 3 + Math.floor(Math.random() * 3);
    const valuesArray = new Array(count).fill(0).map((_, i) => Math.floor(Math.random() * 100));
    return valuesArray;
  };

  const setPipValues = () => (validValues = randomize());

  // valid class to display a red handle if invalid
  $: isValid = validValues.includes(value);

  // here we create a <style> tag which will be inserted into the page
  // and for each valid value, we will create a css rule to show the pip
  $: style = `
    <style>
      ${validValues.map((v) => `#testSlider .pip[data-val="${v}"] { display: block; }`).join("")}
    </style>  
  `;
</script>

<!-- insert the dynamic css into the page-->
{@html style}

<!-- wrap the slider so we can style it as invalid -->
<div class:invalid={!isValid}>
  <!-- give the slider an ID so we can style it -->
  <RangeSlider id="testSlider" bind:value float pips all="label" hoverable pipstep={1} />
</div>

<button type="button" on:click={setPipValues}>Randomize</button>
Only show a subset of pips
30
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
30