Zum Hauptinhalt springen Seitenleiste
Auf dieser Seite

Slider

<pc-slider> Seit  1.0.0-alpha.4 Experimentell

Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.

Sliders allow the user to select a single value within a given range.

<pc-slider
    label="Number of users"
    hint="Limit six per team"
    name="value"
    value="3"
    min="0"
    max="6"
    with-markers
    has-tooltip
>
    <span slot="reference">Less</span>
    <span slot="reference">More</span>
</pc-slider>
Code Edit

This component works well with standard <form> elements. Please refer to the form controls page to learn more about form submission and client‐side validation.

Demos

Labels

Use the label attribute to give the slider an accessible label. For labels that contain HTML, use the label slot instead.

Edit

Hint

Add descriptive hint to a slider with the hint attribute. For hints that contain HTML, use the hint slot instead.

Edit

Showing tooltips

Use the has-tooltip attribute to display a tooltip with the current value when the slider is focused or being dragged.

Edit

Setting min, max and step

Use the min and max attributes to define the slider’s range, and the step attribute to control the increment between values.

Edit

Showing markers

Use the with-markers attribute to display visual indicators at each step increment. This works best with sliders that have a smaller range of values.

Edit

Adding references

Use the reference slot to add contextual labels below the slider. References are automatically spaced using justify-content: space-between, making them easy to align with the start, center and end positions.

Edit

If you want to show a reference next to a specific marker, you can add position: absolute to it and set the inset-block-start, inset-block-end, inset-inline-start or inset-inline-end property to a percentage that corresponds to the marker’s position.

Value formatting

Customise how values are displayed in tooltips and announced to screen readers using the valueFormatter property. Set it to a function that accepts a number and returns a formatted string. You can use the Intl.NumberFormat API to format numbers in many ways.

Edit

Range selection

Use the range attribute to enable dual‐thumb selection for choosing a range of values. Set the initial thumb positions with the min-value and max-value attributes.

Edit

For range sliders, the minValue and maxValue properties represent the current positions of the thumbs. When the form is submitted, both values will be included as separate entries with the same name.

const slider = document.querySelector("pc-slider[range]");

console.log(`Minimum value: ${slider.minValue}, maximum value: ${slider.maxValue}`);

slider.minValue = 30;
slider.maxValue = 70;

Vertical

Set the orientation attribute to vertical to create a vertical slider. Vertical sliders automatically centre themselves and fill the available vertical space.

Edit

Range sliders can also be vertical.

Edit

Size

Control the slider’s size using the size attribute.

Edit

Indicator offset

By default, the filled indicator extends from the minimum value to the current position. Use the indicator-offset attribute to change the starting point of this visual indicator.

Edit

Disabled

Use the disabled attribute to disable a slider.

Edit

Eigenschaften

NameBeschreibungReflektiertStandard
validationTargetOverrides the validation target to point to the focusable element.
labelThe slider’s label. If you need to provide HTML in the label, use the label slot instead.
Typ: string
""
hintThe slider’s hint. If you need to display HTML, use the hint slot instead.
Typ: string
""
nameThe name of the slider, submitted as a name/value pair with form data.
Typ: string
minValue
min-value
The minimum value of a range selection. This is only used when the range attribute is set.
Typ: number
0
maxValue
max-value
The maximum value of a range selection. This is only used when the range attribute is set.
Typ: number
50
defaultValue
value
The default value of the slider. Primarily used for resetting the slider.
Typ: number
valueThe current value of the slider, submitted as a name/value pair with form data.
Typ: number
rangeConverts the slider to a range slider with two thumbs.
Typ: boolean
false
isRangeGet if this is a range slider.
Typ: boolean
disabledDisables the slider.
Typ: boolean
false
readonlyMakes the slider a read‐only field.
Typ: boolean
false
orientationThe orientation of the slider.
Typ: "horizontal" | "vertical"
"horizontal"
sizeThe slider’s size.
Typ: "small" | "medium" | "large"
"medium"
indicatorOffset
indicator-offset
The starting value from which to draw the slider’s fill, which is based on its current value.
Typ: number | undefined
minThe minimum value allowed.
Typ: number
0
maxThe maximum value allowed.
Typ: number
100
stepThe granularity the value must adhere to when incrementing and decrementing the value.
Typ: number
1
requiredIndicates if the slider must be interacted with or not.
Typ: boolean
false
autofocusTells the browser to focus the slider when the page loads or a dialog is shown.
Typ: boolean
tooltipDistance
tooltip-distance
The distance of the tooltip from the slider’s thumb.
Typ: number
8
tooltipPlacement
tooltip-placement
The placement of the tooltip in reference to the slider’s thumb.
Typ: "top" | "right" | "bottom" | "left"
"top"
withMarkers
with-markers
Adds markers at each step along the slider.
Typ: boolean
false
hasTooltip
has-tooltip
Adds a tooltip above the thumb when the control has focus or is dragged.
Typ: boolean
false
valueFormatterA custom formatting function to apply to the value. This will be shown in the tooltip and announced by screen readers and is property only.
Typ: (value: number) => string | undefined
updateComplete Ein schreibgeschütztes Promise, das erfüllt ist, sobald die Komponente fertig aktualisiert wurde.

