Skip to content

← All components

Actions and forms

Slider

Native range input with bindable value and formatted output.

Live example

64%
Use arrow keys for precise adjustments.

Usage

Each example includes the complete adapter-specific parameter reference. Copy it as a starting point, then remove options your use case does not need.

React

tsx
import { Slider } from "@cofob/design-system-react";

/**
 * Complete Slider parameter reference.
 * @param value/defaultValue
 *   type: number; controlled or initial value
 *   default: 0
 *   example: "overview"
 * @param label
 *   type: string | renderable content
 *   required
 *   example: "Accessible label"
 * @param min
 *   type: number
 *   default: 0
 *   example: {min}
 * @param max
 *   type: number
 *   default: 100
 *   example: {max}
 * @param step
 *   type: number
 *   default: 1
 *   example: {step}
 * @param showValue
 *   type: boolean
 *   default: true
 *   example: {showValue}
 * @param hint
 *   type: adapter-specific
 *   default: —
 *   example: {hint}
 * @param formatValue
 *   type: (value: number) => renderable content
 *   default: —
 *   example: {formatValue}
 * @param onValueChange
 *   type: (value: number) => void
 *   default: —
 *   example: {handleValueChange}
 * @param input attributes
 *   type: native element attributes
 *   default: —
 *   example: class / style / aria-* / data-*
 */
export function SliderExample() {
  return (
    <Slider label="Volume" defaultValue={60} />
  );
}

Svelte

svelte
<script lang="ts">
  import { Slider } from "@cofob/design-system-svelte";

  // Complete Slider parameter reference.
  // value/defaultValue
  //   type: number; controlled or initial value
  //   default: 0
  //   example: "overview"
  // label
  //   type: string | renderable content
  //   required
  //   example: "Accessible label"
  // min
  //   type: number
  //   default: 0
  //   example: {min}
  // max
  //   type: number
  //   default: 100
  //   example: {max}
  // step
  //   type: number
  //   default: 1
  //   example: {step}
  // showValue
  //   type: boolean
  //   default: true
  //   example: {showValue}
  // hint
  //   type: adapter-specific
  //   default: —
  //   example: {hint}
  // formatValue
  //   type: (value: number) => renderable content
  //   default: —
  //   example: {formatValue}
  // onValueChange
  //   type: (value: number) => void
  //   default: —
  //   example: {handleValueChange}
  // input attributes
  //   type: native element attributes
  //   default: —
  //   example: class / style / aria-* / data-*
</script>

<Slider label="Volume" bind:value />

HTML

html
<!--
  Complete Slider parameter reference.
  value/defaultValue
    type: number; controlled or initial value
    default: 0
    example: "overview"
  label
    type: string | renderable content
    required
    example: "Accessible label"
  min
    type: number
    default: 0
    example: {min}
  max
    type: number
    default: 100
    example: {max}
  step
    type: number
    default: 1
    example: {step}
  showValue
    type: boolean
    default: true
    example: {showValue}
  hint
    type: adapter-specific
    default: —
    example: {hint}
  formatValue
    type: (value: number) => renderable content
    default: —
    example: {formatValue}
  onValueChange
    type: (value: number) => void
    default: —
    example: {handleValueChange}
  input attributes
    type: native element attributes
    default: —
    example: class / style / aria-* / data-*
-->
<label class="cf-slider">Volume <input class="cf-slider__control" type="range" /></label>

<script type="module">
  import { initDesignSystem } from "@cofob/design-system-css";

  const designSystem = initDesignSystem(document);
  window.addEventListener("pagehide", () => designSystem.destroy(), { once: true });
</script>

Parameters

Adapter differences are explicit. Native element attributes are forwarded in React and Svelte and can be written directly in HTML.

ParameterTypeDefaultAdaptersExampleDescription
value/defaultValuenumber; controlled or initial value0React · Svelte · HTML"overview"Use the first form for controlled state and the second for initial state.
labelrequiredstring | renderable contentrequiredReact · Svelte · HTML"Accessible label"Visible or accessible name, depending on the component.
minnumber0React · Svelte · HTML{min}Lowest allowed range value.
maxnumber100React · Svelte · HTML{max}Highest allowed range or progress value.
stepnumber1React · Svelte · HTML{step}Increment used by the native range input.
showValuebooleantrueReact · Svelte · HTML{showValue}Shows formatted output beside the slider label.
hintadapter-specificReact · Svelte · HTML{hint}Configures hint.
formatValue(value: number) => renderable contentReact · Svelte · HTML{formatValue}Formats visible numeric output without changing the underlying value.
onValueChange(value: number) => voidReact · Svelte · HTML{handleValueChange}Reports a user-driven tab or accordion value change.
input attributesnative element attributesReact · Svelte · HTMLclass / style / aria-* / data-*Forwards native class/style, accessibility, event, and data attributes to the root element.