Usage
Range lets users pick a numeric value with a slider that must be no less than a given minimum and no more than a given maximum. Set min, max and step to define the allowed values, and value for the initial position.
The range renders its built-in label, hint and error on its own. Wrapped in a Field, the Field takes over with a Field Label, Field Description and Field Error, and the built-in versions step aside automatically.
import "@nordhealth/components/lib/Range"
import "@nordhealth/components/lib/Field"
import "@nordhealth/components/lib/FieldLabel"
import "@nordhealth/components/lib/FieldDescription"
Standalone or inside a Field
Use the control on its own with its built-in label, hint and error, or wrap it in a Field — the Field then provides the labelling. Both render the same control:
Examples
Range and step
Use min, max and step to control the bounds and increment of the slider.
Steps
Use step to constrain the value to fixed increments as the user drags the thumb.
Unit
Display a unit alongside the value to clarify what the number represents.
Hint
Add a Field Hint to give the user extra guidance about the field.
Required
Set required on the Field Label to show the required indicator and mark the control required.
Custom thumb size
Adjust the size of the draggable thumb with a CSS custom property.
Custom track size
Adjust the thickness of the track with a CSS custom property.
Responsive
The range adapts to the available space and remains usable across viewport sizes.
Error
Show validation with a Field Error and mark the Field invalid.
Disabled and read-only
A disabled range cannot be focused or changed and is excluded from form submission. A readonly range can be focused but not changed, and its value is still submitted.
Hidden label
Every range needs an accessible name. To hide the label visually while keeping it available to assistive technology, set hide-label on the range and connect a Field Label with for. Inside a Field, a Field Label provides this instead.
Expand
Use expand to make the range fill the width of its container.
RTL
Range follows the document or container direction. Toggle the direction to see the layout mirror.
Accessibility
- Always give the range an accessible name with a Field Label connected via
for. If a visible label doesn't suit the layout, sethide-labelon the range so it keeps an accessible name for screen reader users. - The slider is keyboard operable: arrow keys move the value by
stepbetweenminandmax, and the current value is exposed to assistive technology. - Convey validation with a Field Error rather than colour alone — it is associated with the range and announced to assistive technology.
- Mark required fields by setting
requiredon the Field Label; it shows the indicator and marks the control required. - Prefer
readonlyoverdisabledwhen the value is still relevant but not adjustable, as disabled controls are removed from the tab order and not submitted with the form.
API reference
Range
Range input lets user specify a numeric value using a slider which must be no less than a given value, and no more than another given value.
<nord-accordion></nord-accordion>Props
| Property | Attribute | Description | Type | Default |
|---|---|---|---|---|
min | min | Minimum value for the range slider. | number | 0 |
max | max | Maximum value for the range slider. | number | 10 |
step | step | Step amount for the range slider. | number | 1 |
expand | expand | Controls whether the input expands to fill the width of its container. | boolean | false |
placeholder | placeholder | Placeholder text to display within the control. | string | undefined | — |
required | required | Determines whether the control is required or not.
A required control is announced as such to assistive technology and, inside
a <nord-field>, drives the required indicator on the <nord-field-label>.
When using this property you need to also set “novalidate” attribute on a form element to prevent browser from displaying its own validation errors. | boolean | false |
autocomplete | autocomplete | Specifies the data type of the field, so that the browser may attempt to fill out the field automatically on behalf of the user. | AutocompleteAttribute | 'off' |
readonly | readonly | Makes the component readonly, so that it is not editable. Readonly differs from disabled in that readonly fields are still focusable and will be submitted with a form. | boolean | false |
disabled | disabled | Makes the component disabled. This prevents users from being able to interact with the component, and conveys its inactive state to assistive technologies. | boolean | false |
name | name | The name of the form component. | string | undefined | — |
value | value | The value of the form component. | string | '' |
form | form | Gets the form, if any, associated with the form element. The setter accepts a string, which is the id of the form. | HTMLFormElement | null | — |
Field properties
| Property | Attribute | Description | Type | Default |
|---|---|---|---|---|
label | label | Label for the control. Ignored when the control is wrapped in a
<nord-field>, which provides the label via <nord-field-label>. | string | '' |
hint | hint | Optional hint text shown with the control. Ignored inside a <nord-field>,
which provides it via <nord-field-description>. | string | undefined | — |
hintBelow | hint-below | Renders the hint below the control and any error instead of below the label. | boolean | false |
hideLabel | hide-label | Visually hide the label, but still expose it to assistive technologies. | boolean | false |
error | error | Optional error shown with the control. Ignored inside a <nord-field>,
which provides it via <nord-field-error>. | string | undefined | — |
hideRequired | hide-required | Visually hide the required indicator, but still expose the required state to assistive technologies. | boolean | false |
Slots
| Slot name | Description |
|---|---|
label | Use when a label requires more than plain text. |
hint | Optional slot that holds hint text for the input. |
error | Optional slot that holds error text for the input. |
Methods
| Method name | Parameters | Description |
|---|---|---|
focus(options?: FocusOptions) => void | options: An object which controls aspects of the focusing process. | Programmatically move focus to the component. |
blur() => void | N/A | Programmatically remove focus from the component. |
click() => void | N/A | Programmatically simulates a click on the component. |
| Event | Detail Type | Description |
|---|---|---|
input | NordEvent | Fired as the user types into the input. |
change | NordEvent | Fired whenever the input's value is changed via user interaction. |
CSS Properties
CSS Custom Properties provide more fine grain control over component presentation. We advise utilizing existing properties on the component before using these.
| Property | Description | Default |
|---|---|---|
--n-range-thumb-size | Controls the size of the thumb. | 20px |
--n-range-track-color-active | Controls the color of the portion of the track that represents the current value. | var(--n-color-accent) |
--n-range-track-color-inactive | Controls the color of the portion of the track that represents the remaining value. | var(--n-color-border-strong) |
--n-range-track-size | Controls the height of the track. | 3px |
Design guidelinesFor designers
Usage
This section includes guidelines for designers and developers about the usage of this component in different contexts.
Do
- Use to let user specify a numeric value using a slider.
- Use when the accuracy of the numeric value entered isn’t important.
- Always use with a label, even if that label is hidden.
Don’t
- Don’t use when the accuracy of the numeric value entered is important.
- For entering arbitrary numeric values. Use input component instead.
Hint placement
Hint text is rendered above the control by default to preserve existing behavior for current consumers. Use the hint-below property to opt in to rendering the hint below the control and any error.
This is a non-breaking rollout for teams adopting the new layout gradually. Existing integrations keep the current placement unless hint-below is explicitly set.
Content guidelines
Range labels act as a title for the range input. Labels should typically be short and in noun form:
When writing range labels, always write them in sentence case, not title case. The first word should be capitalized and the rest lowercase (unless a proper noun):
Do not use colons in range label: