Accessible Progres bar / Range slider
What is this
As I haven't found one, I've tried to create simple to use, fully accessible slider component. Build is less than 2Kb.
It is written in TypeScript and I will be releasing React component soon.
I will appreciate any feedback and pull requests.
DEMO
Features
- Fully accessible (based on this example)
- Works on touch enabled devices (you can tap anywhere and drag)
- IE10+
- Support for both integers and float values (using
options.float
) - Two value tooltips, one shown all the time, and one on hover
- Callback system
- Additional "buffer bar" that is controlled by the user
- Easy to style
TODO
Usage
You'll need to import ProgressBar
class and instantiate by passing two params.
The first one is selectorOrElement
- CSS selector string or HTML element. This element will be used as a slider's wrapper, and library will create all needed elements inside it.
Two other one is the options
object, and check below for more documenation on available options.
ProgressBar(selectorOrElement:TSelectorOrElement, options:IProgressBarOptionsPartial);
You'll have to import CSS styling as well.
Example:
import ProgressBar from 'aria-progress-range-slider';
import 'aria-progress-range-slider/dist/style.css';
const selector = '.progress-bar';
const options = {};
new ProgressBar(selector, options);
Options
ariaLabel?: string;
ariaLabeledBy?: string;
arrowMoveStep?: number;
className?: string;
disabled?: boolean;
float?: boolean;
getTooltipText?(value: number, options?: IProgressBarOptions): string;
getValueText?(value: number, options?: IProgressBarOptions): string;
initialValue?: number;
max?: number;
min?: number;
onChange?(value: number, options?: IProgressBarOptions): any;
onDragEnd?(value: number, options?: IProgressBarOptions): any;
onDragMove?(value: number, options?: IProgressBarOptions): any;
onDragStart?(value: number, options?: IProgressBarOptions): any;
pageMoveStep?: number;
snap?: boolean;
step?: number;
Please note that you can't hide elements through options (nor API). Just use CSS to hide them. I think it is a little bit cleaner than having a lot of conditions in the code.
Elements and CSS classes
Default CSS class names are:
.AriaProgressBar {}
.AriaProgressBar--hover {}
.AriaProgressBar--dragging {}
.AriaProgressBar--disabled {}
.AriaProgressBar-track {}
.AriaProgressBar-progress {}
.AriaProgressBar-hover {}
.AriaProgressBar-buffer {}
.AriaProgressBar-handle {}
.AriaProgressBar-mainTooltip {}
.AriaProgressBar-hoverTooltip {}
Please note that if you change options.className
it will use it instead of AriaProgressBar
.
Check https://github.com/Stanko/aria-progress-range-slider/blob/master/src/style.scss to create your own theme. (Everything above // Default theme
is mandatory for slider to work.)
API
This is component's public API.
destroy(): void;
getValue(): number;
setValue(value: number): void;
setBufferValue(value: number): void;
disable(): void;
enable(): void;
Development
I'm using Parcel for development and docs, while microbundle is used for npm builds.
For local development use:
npm start
It will start development server on http://localhost:1234/