3.0.0-alpha.4 Alpha
Light Dark Light Dark System Search /

Range

<wa-range> Since 2.0 stable

Ranges allow the user to select a single value within a given range using a slider.

<wa-range></wa-range>

This component works with standard <form> elements. Please refer to the section on form controls to learn more about form submission and client-side validation.

Examples

Labels

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

<wa-range label="Volume" min="0" max="100"></wa-range>

Help Text

Add descriptive help text to a range with the help-text attribute. For help texts that contain HTML, use the help-text slot instead.

<wa-range label="Volume" help-text="Controls the volume of the current song." min="0" max="100"></wa-range>

Min, Max, and Step

Use the min and max attributes to set the range's minimum and maximum values, respectively. The step attribute determines the value's interval when increasing and decreasing.

<wa-range min="0" max="10" step="1"></wa-range>

Disabled

Use the disabled attribute to disable a slider.

<wa-range disabled></wa-range>

Tooltip Placement

By default, the tooltip is shown on top. Set tooltip to bottom to show it below the slider.

<wa-range tooltip="bottom"></wa-range>

Disable the Tooltip

To disable the tooltip, set tooltip to none.

<wa-range tooltip="none"></wa-range>

Custom Track Colors

You can customize the active and inactive portions of the track using the --track-color-active and --track-color-inactive custom properties.

<wa-range
  style="
  --track-color-active: var(--wa-color-brand-fill-loud);
  --track-color-inactive: var(--wa-color-brand-fill-normal);
"
></wa-range>

Custom Track Offset

You can customize the initial offset of the active track using the --track-active-offset custom property.

<wa-range
  min="-100"
  max="100"
  style="
  --track-color-active: var(--wa-color-brand-fill-loud);
  --track-color-inactive: var(--wa-color-brand-fill-normal);
  --track-active-offset: 50%;
"
></wa-range>

Custom Tooltip Formatter

You can change the tooltip's content by setting the tooltipFormatter property to a function that accepts the range's value as an argument.

<wa-range min="0" max="100" step="1" class="range-with-custom-formatter"></wa-range>

<script>
  const range = document.querySelector('.range-with-custom-formatter');
  range.tooltipFormatter = value => `Total - ${value}%`;
</script>

Slots

Name Description
label The range's label. Alternatively, you can use the label attribute.
help-text Text that describes how to use the input. Alternatively, you can use the help-text attribute.

Properties

Name Description Reflects
name
name
The name of the range, submitted as a name/value pair with form data.
Type string
Default ''
defaultValue
value
The default value of the form control. Primarily used for resetting the form control.
value
The current value of the range, submitted as a name/value pair with form data.
Type number
label
label
The range's label. If you need to display HTML, use the label slot instead.
Type string
Default ''
helpText
help-text
The range's help text. If you need to display HTML, use the help-text slot instead.
Type string
Default ''
disabled
disabled
Disables the range.
Type boolean
Default false
min
min
The minimum acceptable value of the range.
Type number
Default 0
max
max
The maximum acceptable value of the range.
Type number
Default 100
step
step
The interval at which the range will increase and decrease.
Type number
Default 1
tooltip
tooltip
The preferred placement of the range's tooltip.
Type 'top' | 'bottom' | 'none'
Default 'top'
tooltipFormatter
A function used to format the tooltip's value. The range's value is passed as the first and only argument. The function should return a string to display in the tooltip.
Type (value: number) => string
form
form
By default, form controls are associated with the nearest containing <form> element. This attribute allows you to place the form control outside of a form and associate it with the form that has this id. The form must be in the same document or shadow root for this to work.
Type null | string
Default null
withLabel
with-label
Used for SSR to render slotted labels. If true, will render slotted label content on first paint.
Type boolean
Default false
withHelpText
with-help-text
Used for SSR to render slotted labels. If true, will render slotted help-text content on first paint.
Type boolean
Default false

Methods

Name Description Arguments
focus() Sets focus on the range. options: FocusOptions
blur() Removes focus from the range.
stepUp() Increments the value of the range by the value of the step attribute.
stepDown() Decrements the value of the range by the value of the step attribute.

Events

Name Description
wa-blur Emitted when the control loses focus.
wa-change Emitted when an alteration to the control's value is committed by the user.
wa-focus Emitted when the control gains focus.
wa-input Emitted when the control receives input.
wa-invalid Emitted when the form control has been checked for validity and its constraints aren't satisfied.

CSS custom properties

Name Description
--thumb-color
The color of the thumb.
--thumb-gap
The visual gap between the edges of the thumb and the track.
--thumb-shadow
The shadow effects around the edges of the thumb.
--thumb-size
The size of the thumb.
--tooltip-offset
The vertical distance the tooltip is offset from the thumb.
--track-color-active
The color of the portion of the track that represents the current value.
--track-color-inactive
The of the portion of the track that represents the remaining value.
--track-height
The height of the track.
--track-active-offset
The point of origin of the active track.

CSS parts

Name Description
form-control The form control that wraps the label, input, and help text.
form-control-label The label's wrapper.
form-control-input The range's wrapper.
form-control-help-text The help text's wrapper.
base The component's base wrapper.
input The internal <input> element.
tooltip The range's tooltip.

Importing

The autoloader is the recommended way to import components. If you prefer to do it manually, use one of the following code snippets.

CDN npm React

To manually import this component from the CDN, use the following code.

import 'https://early.webawesome.com/webawesome@3.0.0-alpha.4/dist/components/range/range.js';
Coming soon! Coming soon!
    No results