Skip to content
Focsd homeFocsd homeFocsd
Forms

Slider

A value, or a range with two thumbs, set by dragging or with the keyboard.

  • Tag: focsd-slider
  • Pattern: Slider (single + range)
  • Category: Forms

Example

HTML
<div class="stack">
<focsd-slider label="Volume" value="40" value-text="{value}%"></focsd-slider>
<focsd-slider
label="Price"
range
value-low="20"
value-high="80"
step="5"
value-text="€{value}"></focsd-slider>
</div>

Usage

Import the module once, then use the tag like any HTML element. Every framework below renders the same element; see Frameworks for setup.

<script type="module">
import '@focsd-dev/components/focsd-slider.js';
</script>
<focsd-slider label="Volume" value="40" value-text="{value}%"></focsd-slider>

API

Attributes

AttributePropertyTypeDefault
namenamestring—
disableddisabledbooleanfalse
requiredrequiredbooleanfalse
readonlyreadOnlybooleanfalse
aria-labelhostAriaLabelstring | nullnull
aria-descriptionhostAriaDescriptionstring | nullnull
aria-labelledbyhostAriaLabelledBystring | nullnull
aria-describedbyhostAriaDescribedBystring | nullnull
label-positionlabelPosition'top' | 'start' | 'end' | undefined—
hinthintstring—
errorerror——
warningwarningstring | undefined—
successsuccessstring | undefined—
error-messageerrorMessagestring | undefined—
warning-messagewarningMessagestring | undefined—
warning-patternwarningPatternstring | undefined—
labellabelstring—
valuevaluenumber50
minminnumber0
maxmaxnumber100
stepstepnumber1
rangerangebooleanfalse
value-lowvalueLownumber0
value-highvalueHighnumber100
value-textvalueTextstring—

Methods

MethodDescription
describedByIds()IDs to add to the inner control's aria-describedby: the hint, then the shown message.
checkValidity()True when the value is valid; otherwise fires invalid and returns false, like native.
reportValidity()Like checkValidity(), and also shows the browser's validation message when invalid.
setCustomValidity(message)Set (non-empty) or clear (empty string) a custom validation error, like native controls.
setValidityState(flags, message, anchor)For subclasses: set the validity flags and message. anchor is the element the browser points its message at.
validate()Show (or clear) the error from the control's own checks: required, type, pattern, min, max and the like. Uses error-message, else the browser's localized message. An error the author set (a server error, say) is left as it is.
clearValidation()Clear the error and warning that validate() and warning-pattern showed (a form reset does).
emitValue(commit)For subclasses: fire the value events, as a native control does on a user edit: input (bubbles, composed), then with commit also change (bubbles, stays in its tree).
idrefText(ids)For subclasses: the text of the elements an ID reference list names, resolved in the host's tree (ID references cannot cross a shadow root), joined by spaces.
stepUp(n)Move the value up by n steps, clamped to the range. Fires no events, like native.
stepDown(n)Move the value down by n steps, clamped to the range. Fires no events, like native.

Events

EventDescription
inputFired on every user edit of the value.
changeFired when the user commits a change to the value or state.

CSS parts

Style the inside of the component with ::part(), for example focsd-slider::part(layout).

PartDescription
layoutThe wrapper that places the label, the body and the messages.
bodyThe track, with the hint and message below it.
fillThe fill element.
headerThe label and value row (above the track), or only the value when the label sits beside.
labelThe label element.
outputThe visible value next to the label.
hintThe author's hint.
messageThe shown error, warning or success message.
message-iconThe icon in the message.
announcerThe visually hidden live region.
thumbThe thumb element.
trackThe track element.

Accessibility

  • Do not set readonly here: like a native checkbox or select it has no effect, and HTML skips validation for any custom form control with a readonly attribute. Use disabled, or show the value as text.
  • valueAsNumber, stepUp() and stepDown() work as on a native range input.
  • Each thumb is role="slider" with aria-valuenow/min/max and aria-valuetext from the value-text template.
  • Range thumbs are named "Minimum Price" and "Maximum Price" and cannot cross.
  • Form-associated: participates in FormData, validation, reset and fieldset disabled like a native control.

Keyboard

KeyAction
Arrow keysStep by step
Page Up / DownStep by 10 × step
Home / EndJump to min / max