dxpr / DXB-Slider

A customizable range slider with RTL support, synchronized number input, and accessibility features for modern web applications.
GNU General Public License v2.0
0 stars 0 forks source link

DXB Slider - Customizable Range + Number Input Slider with RTL Support and WCAG AA Accessibility features

DXB Slider demo page

DXB Slider is a lightweight, customizable range slider component with a programmatically added number input. It's designed to be easy to implement, accessible, styleable, and supports both LTR and RTL layouts.

dxb-slider-chrome-firefox-safari

Features

Installation

To use DXB Slider, include the CSS and JavaScript files in your project, and follow the usage instructions below.

Usage

  1. Include the CSS in your <head> tag:

    <link rel="stylesheet" href="https://github.com/dxpr/DXB-Slider/blob/2.x/path/to/dxb-slider.min.css">
  2. Add the HTML structure for your slider:

    <div class="dxb-slider-container">
        <label id="mySliderLabel" for="mySlider">Slider Label</label>
        <div class="dxb-slider-wrapper">
            <div class="dxb-slider-track">
                <input type="range" id="mySlider" class="dxb-slider" 
                       min="0" max="100" value="50" step="1" 
                       data-dxb-slider
                       aria-labelledby="mySliderLabel">
            </div>
        </div>
    </div>
  3. Include the JavaScript at the end of your <body> tag:

    <script src="https://github.com/dxpr/DXB-Slider/raw/2.x/path/to/dxb-slider.min.js"></script>
  4. The sliders will be automatically initialized for all elements with the data-dxb-slider attribute, including those added dynamically after page load.

  5. The sliders will automatically adjust for mobile devices, displaying the appropriate software keyboard (numeric or decimal) based on the slider's configuration.

RTL Support and Language-Specific Numerals

To use the slider in RTL mode, add the dir="rtl" attribute to the container:

<div class="dxb-slider-container" dir="rtl" lang="ar">
    <!-- ... slider content ... -->
</div>

The slider will automatically adjust its layout for RTL, including:

For language-specific numerals, DXB Slider uses CSS font-variant-numeric properties. Currently supported languages include:

Note: The language-specific numeral feature is currently fully supported in Firefox. Other browsers may have limited or no support for this feature. As browser adoption increases, this feature will become more widely available without any changes to the DXB Slider code.

Customization

You can customize the appearance of the slider by modifying the CSS variables in the :root selector:

:root {
    --dxb-slider-width: 270px;
    --dxb-slider-height: 5px;
    --dxb-slider-thumb-size: 20px;
    --dxb-slider-primary-color: #0550e6;
    --dxb-slider-secondary-color: #dadfe7;
}

DXB Slider Feature Comparison

Feature DXB Slider AlRangeSlider Ion.RangeSlider Simple Slider Bootstrap Slider
File Size 1 KB 75 KB 85 KB 15 KB 11 KB
Dependency-free ❌ (jQuery) ❌ (jQuery) ❌ (jQuery) ✅ (Optional)
Supports Double Handle
RTL Support
Mobile Optimization
Accessibility Features
Built-in Themes/Skins ✅ (6 skins)
Touch Support

Comparison of range slider plugins based on key features.

Accessibility

DXB Slider is designed with accessibility in mind:

Keyboard Navigation

Mobile Support

DXB Slider is optimized for mobile devices, providing an enhanced user experience:

Roadmap

  1. Make default design fully WCAG AA or AAA compliant
  2. Add support for tickmarks to aide stepped slider user experience
  3. Add more design customization options, for example for the handle shape
  4. Optimize performance for pages with frequent DOM changes

Frequently Asked Questions (FAQ)

License

This project is licensed under the GNU General Public License v2.0 (GPL-2.0) - see the LICENSE file for details.

Contributing

Contributions are welcome! Please open an issue or submit a pull request.