JGuang

Slider

Slider · Material UI

Preview
npm install @mui/material@9.4.0 @emotion/react@11.14.0 @emotion/styled@11.14.1

Slider

Choose scalar or range values with native marks and accessible labels.

This guide covers Material UI Core with the default Emotion engine; extensions and additional demos are explicitly classified.

Use case and business boundary

Slider may return number or number[]; distinguish live change from committed change and map nonlinear scales explicitly.

Native composition and scope

Slider

Preserve native Material UI composition and types; do not substitute JGuang UI/Base UI/Radix APIs. Example entries are not extra components.

Native installation and initialization

npm install @mui/material@9.4.0 @emotion/react@11.14.0 @emotion/styled@11.14.1

Use native npm and Emotion, not an invented JGuang UI Registry URL. Place examples inside native ThemeProvider; choose CssBaseline or ScopedCssBaseline for the project. Inspect React, existing providers, lockfile and SSR first. Never overwrite files or conceal peer conflicts. This batch verified React 19.2.8; React 18 and below require matching react-is. See the included bilingual setup guide.

Practical native parameters

These selected parameters are not a flattened universal API. Preserve the native declaring owner, slot structure, nullable values and generics.

Owner.propPractical roleDeclaration source
Slider.valueControlled native value; its scalar/array/nullable type is owner-specific.Slider
Slider.minNative Slider minimum value.Slider
Slider.maxBadge visible-count limit or Slider maximum; preserve the owner and units.Slider
Slider.stepNative Slider step; null restricts choice to marks.Slider
Slider.onChangeOwning control's native callback; preserve its exact event/value/nullable signature.Slider
Slider.onChangeCommittedSlider callback after the interaction is committed; distinct from live change.Slider
Slider.getAriaValueTextFormat meaningful spoken Slider value text, including units.Slider

Runnable native examples

Machine keys select example entries, not universal variant props. Native demo JSX/data stay unchanged; JGuang-authored acceptance fixtures are explicitly labelled.

  • Continuous sliders · ContinuousSlider · upstream native demo
  • Sizes · SliderSizes · upstream native demo
  • Discrete sliders · DiscreteSlider · upstream native demo
  • Small steps · DiscreteSliderSteps · upstream native demo
  • Custom marks · DiscreteSliderMarks · upstream native demo
  • Restricted values · DiscreteSliderValues · upstream native demo
  • Label always visible · DiscreteSliderLabel · upstream native demo
  • Range slider · RangeSlider · upstream native demo
  • Minimum distance · MinimumDistanceSlider · upstream native demo
  • Slider with input field · InputSlider · upstream native demo
  • Color · ColorSlider · upstream native demo
  • Customization · CustomizedSlider · upstream native demo
  • Music player · MusicPlayerSlider · upstream native demo
  • Vertical sliders · VerticalSlider · upstream native demo
  • Marks placement · CustomMarks · upstream native demo
  • Removed track · TrackFalseSlider · upstream native demo
  • Inverted track · TrackInvertedSlider · upstream native demo
  • Non-linear scale · NonLinearSlider · upstream native demo

Actual usage example

Unmodified pinned native demo; copy its required local helper files together.

import * as React from 'react';
import Box from '@mui/material/Box';
import Stack from '@mui/material/Stack';
import Slider from '@mui/material/Slider';
import VolumeDown from '@mui/icons-material/VolumeDown';
import VolumeUp from '@mui/icons-material/VolumeUp';

export default function ContinuousSlider() {
  const [value, setValue] = React.useState<number>(30);

  const handleChange = (event: Event, newValue: number) => {
    setValue(newValue);
  };

  return (
    <Box sx={{ width: 200 }}>
      <Stack spacing={2} direction="row" sx={{ alignItems: 'center', mb: 1 }}>
        <VolumeDown />
        <Slider aria-label="Volume" value={value} onChange={handleChange} />
        <VolumeUp />
      </Stack>
      <Slider disabled defaultValue={30} aria-label="Disabled slider" />
    </Box>
  );
}

Example dependency boundaries

react, @mui/material/Box, @mui/material/Stack, @mui/material/Slider, @mui/icons-material/VolumeDown, @mui/icons-material/VolumeUp, @mui/material/styles, @mui/material/Grid, @mui/material/Typography, @mui/material/Input, @mui/material/Tooltip, @mui/material/IconButton, @mui/icons-material/PauseRounded, @mui/icons-material/PlayArrowRounded, @mui/icons-material/FastForwardRounded, @mui/icons-material/FastRewindRounded, @mui/icons-material/VolumeUpRounded, @mui/icons-material/VolumeDownRounded

Direct Icons/System/Utils example imports require their matching 9.4.0 packages. Relative data/helpers are part of the example closure, not extra components. Remote images and simulated operations do not supply a backend.

Pinned upstream API metadata reference

These tables retain the upstream metadata, not a newly inferred generic type system. Conditional generics, inherited props and callback details are defined by the source declarations below. Theme defaults may override metadata defaults.

Slider

import Slider from '@mui/material/Slider';
import { Slider } from '@mui/material';
PropRequiredUpstream metadata type / constraintMetadata default
aria-labelnostring—
aria-labelledbynostring—
aria-valuetextnostring—
classesnoobject—
colorno'primary' | 'secondary' | 'error' | 'info' | 'success' | 'warning' | string'primary'
defaultValuenoArray<number> | number—
disablednoboolfalse
disableSwapnoboolfalse
getAriaLabelnofunc—
getAriaValueTextnofunc—
marksnoArray<{ label?: node, value: number }> | boolfalse
maxnonumber100
minnonumber0
namenostring—
onChangenofunc—
onChangeCommittednofunc—
orientationno'horizontal' | 'vertical''horizontal'
scalenofuncfunction Identity(x) { return x; }
shiftStepnonumber10
sizeno'small' | 'medium' | string'medium'
slotPropsno{ input?: func | object, mark?: func | object, markLabel?: func | object, rail?: func | object, root?: func | object, thumb?: func | object, track?: func | object, valueLabel?: func | { children?: element, className?: string, open?: bool, style?: object, value?: node, valueLabelDisplay?: 'auto' | 'off' | 'on' } }{}
slotsno{ input?: elementType, mark?: elementType, markLabel?: elementType, rail?: elementType, root?: elementType, thumb?: elementType, track?: elementType, valueLabel?: elementType }{}
stepnonumber1
sxnoArray<func | object | bool> | func | object—
tabIndexnonumber—
trackno'inverted' | 'normal' | false'normal'
valuenoArray<number> | number—
valueLabelDisplayno'auto' | 'off' | 'on''off'
valueLabelFormatnofunc | stringfunction Identity(x) { return x; }

Native source declarations

Declarations/imports are extracted from pinned source without flattening unions or external inheritance. Original English comments/types are source reference, not a claim of translated upstream prose. Shared types stay in their native packages.

vendor/src/Slider/Slider.d.ts

import * as React from 'react';

import { SxProps } from '@mui/system';

import { OverridableStringUnion } from '@mui/types';

import { Mark } from './useSlider.types';

import { CreateSlotsAndSlotProps, SlotComponentProps, SlotProps } from '../utils/types';

import { Theme } from '../styles';

import { OverrideProps, OverridableComponent } from '../OverridableComponent';

import SliderValueLabelComponent from './SliderValueLabel';

import { SliderClasses } from './sliderClasses';

export interface SliderPropsColorOverrides {}

export interface SliderPropsSizeOverrides {}

