sp-slider-handle

Overview API

Overview

Section titled Overview

Some advanced slider uses require more than one handle. One example of this is the range slider. <sp-slider> supports multiple handles via the <sp-slider-handle> sub-component, although it would be very rare to ever require more than two handles.

<sp-slider-handle> is unnecessary for single-handle sliders. Always slot two or more <sp-slider-handle> components together. To customize the properties of a single-handle slider (normalization, value, etc), set them on the <sp-slider> element directly.

Usage

Section titled Usage

See it on NPM! How big is this package in your project? Try it on webcomponents.dev

yarn add @spectrum-web-components/slider

Import the side effectful registration of <sp-slider> and <sp-slider-handle> via:

import '@spectrum-web-components/slider/sp-slider.js';
import '@spectrum-web-components/slider/sp-slider-handle.js';

Anatomy

Section titled Anatomy

When two or more sliders are present, the label attribute can be used to identify each handle to assistive technology. For form submission, the name property is a unique identifier for each handle. Each handle will also have its own value based on its position on the slider.

<sp-slider variant="range" step="1" min="0" max="255">
    Output Levels
    <sp-slider-handle
        slot="handle"
        name="min"
        label="Minimum"
        value="5"
    ></sp-slider-handle>
    <sp-slider-handle
        slot="handle"
        name="max"
        label="Maximum"
        value="250"
    ></sp-slider-handle>
</sp-slider>

For slider handles that have the same numeric range, you can specify min="previous" or max="next" to constrain handles by the values of their previous/nextElementSiblings. Keep in mind that the first slider handle with not have a previous handle to be its min and the last slider handle will not have a next handle to be its max.

<sp-slider step="1" min="0" max="255">
    Output Levels
    <sp-slider-handle
        slot="handle"
        name="low"
        label="Low"
        value="5"
        max="next"
    ></sp-slider-handle>
    <sp-slider-handle
        slot="handle"
        name="mid"
        label="Mid"
        value="100"
        min="previous"
        max="next"
    ></sp-slider-handle>
    <sp-slider-handle
        slot="handle"
        name="high"
        label="High"
        value="250"
        min="previous"
    ></sp-slider-handle>
</sp-slider>

Accessibility

Section titled Accessibility

Include a label

Section titled Include a label

For sliders with more than one handle, each slider handle should have a label. A slider without a label is ambiguous and not accessible.

Review the accessibility guidelines for the slider.

API

Attributes and Properties

Section titled Attributes and Properties
Property Attribute Type Default Description defaultValue default-value number Set the default value of the handle. Setting this property will cause the handle to reset to the default value on double click or pressing the `escape` key. disabled disabled boolean false Disable this control. It will not receive focus or events dragging dragging boolean false formatOptions format-options NumberFormatOptions | undefined Enables options for number formatting and internationalization, including those supported by [`Intl.NumberFormatOptions`](https://tc39.es/proposal-unified-intl-numberformat/section6/locales-currencies-tz_proposed_out.html#sec-issanctionedsimpleunitidentifier), as well as polyfills for additional units (e.g. the graphics units of `pixel`, `pixels`, `points`, etc.) that are not supported therein in the format `{ style: "unit", unit: "px" }` . highlight highlight boolean false label label string '' max max number | 'next' | undefined Maximum value to accept; must be less than or equal to `min`. min min number | 'previous' | undefined Minimum value to accept; must be less than or equal to `max`. name name string '' step step number | undefined Level of granularity tabIndex tabIndex number The tab index to apply to this control. See general documentation about the tabindex HTML property value value number By default, the value of a Slider Handle will be halfway between its `min` and `max` values, or the `min` value when `max` is less than `min`.

Events

Section titled Events
Name Type Description change Event An alteration to the value of the element has been committed by the user. input Event The value of the element has changed. sp-slider-handle-ready CustomEvent