FormikSlider
Basic Usage
import { FormikSlider } from '@krakentech/coral-formik';
import { Button } from '@krakentech/coral';
import { Formik, Form } from 'formik';
<Formik
initialValues={{ slider: 100 }}
onSubmit={() => console.log('Submitted')}
validationSchema={yup.object().shape({
slider: yup
.number()
.required('This field is required')
.min(150, 'Please choose a value of at least 150'),
})}
>
<Form method="post">
<FormikSlider name="slider" label="Select value" min={69} max={420} />
<Button type="submit">Submit</Button>
</Form>
</Formik>Full API
| Name | Type | Default |
|---|---|---|
ariaLabel | stringThe aria-label of the slider thumb. | Slider control |
disabled | booleanIf | false |
getAriaValueText | (value: number) => stringAccepts a function which returns a string value that provides a user-friendly name for the current value of the slider. This is important for screen reader users. | |
isAnimated | booleanIf | true |
label | stringThe accessible label for the slider. | |
max | numberThe maximum allowed value of the slider. This should not be equal to min. | 100 |
min | numberThe minimum allowed value of the slider. This should not be equal to max. | 0 |
name | stringName attribute of the hidden | |
onBlur | FocusEventHandler<HTMLDivElement>Callback fired when the slider loses user focus. | |
onChange | SliderChangeHandlerCallback fired each time the user changes the slider value.
| |
optional | booleanAdd an optional flag to the label for this field (controlled by https://coral-oe.vercel.app/?path=/docs/guides-configuration—docs#overrides-optional-indicator optionalIndicator). This should be set to true if you have set this field to be optional in your validation schema. | false |
showLabels | booleanDisplay the field label, including the currently-selected value. | true |
step | numberThe granularity with which the slider can step through values. (A “discrete” slider.) The min prop serves as the origin for the valid values. We recommend (max - min) to be evenly divisible by the step. | 1 |
valueLabelDisplay | SliderValueLabelDisplayControls when the value label is displayed:
| auto |
valueLabelFormat | (value: number) => stringA function that formats the value label. This is useful for displaying currency, percentages, etc. | |
validate | FieldValidator | undefinedAn optional field level validation function. See Formik docs for more details |