export interface SliderSlots {
  /**
   * The component that renders the root.
   * @default 'span'
   */
  root: React.ElementType;
  /**
   * The component that renders the track.
   * @default 'span'
   */
  track: React.ElementType;
  /**
   * The component that renders the rail.
   * @default 'span'
   */
  rail: React.ElementType;
  /**
   * The component that renders the thumb.
   * @default 'span'
   */
  thumb: React.ElementType;
  /**
   * The component that renders the mark.
   * @default 'span'
   */
  mark: React.ElementType;
  /**
   * The component that renders the mark label.
   * @default 'span'
   */
  markLabel: React.ElementType;
  /**
   * The component that renders the value label.
   * @default SliderValueLabel
   */
  valueLabel: React.ElementType;
  /**
   * The component that renders the input.
   * @default 'input'
   */
  input: React.ElementType;
}

export interface SliderRootSlotPropsOverrides {}

export interface SliderTrackSlotPropsOverrides {}

export interface SliderRailSlotPropsOverrides {}

export interface SliderThumbSlotPropsOverrides {}

export interface SliderMarkSlotPropsOverrides {}

export interface SliderMarkLabelSlotPropsOverrides {}

export interface SliderValueLabelSlotPropsOverrides {}

export interface SliderInputSlotPropsOverrides {}

export type SliderSlotsAndSlotProps = CreateSlotsAndSlotProps<
  SliderSlots,
  {
    /**
     * Props forwarded to the root slot.
     * By default, the available props are based on the span element.
     */
    root: SlotProps<'span', SliderRootSlotPropsOverrides, SliderOwnerState>;
    /**
     * Props forwarded to the track slot.
     * By default, the available props are based on the span element.
     */
    track: SlotProps<'span', SliderTrackSlotPropsOverrides, SliderOwnerState>;
    /**
     * Props forwarded to the rail slot.
     * By default, the available props are based on the span element.
     */
    rail: SlotProps<'span', SliderRailSlotPropsOverrides, SliderOwnerState>;
    /**
     * Props forwarded to the thumb slot.
     * By default, the available props are based on the span element.
     */
    thumb: SlotProps<'span', SliderThumbSlotPropsOverrides, SliderOwnerState>;
    /**
     * Props forwarded to the mark slot.
     * By default, the available props are based on the span element.
     */
    mark: SlotProps<'span', SliderMarkSlotPropsOverrides, SliderOwnerState>;
    /**
     * Props forwarded to the mark label slot.
     * By default, the available props are based on the span element.
     */
    markLabel: SlotProps<'span', SliderMarkLabelSlotPropsOverrides, SliderOwnerState>;
    /**
     * Props forwarded to the value label slot.
     * By default, the available props are based on the [SliderValueLabel](https://mui.com/material-ui/api/slider/) component.
     */
    valueLabel: SlotComponentProps<
      typeof SliderValueLabelComponent,
      SliderValueLabelSlotPropsOverrides,
      SliderOwnerState
    >;
    /**
     * Props forwarded to the input slot.
     * By default, the available props are based on the input element.
     */
    input: SlotProps<'input', SliderInputSlotPropsOverrides, SliderOwnerState>;
  }
>;

export interface SliderOwnerState extends SliderProps {
  dragging: boolean;
  marked: boolean;
  focusedThumbIndex: number;
}

