Forms

Slider

A labelled range input with its current value in an <output> and optional bounds.

JxSlider import 'package:jx_cli/ui.dart' New in 0.0.3

Preview

40%

When to use it

  • Volume, opacity, a price ceiling.
  • Any value where the exact number matters less than the position.

States

16 px

Applies to the reading view.

With a hint
70
Disabled

Minimal example

Dart
JxSlider(id: 'volume', label: 'Volume', value: 40)

Complete example

A full Jaspr component you can paste into a project.

Dart
import 'package:jaspr/jaspr.dart';
import 'package:jx_cli/ui.dart';

@client
class PriceFilter extends StatefulComponent {
  const PriceFilter({super.key});

  @override
  State<PriceFilter> createState() => _PriceFilterState();
}

class _PriceFilterState extends State<PriceFilter> {
  num ceiling = 250;

  @override
  Component build(BuildContext context) {
    return JxSlider(
      id: 'price',
      name: 'max_price',
      label: 'Maximum price',
      value: ceiling,
      min: 0,
      max: 1000,
      step: 50,
      unit: ' €',
      showBounds: true,
      onInput: (value) => setState(() => ceiling = value),
    );
  }
}

Properties

Property Type Default Description
id String required Links the label, the output and the hint.
label String required Visible label.
value num required Current value.
min num 0 Lowest value.
max num 100 Highest value.
step num 1 Increment.
name String? null Form field name.
unit String '' Appended to the shown value, such as % or px .
showValue bool true Shows the value beside the label.
showBounds bool false Shows min and max under the track.
hint String? null Help text under the slider.
disabled bool false Disables the slider.
classes String? null Extra JX classes, appended after the component classes.

Events

Callback Type Fires when
onInput ValueChanged<num>? While the thumb moves, by pointer or keyboard.

Customizing

  • Pass classes to add or override utilities: they come last, so classes: 'w:full' wins over the default width.
  • The track takes the primary color through accent:.

Responsive

  • Full width of its container; the native thumb is large enough to drag on touch screens.

Accessibility

  • A native type="range": arrow keys, Page Up/Down, Home and End work everywhere.
  • With a unit, aria-valuetext reads "40%" instead of "40".
  • The value is in an <output for> linked to the input.

Limitations

  • One thumb: no range with a minimum and a maximum.
  • The track look is the browser's, tinted with accent-color.