The slider
input is an advanced and highly configurable version of the native HTML range
input. Some notable additions compared to the standard range
input are:
if you're familar with using the native HTML range
input you'll find than many of the existing props you're familiar with work as expected with the slider
input.
Even in its simplest form the slider
input has a few tricks up its sleeve. Just like the native range
input you can use your arrow keys to adjust the input value when it is focused — but with the slider
input you can hold the shift
key to increment by 10x and your system's modifer key (command
or ctrl
) to jump to the min / max values.
Whenever you have a handle focused on a slider
input you can type a value on your keyboard and after a slight debounce your slider
handle will be set to the value you provided — or the closest available match.
To render two value handles on a slider
input supply an array as the input's value. Control handles can be dragged through each other and your resulting array value will always be returned sorted in order from smallest to largest.
Using the maxHandleInner
(default) and minHandleInner
slots you can customize the appearance of your slider
handles. The maxHandleInner
slot is used for single-value slider
inputs.
By default slider
tooltips show on hover and when a selection handle is being dragged. You can force tooltips into an on or off state by using the tooltip
prop and providing a boolean value.
By providing a function to the tooltip-format
prop you can customize the value of your slider
tooltip. Your tooltip-format
function will be provided two arguments:
value
: The current value that would be displayed in the tooltip by default.
handle
: The current handle being affected by the funciton. Either min
or max
.
By using the tooltip-format
prop you can introduce variety to your slider
inputs — especially when combined with FormKit's section-key class prop system.
Sometimes a range-style input is more useful for users if they're also able to directly enter numeric values in linked fields. You can reveal number
inputs that are bound to the values of the slider
range handles by setting the show-input
prop to true
.
The linked number
inputs are FormKit inputs. You can apply props to them using the provided props:
input-attrs
: will bind your provided object to both the min
and max
inputs.min-input-attrs
: Object to bind to the linked min
input.max-input-attrs
: Object to bind to the linked max
input.The slider
input supports the rendering of marks on the input's track. By setting the marks
property to true
marks will be rendered at every steps
interval.
You can enable labels for your marks by setting the mark-labels
prop to true
.
By supplying an array of objects to the marks
prop instead of a boolean you can place arbirtary marks on the slider's track. Mark objects shold have the folloing properties:
at
: The position (value) on the track where the mark should render.label
: The label to render for the mark if the mark-labels
prop is enabled.class
: A string of classes to apply to the mark element.labelClasses
: A string of classes to apply to the mark label element.When supplying custom marks you may want to force the selection to snap to the provided marks. This can be achieved with the snap-to-marks
prop. When snap-to-marks
is true
keyboard events will jump to the next closest mark and entered values through keyboard or linked inputs will snap to the nearest available mark.
You can apply custom classes to your marks and mark labels by using the class
and labelClasses
properties on your mark objects.
By default the slider
input scales values linearly across its entire range. However, you can use the provided scaling-function
or intervals
props to change this behavior.
The scaling-function
prop accepts 3 values:
linear
— this is the default behaviorlog
which will apply a logarithmic scaling function to your slider
forward
and reverse
which will apply your own scaling logic.The intervals
prop accepts an array of object where each object defines an interval range on the slider
. Each obect contains:
value
: The point on the slider
at which the interval beginsstep
: The step size that should be used within the intervalYour last interval will cover the range extending from your specified value
to the max
prop value on your slider
. If your lowest interval does not begin at the minimum possible value of your slider
then an interval covering the range from your min
slider prop to your first interval will be created for you. Its step
value will be the value of the step
prop on your slider
input.
It's important to note that the visual representation of intervals on a slider
track is based on the total number of possible steps within a given interval and not the interval's raw numeric value.
You can render a bar chart above the slider with arbitrary values by suppling an array to the chart
prop. The chart
array has a similar structure to the marks
array. Each nested object should contain:
at
: The position (value) on the track where the bar for the chart should render.value
: A numeric value that will be used to calculate the relative height of the bar in the chart.The slider
input will iterate over you chart
array and determine the largest value
contained in the array, and then divide all other values by that largest value to determine the relative heights for rendering the bars of the chart.
By combining the provided props for the slider
component you can create a robust input to cover a variety of usecases. Here is an example for a price-range slider.
Prop | Type | Default | Description |
---|---|---|---|
chart | array | none | An array of objects containing at and value keys. Renders a relative-height bar-chart above the slider track. |
input-attrs | object | {} | Applies custom attributes to the nested linked FormKit inputs for both min and max values. |
intervals | array | none | An array of interval values consisting of value and step used to define differing scaling for different sections of a slider track. |
marks | boolean || array | false | When true , renders marks on the track at every step value. When an Array of objects with at and label keys, renders a mark on the track at every object's at value. |
mark-labels | boolean | false | Enables rendering of labels belowe marks on track |
max | number | 100 | The maximum possible value of the slider range. |
max-input-attrs | object | {} | Applies custom attributes to the nested linked FormKit input for the max value. |
min | number | 0 | The minimum possible value of the slider range. |
min-input-attrs | object | {} | Applies custom attributes to the nested linked FormKit input for the min value. |
prefix | string | none | Characters that will always appear at the beginning of the input. |
scaling-function | string || object | linear | Defines scaling behavior for values on the rendered slider track using either a preset value string or a set of custom functions. |
show-input | boolean | false | Renders FormKit type="number" input(s) that are linked to the slider's value(s) |
snap-to-marks | boolean | false | When enabled, forces user selection to snap to marks |
step | number | 1 | The minimum value at which the slider value can increment / decrement. |
suffix | string | none | Characters that will always appear at the end of the input. |
tooltip | boolean | none | When set with a boolean value, forces the display of the slider's handle tooltip(s). |
tooltip-format | function | none | A function that is provided the value and handle for each slider handle which should return a string . |
Show Universal props | |||
config | Object | {} | Configuration options to provide to the input’s node and any descendent node of this input. |
delay | Number | 20 | Number of milliseconds to debounce an input’s value before the commit hook is dispatched. |
dirtyBehavior | string | touched | Determines how the "dirty" flag of this input is set. Can be set to touched or compare — touched (the default) is more performant, but will not detect when the form is once again matching its initial state. |
errors | Array | [] | Array of strings to show as error messages on this field. |
help | String | '' | Text for help text associated with the input. |
id | String | input_{n} | The unique id of the input. Providing an id also allows the input’s node to be globally accessed. |
ignore | Boolean | false | Prevents an input from being included in any parent (group, list, form etc). Useful when using inputs for UI instead of actual values. |
index | Number | undefined | Allows an input to be inserted at the given index if the parent is a list. If the input’s value is undefined, it inherits the value from that index position. If it has a value it inserts it into the lists’s values at the given index. |
label | String | '' | Text for the label element associated with the input. |
name | String | input_{n} | The name of the input as identified in the data object. This should be unique within a group of fields. |
parent | FormKitNode | contextual | By default the parent is a wrapping group, list or form — but this props allows explicit assignment of the parent node. |
prefix-icon | String | '' | Specifies an icon to put in the prefixIcon section. |
preserve | boolean | false | Preserves the value of the input on a parent group, list, or form when the input unmounts. |
preserve-errors | boolean | false | By default errors set on inputs using setErrors are automatically cleared on input, setting this prop to true maintains the error until it is explicitly cleared. |
sections-schema | Object | {} | An object of section keys and schema partial values, where each schema partial is applied to the respective section. |
suffix-icon | String | '' | Specifies an icon to put in the suffixIcon section. |
type | String | text | The type of input to render from the library. |
validation | String, Array | [] | The validation rules to be applied to the input. |
validation-visibility | String | blur | Determines when to show an input's failing validation rules. Valid values are blur , dirty , and live . |
validation-label | String | {label prop} | Determines what label to use in validation error messages, by default it uses the label prop if available, otherwise it uses the name prop. |
validation-rules | Object | {} | Additional custom validation rules to make available to the validation prop. |
value | Any | undefined | Seeds the initial value of an input and/or its children. Not reactive. Can seed entire groups (forms) and lists.. |
You can target a specific section of an input using that section's "key", allowing you to modify that section's classes, HTML (via :sections-schema
, or content (via slots)). Read more about sections here.
Section-key | Description |
---|---|
chart | A container for the chart bar elements. |
chartBar | An individual bar for the chart element. |
fill | The fill for the selected range on the slider input. |
handleMax | The maximum value selection handle. This is the default handle for single-value slider inputs. |
handleMin | The minimum value selection handle. |
handles | A container for the track selection handles |
linkedValues | A wrapper for the linked inputs for the slider’s minimum and maximum values. |
mark | An individual mark on the track. |
markLabel | The label for an individual mark on the track. |
marks | A container for all of the marks on the track |
maxValue | The linked FormKit number input for the slider’s maximum value. If the slider only has a single value this is rendered as a direct descendant of the sliderInner section. |
minValue | The linked FormKit number input for the slider’s minimum value. |
sliderInner | The interior div that contains the slider input content. |
track | A wrapper that contains all of the track markup for the slider input. |
trackInner | An interior wrapper for styling purposes that contains all of the track markup excluding the chart. |
trackWrapper | A wrapper that contains all of the track markup excluding the chart. |
tooltipMin | The tooltip for the minimum value selection handle |
tooltipMax | The tooltip for the maximum value selection handle |
Show Universal section keys | |
outer | The outermost wrapping element. |
wrapper | A wrapper around the label and input. |
label | The label of the input. |
prefix | Has no output by default, but allows content directly before an input element. |
prefixIcon | An element for outputting an icon before the prefix section. |
inner | A wrapper around the actual input element. |
suffix | Has no output by default, but allows content directly after an input element. |
suffixIcon | An element for outputting an icon after the suffix section. |
input | The input element itself. |
help | The element containing help text. |
messages | A wrapper around all the messages. |
message | The element (or many elements) containing a message — most often validation and error messages. |
All FormKit inputs are designed with the following accessibility considerations in mind. Help us continually improve accessibility for all by filing accessibility issues here:
Section Key | Attribute | Default | Description |
---|---|---|---|
maxValue | tabindex | -1 | Prioritizes keyboard focus order by setting it to -1 when input is disabled. |
minValue | tabindex | -1 | Prioritizes keyboard focus order by setting it to -1 when input is disabled. |
handleMax | tabindex | -1 or 0 | Prioritizes keyboard focus order by setting it to -1 when input is disabled and 0 when its not. |
handleMin | tabindex | -1 or 0 | Prioritizes keyboard focus order by setting it to -1 when input is disabled and 0 when its not. |
Show Universal section key | |||
label | label | for | Associates the label to an input element. Users can click on the label to focus the input or to toggle between states. |
input | input | disabled | Disables an HTML element, preventing user interaction and signaling a non-interactive state. |
aria-describedby | Associates an element with a description, aiding screen readers. | ||
aria-required | Adds this attribute when validation is required. | ||
icon | icon | for | Whenever icon is defined as a label it links it to an input element. |
Keyboard Event | Description |
---|---|
Tab | Moves the focus to the next focusable input on the page. |
Shift + Tab | Moves the focus to the previous focusable input on the page. |