export interface SliderOwnProps<Value extends number | readonly number[]> {
  /**
   * The label of the slider.
   */
  'aria-label'?: string | undefined;
  /**
   * The id of the element containing a label for the slider.
   */
  'aria-labelledby'?: string | undefined;
  /**
   * A string value that provides a user-friendly name for the current value of the slider.
   */
  'aria-valuetext'?: string | undefined;
  /**
   * The color of the component.
   * It supports both default and custom theme colors, which can be added as shown in the
   * [palette customization guide](https://mui.com/material-ui/customization/palette/#custom-colors).
   * @default 'primary'
   */
  color?:
    | OverridableStringUnion<
        'primary' | 'secondary' | 'error' | 'info' | 'success' | 'warning',
        SliderPropsColorOverrides
      >
    | undefined;
  /**
   * Override or extend the styles applied to the component.
   */
  classes?: Partial<SliderClasses> | undefined;
  /**
   * @ignore
   */
  className?: string | undefined;
  /**
   * The default value. Use when the component is not controlled.
   */
  defaultValue?: Value | undefined;
  /**
   * If `true`, the component is disabled.
   * @default false
   */
  disabled?: boolean | undefined;
  /**
   * If `true`, the active thumb doesn't swap when moving pointer over a thumb while dragging another thumb.
   * @default false
   */
  disableSwap?: boolean | undefined;
  /**
   * Accepts a function which returns a string value that provides a user-friendly name for the thumb labels of the slider.
   * This is important for screen reader users.
   * @param {number} index The thumb label's index to format.
   * @returns {string}
   */
  getAriaLabel?: ((index: number) => string) | undefined;
  /**
   * Accepts a function which returns a string value that provides a user-friendly name for the current value of the slider.
   * This is important for screen reader users.
   * @param {number} value The thumb label's value to format.
   * @param {number} index The thumb label's index to format.
   * @returns {string}
   */
  getAriaValueText?: ((value: number, index: number) => string) | undefined;
  /**
   * Marks indicate predetermined values to which the user can move the slider.
   * If `true` the marks are spaced according the value of the `step` prop.
   * If an array, it should contain objects with `value` and an optional `label` keys.
   * @default false
   */
  marks?: boolean | readonly Mark[] | undefined;
  /**
   * The maximum allowed value of the slider.
   * Should not be equal to min.
   * @default 100
   */
  max?: number | undefined;
  /**
   * The minimum allowed value of the slider.
   * Should not be equal to max.
   * @default 0
   */
  min?: number | undefined;
  /**
   * Name attribute of the hidden `input` element.
   */
  name?: string | undefined;
  /**
   * Callback function that is fired when the slider's value changed.
   *
   * @param {Event} event The event source of the callback.
   * You can pull out the new value by accessing `event.target.value` (any).
   * **Warning**: This is a generic event not a change event.
   * @param {Value} value The new value.
   * @param {number} activeThumb Index of the currently moved thumb.
   */
  onChange?: ((event: Event, value: Value, activeThumb: number) => void) | undefined;
  /**
   * Callback function that is fired when the pointer or touch interaction ends.
   *
   * @param {React.SyntheticEvent | Event} event The event source of the callback. **Warning**: This is a generic event not a change event.
   * @param {Value} value The new value.
   */
  onChangeCommitted?: ((event: React.SyntheticEvent | Event, value: Value) => void) | undefined;
  /**
   * The component orientation.
   * @default 'horizontal'
   */
  orientation?: 'horizontal' | 'vertical' | undefined;
  /**
   * A transformation function, to change the scale of the slider.
   * @param {any} x
   * @returns {any}
   * @default function Identity(x) {
   *   return x;
   * }
   */
  scale?: ((value: number) => number) | undefined;
  /**
   * The granularity with which the slider can step through values when using Page Up/Page Down or Shift + Arrow Up/Arrow Down.
   * @default 10
   */
  shiftStep?: number | undefined;
  /**
   * The size of the slider.
   * @default 'medium'
   */
  size?: OverridableStringUnion<'small' | 'medium', SliderPropsSizeOverrides> | undefined;
  /**
   * The granularity with which the slider can step through values. (A "discrete" slider.)
   * The `min` prop serves as the origin for the valid values.
   * We recommend (max - min) to be evenly divisible by the step.
   *
   * When step is `null`, the thumb can only be slid onto marks provided with the `marks` prop.
   * @default 1
   */
  step?: number | null | undefined;
  /**
   * The system prop that allows defining system overrides as well as additional CSS styles.
   */
  sx?: SxProps<Theme> | undefined;
  /**
   * Tab index attribute of the hidden `input` element.
   */
  tabIndex?: number | undefined;
  /**
   * The track presentation:
   *
   * - `normal` the track will render a bar representing the slider value.
   * - `inverted` the track will render a bar representing the remaining slider value.
   * - `false` the track will render without a bar.
   * @default 'normal'
   */
  track?: 'normal' | false | 'inverted' | undefined;
  /**
   * The value of the slider.
   * For ranged sliders, provide an array with two values.
   */
  value?: Value | undefined;
  /**
   * Controls when the value label is displayed:
   *
   * - `auto` the value label will display when the thumb is hovered or focused.
   * - `on` will display persistently.
   * - `off` will never display.
   * @default 'off'
   */
  valueLabelDisplay?: 'on' | 'auto' | 'off' | undefined;
  /**
   * The format function the value label's value.
   *
   * When a function is provided, it should have the following signature:
   *
   * - {number} value The value label's value to format
   * - {number} index The value label's index to format
   * @param {any} x
   * @returns {any}
   * @default function Identity(x) {
   *   return x;
   * }
   */
  valueLabelFormat?: string | ((value: number, index: number) => React.ReactNode) | undefined;
}

