npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

dxb_slider

v2.0.0

Published

Customizable Range Slider with RTL Support and WCAG AA Accessibility features

Downloads

44

Readme

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.

Features

  • Customizable range slider with a dynamically added, synchronized number input
  • Accessible design with ARIA attributes
  • Namespaced CSS for easy integration
  • Minimal JavaScript footprint
  • Support for both LTR (Left-to-Right) and RTL (Right-to-Left) layouts
  • Language-specific numeral display (pending broader browser adoption)
  • Optimized for mobile devices with appropriate software keyboard support

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="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="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:

  • Reversing the order of the slider and number input
  • Adjusting the slider track fill direction
  • Properly aligning text and elements for RTL languages

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

  • Arabic (lang="ar")
  • Persian (lang="fa")
  • Bengali (lang="bn")
  • Hindi, Marathi, Nepali (lang="hi", lang="mr", lang="ne")

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:

  • The range input is properly labeled using aria-labelledby.
  • ARIA attributes (aria-valuemin, aria-valuemax, aria-valuenow) are dynamically updated to reflect the current state of the slider.
  • The number input is added programmatically and hidden from screen readers (aria-hidden="true") to avoid redundancy and potential confusion.
  • The slider can be operated using keyboard controls (arrow keys for fine adjustment, Page Up/Down for larger steps).

Keyboard Navigation

  • Arrow Left/Down: Decrease value by one step
  • Arrow Right/Up: Increase value by one step
  • Page Down: Decrease value by 10% of the range
  • Page Up: Increase value by 10% of the range
  • Home: Set to minimum value
  • End: Set to maximum value

Mobile Support

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

  • The number input field automatically triggers the appropriate software keyboard on mobile devices:
    • For whole number inputs, a numeric keyboard is displayed.
    • For decimal inputs (when the slider's step attribute includes decimals), a decimal keyboard is shown.
  • The pattern attribute ensures that only valid numeric input is accepted.
  • These optimizations work across modern mobile browsers, including Safari.

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)

  • Q: How do I customize the slider's appearance?

    A: You can customize the slider by modifying the CSS variables in the :root selector. Refer to the Customization section for more details.

  • Q: Does DXB Slider support touch devices?

    A: Yes, DXB Slider is designed to work on both desktop and touch devices.

  • Q: How do I enable RTL support?

    A: Add the dir="rtl" attribute to the container. Refer to the RTL Support section for more details.

  • Q: What browsers are supported?

    A: DXB Slider supports all modern browsers. Note that language-specific numeral features are currently best supported in Firefox.

  • Q: How can I contribute to the project?

    A: Contributions are welcome! Please open an issue or submit a pull request. Refer to the Contributing section for more details.

  • Q: How does DXB Slider handle input on mobile devices?

    A: DXB Slider automatically displays the appropriate software keyboard (numeric or decimal) on mobile devices based on the slider's configuration. This ensures a smooth input experience for users on touch devices.

  • Q: Does DXB Slider support dynamically added content?

    A: Yes, DXB Slider automatically detects and initializes new sliders added to the page after the initial load.

  • Q:Is DXB Slider really only 1KB?

    A: Yes, DXB Slider's minified payload is only 894 bytes at the time of writing. This is possible due to modern browsers supprting CSS styling of native HTML range inputs. Feel free to count the bytes yourself:image

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.