For AI agents: the complete documentation index is available at https://ifhover.github.io/leaf-ui/v/0.6.0/en/llms.txt, the full documentation bundle is available at https://ifhover.github.io/leaf-ui/v/0.6.0/en/llms-full.txt, and this page is available as Markdown at https://ifhover.github.io/leaf-ui/v/0.6.0/en/components/slider.md.
  • English
  • Slider

    Choose a number or range by sliding.

    Basic usage

    Current value: 35
    basic.tsx
    import type { SliderMark } from '@ifhover/leaf-ui';
    
    import { Form, FormField, Slider, Text } from '@ifhover/leaf-ui';
    
    import { useState } from 'react';
    
    const marks: SliderMark[] = [
      { value: 0, label: 'Low' },
      { value: 50, label: 'Mid' },
      { value: 100, label: 'High' },
    ];
    
    export function SliderBasic() {
      const [value, setValue] = useState(35);
      return (
        <Form layout="vertical">
          <FormField label="Volume">
            <Slider aria-label="Volume" value={value} onChange={setValue} marks={marks} />
          </FormField>
          <Text tone="muted">Current value: {value}</Text>
          <FormField label="Budget">
            <Slider aria-label="Budget" range defaultValue={[20, 70]} marks={marks} />
          </FormField>
          <FormField label="Disabled value">
            <Slider aria-label="Disabled value" defaultValue={45} disabled />
          </FormField>
          <FormField label="Vertical value">
            <Slider aria-label="Vertical value" vertical defaultValue={60} />
          </FormField>
        </Form>
      );
    }
    

    Discrete marks and tooltip

    Discrete marks with formatted tooltip
    capabilities.tsx
    import { Flex, Slider, Space, Text } from '@ifhover/leaf-ui';
    
    export function Capabilities() {
      return (
        <Space direction="vertical" align="stretch">
          <Flex direction="column" gap="sm" align="center">
            <Text>
              {'Discrete marks with formatted tooltip'}
            </Text>
            <Slider
              defaultValue={25}
              step={null}
              marks={[
                { value: 0, label: '0' },
                { value: 25, label: '25' },
                { value: 60, label: '60' },
                { value: 100, label: '100' },
              ]}
              tooltip={{ formatter: (value) => `${value}%` }}
            />
          </Flex>
        </Space>
      );
    }
    

    Slider API

    PropertyTypeDefaultDescription
    minnumber0Bounds and step
    maxnumber100Bounds and step
    stepnumber | null1Bounds and step
    marksreadonly SliderMark[][]Marks
    verticalbooleanfalseUse a vertical layout
    showValuebooleanfalseShow the value above the rail on hover or focus; hidden by default
    onChangeComplete(value: number | readonly [number, number]) => void—After a drag or keyboard change completes
    tooltipboolean | { formatter?: (value: number) => ReactNode }falseShow a thumb tooltip, optionally with custom formatting.
    rangefalse | truefalseRange selection
    valuenumber | readonly [number, number]RequiredMark position
    defaultValuenumber | readonly [number, number][min, max]Controlled / initial value; tuple for ranges
    onChange((value: number) => void) | ((value: [number, number]) => void)—Value changes; callback follows range mode
    disabledbooleanfalseDisable interaction.
    readOnlybooleanfalseLock the value against typing, selection, clearing and removal.
    namestring—Field name in native FormData.
    formstring—ID of the associated native form.

    SliderMark

    PropertyTypeDefaultDescription
    valuenumberRequiredMark position
    labelReactNode—Mark label

    Types

    Import the exported types when defining props or building item lists.

    import type { SliderProps, SliderMark } from '@ifhover/leaf-ui';

    Usage notes

    Arrows change the value, Home / End go to bounds, and Shift + arrows or PageUp / PageDown move ten steps. Range thumbs do not cross. Range mode submits two values under the same name; read them with FormData.getAll. Native form reset is supported.

    SliderMark

    PropertyTypeDefaultDescription
    valuenumber—Required. Controlled value.
    labelReactNode—Visible label or content.