export interface SliderTypeMap<
  RootComponent extends React.ElementType = 'span',
  AdditionalProps = {},
  Value extends number | readonly number[] = number | number[],
> {
  props: AdditionalProps & SliderOwnProps<Value> & SliderSlotsAndSlotProps;
  defaultComponent: RootComponent;
}

export type SliderComponent<Value extends number | readonly number[]> = OverridableComponent<
  SliderTypeMap<'span', {}, Value>
>;

export type SliderType = SliderComponent<number> &
  SliderComponent<number[]> &
  SliderComponent<readonly number[]> &
  SliderComponent<number | number[]>;

export interface SliderValueLabelProps extends React.HTMLAttributes<HTMLSpanElement> {
  children: React.ReactElement<unknown>;
  index: number;
  open: boolean;
  value: React.ReactNode;
}

type SliderRootProps = NonNullable<SliderTypeMap['props']['slotProps']>['root'];

type SliderMarkProps = NonNullable<SliderTypeMap['props']['slotProps']>['mark'];

type SliderMarkLabelProps = NonNullable<SliderTypeMap['props']['slotProps']>['markLabel'];

type SliderRailProps = NonNullable<SliderTypeMap['props']['slotProps']>['rail'];

type SliderTrackProps = NonNullable<SliderTypeMap['props']['slotProps']>['track'];

type SliderThumbProps = NonNullable<SliderTypeMap['props']['slotProps']>['thumb'];

export declare const SliderRoot: React.FC<SliderRootProps>;

export declare const SliderMark: React.FC<SliderMarkProps>;

export declare const SliderMarkLabel: React.FC<SliderMarkLabelProps>;

export declare const SliderRail: React.FC<SliderRailProps>;

export declare const SliderTrack: React.FC<SliderTrackProps>;

export declare const SliderThumb: React.FC<SliderThumbProps>;

export declare const SliderValueLabel: React.FC<SliderValueLabelProps>;

declare const Slider: SliderType;

export type SliderProps<
  RootComponent extends React.ElementType = SliderTypeMap['defaultComponent'],
  AdditionalProps = {},
  Value extends number | readonly number[] = number | number[],
> = OverrideProps<SliderTypeMap<RootComponent, AdditionalProps, Value>, RootComponent> & {
  component?: React.ElementType | undefined;
};

Post-install acceptance

Run strict types, production build and real interactions. Check keyboard labels/focus, disabled/error/read-only semantics where natively supported, both themes, narrow screens and reduced motion. Verify callbacks against the real host data; do not declare installation complete from copying a prompt. Initialization fixtures also require server HTML and warning-free hydration.

Source and license

https://github.com/mui/material-ui/tree/809a7717b4c050ba3f69b75300689f07c050a16e

MIT · @mui/material@9.4.0. Vendor originals and license are preserved. Full original upstream prose remains in vendor/docs and is not represented as fully translated.