MDUIDocs
Copy llms.txt linkCopy llms-full.txt linkView this page in MarkdownDiscuss this page with ChatGPTDiscuss full project docs with ChatGPT
Preset Colors
Custom Color
Extract from Wallpaper
Please select a wallpaper
Getting Started
AI-Assisted Development
Styles
Integration with Frameworks
Components
Avatar Badge BottomAppBar Button ButtonIcon Card Checkbox Chip CircularProgress Collapse Dialog Divider Dropdown Fab Icon Layout LinearProgress List Menu NavigationBar NavigationDrawer NavigationRail Radio RangeSlider Select SegmentedButton Slider Snackbar Switch Tabs TextField Tooltip TopAppBar
Functions
Libraries

Slider

Sliders allow users to select from a range of values.

Usage

Import the component:

import 'mdui/components/slider.js';

Import the TypeScript type:

import type { Slider } from 'mdui/components/slider.js';

Example:

<mdui-slider></mdui-slider>

Examples

Default Value

The value property lets you read or set the slider's value.

Disabled State

Add the disabled attribute to disable the slider.

Range

Use the min and max attributes to set the slider's minimum and maximum values.

Step Interval

Use the step attribute to set the slider's step interval.

Tickmarks

Add the tickmarks attribute to show tickmarks on the slider.

Hide Value Label

Add the nolabel attribute to hide the value label.

Customize Value Label

The labelFormatter property lets you customize the value label's display format. It takes the slider's current value and returns the text to display.

API

Properties

AttributePropertyReflectTypeDefault
valuevaluenumber0

The value of the slider, which is submitted with form data.

defaultValuenumber0

The default value. The slider resets to this value when the form is reset. JavaScript only.

autofocusautofocusbooleanfalse

Whether the element is focused when the page loads.

tabindextabIndexnumber-

The element's tab order when navigating with the Tab key.

minminnumber0

Specifies the minimum value. Default is 0.

maxmaxnumber100

Specifies the maximum value. Default is 100.

stepstepnumber1

Specifies the step interval. Default is 1.

tickmarkstickmarksbooleanfalse

Adds tickmarks to the slider.

nolabelnolabelbooleanfalse

Hides the value label.

disableddisabledbooleanfalse

Disables the slider.

formformstring-

Associates the slider with a <form> element. Set this to the id of a <form> in the same document. If omitted, the slider uses its parent <form>, if any.

This lets the slider work with any form in the document, not just the one it is nested in.

namenamestring''

Specifies the slider's name, which is submitted with form data.

validityValidityState-

A ValidityState object that represents the element's validity states.

validationMessagestring-

Validation message. Empty string when valid.

labelFormatter(value: number) => string-

Specifies a function to format the tooltip's value. The function receives the slider's value as an argument and should return a string to display in the tooltip.

Methods

NameParametersReturns
click
void

Simulates a mouse click on the element.

focus
  • options: FocusOptions (Optional)
void

Sets focus on the element. An optional object parameter may include a preventScroll property. If preventScroll is set to true, the page will not scroll to bring the focused element into view.

blur
void

Removes focus from the element.

checkValidity
boolean

Checks the validity of the form field. If it is invalid, it triggers an invalid event and returns false. If valid, it returns true.

reportValidity
boolean

Checks the validity of the form field. If it is invalid, it triggers an invalid event, returns false, and displays a validation message. If valid, it returns true.

setCustomValidity
  • message: string
void

Sets a custom error message. If the message is non-empty, the field is considered invalid.

Events

Name
focus

Emitted when the slider gains focus.

blur

Emitted when the slider loses focus.

change

Emitted when the value changes and the slider loses focus.

input

Emitted when the value changes.

invalid

Emitted when the form control's validity is checked and it does not meet the constraints.

CSS Parts

Name
track-inactive

Inactive track.

track-active

Active track.

handle

Slider handle.

label

Value label.

tickmark

Tick mark.

On this page