Erfahre mehr über Attribute und Eigenschaften.

Slots

NameBeschreibung
labelThe slider label. Alternatively, you can use the label attribute.
hintText that describes how to use the input. Alternatively, you can use the hint attribute.
referenceOne or more reference labels to show visually below the slider.

Erfahre mehr über die Benutzung von Slots.

Methoden

NameBeschreibungArgumente
focus()Focuses the slider.
blur()Unfocuses the slider (i.e., blurs it).
stepDown()Decreases the slider’s value by step. This is a programmatic change, so change and input events will not be emitted when this is called.
stepUp()Increases the slider’s value by step. This is a programmatic change, so change and input events will not be emitted when this is called.

Erfahre mehr über Methoden.

Events

NameBeschreibungEvent‐Detail
changeEmitted when an alteration to the control’s value is committed by the user.Event
focusEmitted when the control gains focus.FocusEvent
blurEmitted when the control loses focus.FocusEvent
inputEmitted when the control receives input.InputEvent
pc-invalidEmitted when the slider has been checked for validity and its constraints aren’t satisfied.

Erfahre mehr über Events.

Benutzerdefinierte Eigenschaften

NameBeschreibungStandard
--track-sizeThe height or width of the slider's track.0.75em
--marker-widthThe width of each individual marker.0.1875em
--marker-heightThe height of each individual marker.0.1875em
--thumb-widthThe width of the thumb.1.25em
--thumb-heightThe height of the thumb.1.25em

Erfahre mehr über das Anpassen von benutzerdefinierten Eigenschaften.

Parts

NameBeschreibung
labelThe element that contains the slider’s label.
hintThe element that contains the slider’s hint.
sliderThe focusable element with role="slider". Contains the track and reference slot.
trackThe slider’s track.
indicatorThe colored indicator that shows from the start of the slider to the current value.
markersThe container that holds all the markers when with-markers is used.
markerThe individual markers that are shown when with-markers is used.
referencesThe container that holds references that get slotted in.
thumbThe slider’s thumb.
thumb-minThe thumb representing the minimum value in a range slider.
thumb-maxThe thumb representing the maximum value in a range slider.
tooltipThe tooltip, a <pc-tooltip> element.
tooltip-tooltipThe tooltip’s tooltip part.
tooltip-contentThe tooltip’s content part.
tooltip-arrowThe tooltip’s arrow part.

Erfahre mehr über das Anpassen von CSS‐Parts.

Importieren

Wenn du den Autoloader oder den Standard‐Loader nutzt, kannst du diesen Abschnitt überspringen. Falls du „Cherry Picking“ betreibst, kannst du die folgenden Snippets verwenden, um diese Komponente zu importieren.

CDN (Skript‐Tag)CDN (Import)npm (Import)

Um diese Komponente manuell vom CDN zu importieren, kannst du dieses Code‐Snippet kopieren und es in dein HTML einfügen.

<script type="module" src="https://cdn.jsdelivr.net/npm/placer-toolkit@1.0.0-alpha.4/cdn/components/slider/slider.js"></script>

Um diese Komponente manuell vom CDN zu importieren, kannst du dieses Code‐Snippet kopieren und es in deine JavaScript‐Datei einfügen.

import "https://cdn.jsdelivr.net/npm/placer-toolkit@1.0.0-alpha.4/cdn/components/slider/slider.js";

Um diese Komponente manuell von npm zu importieren, kannst du dieses Code‐Snippet kopieren und es in deine JavaScript‐Datei einfügen.

import "placer-toolkit/dist/components/slider/slider.js";

Abhängigkeiten

Diese Komponente importiert automatisch folgende Komponenten:

Wir würden uns freuen, von dir zu hören. Kontaktiere uns einfach bei Fragen oder Anliegen.

Du kannst uns per E‐Mail unter placer.coc.reports+contact@gmail.com erreichen.

Wir freuen uns darauf, von dir zu hören!

Alles klar!
Gefährliche Lande

Ui! Du bist in die gefährlichen Lande von Placer Toolkit geraten. Version 0 ist veraltet und entspricht nicht den EU‐Datenschutzstandards, einschließlich DSGVO.

Willst du die neuesten Kräfte, Sicherheit und Compliance? Bleib bei der aktuellen Version von Placer Toolkit!

Ups! Aufladen!

Unsere Website ist zu 100 % frei von Cookies! Wir legen großen Wert auf deine Privatsphäre und speichern daher keinerlei Cookies oder persönliche Informationen über dich.

Dein Browserverlauf bleibt sauber und deine Daten sind geschützt, ganz im Einklang mit modernen Datenschutzstandards wie der DSGVO. Genieße deinen Besuch ganz ohne digitale Cookies! 🍪🚫

Weitere Informationen findest du in unserer Datenschutzerklärung.

Alles klar!