Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
accessible-ui-components
Advanced tools
A library of simple, lightweight, extensible, and accessible UI Components
A simple, lightweight (20kb), responsive, customizeable, extensible, & accessible range selector!
With Simple Range you can easily create multiple extensible & accessible range selectors on a page, and you don't even have to worry about event listeners not getting cleaned up because it will handle all of that for you!
For purposes of this documentation the terms slider
, range
, range selector
, and range slider
may be used interchangeably.
This component was designed with accessibility in mind. It was also developed to be extremely flexible and reusable, that means you could easily break accessibility by doing things like making the fonts too small, altering focus states, and so on. Use due diligence when altering the component to ensure you're still accessible with the custom options you apply to it!
This also by no means guarantees that it is fully accessible as accessibility requirements are ever evolving, so if you notice any issues at all regarding accessibility of this component we implore you to submit an issue.
Supported by all modern browsers.
IE is not supported, and frankly you should not support an insecure, unsupported, and non-accessible browser either.
View the demo with many examples here
There are three installation options, select your preferred method of installation below.
npm i accessible-web-components
https://cdn.jsdelivr.net/gh/maxshuty/accessible-web-components@latest/dist/simpleRange.min.js
Save the minified file from this repo and insert it as a script tag on your page:
<script type="text/javascript" src="your-path/simpleRange.min.js"></script>
In your HTML:
<range-selector min-range="0" max-range="1000" />
You must provide these values to use the range selector!
Parameter | Alt Name | Type | Values | Required |
---|---|---|---|---|
min-range | min | int | The minimum range for the slider | Yes |
max-range | max | int | The maximum range for the slider | Yes |
Optional attributes you can provide to customize your range selector to fit your exact use case.
Parameter | Type | Values | Default |
---|---|---|---|
id | string | If provided when the range is changed the range-changed event will include the ID of the slider (useful when there are more than one) | null |
preset-min | int | If provided then the min range slider will automatically be set to this number | null |
preset-max | string | If provided then the max range slider will automatically be set to this number | null |
number-of-legend-items-to-show | int | Number of legend items to show below the slider | 2 |
min-label | string | Accessibility label for the minimum value label | 'Minimum' |
max-label | string | Accessibility label for the maximium value label | 'Maximum' |
event-name-to-emit-on-change | string | The event name that will be emitted when the user adjusts the range. I.e. document.addEventListener('my-custom-range-changed-event-name-here', () => doStuff() | range-changed |
inputs-for-labels | boolean | Whether or not to use inputs instead of labels so that the user can manually type in the range. Simply add the inputs-for-labels attribute for this to work (truth is inferred by the presence of this attribute existing) | false |
hide-label | boolean | Whether or not to hide the label. Simply add the hide-label attribute for this to work (truth is inferred by the presence of this attribute existing) | false |
hide-legend | boolean | Whether or not to hide the legend. Simply add the hide-legend attribute for this to work (truth is inferred by the presence of this attribute existing) | false |
slider-color | string | An awesome[red]sauce color (pun intended) | |
circle-border | string | The CSS border property of the circle | 1px solid {circle-border-color} and if circle-border-color is not provided it defaults to 1px solid #8b8b8b |
circle-focus-border | string | The CSS focus border property of the circle | 2px solid {circle-focus-border-color} and if circle-focus-border-color is not provided it defaults to 2px solid #0074cc |
circle-color | string | The color of the slider circles | #ffffff (white) |
circle-border-color | string | The border color of the slider circles | #8b8b8b (grey) |
circle-focus-border-color | string | The focus border color of the slider circles (for accessibility). This should have proper contrast with the other colors you have selected or else it may fail accessibility requirements | #0074cc (Similar to Chromes default blue focus border) |
circle-size | string | The size of the circle sliders. Note: The size of the range line automatically adjusts based on the height of the slider circles. If you have a use case where you need this to be independent please submit an Issue | 20px |
label-font-weight | string | The font weight of the labels | bold |
label-font-size | string | The font size of the labels | 16px |
label-before | string | Adds whatever content is passed in as CSS ::before content like .my-class::before { content: '$' } | '' |
label-after | string | Adds whatever content is passed in as CSS ::after content like .my-class::after { content: '$' } | '' |
number-locale | string | If provided, formatting will be applied to numbers accordingly (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString) | null |
You can dispatch events to do things like reset one or all range selectors on a page or dynamically set a range selectors value. Additionally the range selectors also provide events when things happen like a user adjusts the range. All of the event documentation is below.
range-changed
: Listening for when a user has adjusted the rangeYou can easily capture the data from the range selector when the user changes it like this:
document.addEventListener('range-changed', (e) => {
const data = e.detail;
// data = { sliderId: null, minRangeValue: 0, maxRangeValue: 1000 }
});
range-reset
: Resetting one or many range selectors to their initial stateIn some circumstances you may want to reset the slider to it's initial state. This can easily be achieved by simply emitting a range-reset
event.
NOTE: If you do not provide a sliderId
in the event.detail
it will reset all sliders on the page if you have multiple of them. If you provide a sliderId
then it will only reset the specific slider that you specify in the sliderId
.
Here is how that can be accomplished using a CustomEvent
:
document.dispatchEvent(new CustomEvent('range-reset', {
bubbles: true,
composed: true,
detail: { sliderId: 'sliderIdHere' },
}
)
);
range-set
Setting the slider min/max values dynamically using JavaScriptIn some circumstances you may want to set the sliders values using JavaScript. This can easily be achieved by simply emitting a range-set
event.
NOTE: You must provide a sliderId
, minValue
, and maxValue
in the event.detail
. If any of these three parameters are not included in the event.detail
then the selector will throw an error in your console window and ignore the event.
Here is how this can be accomplished using a CustomEvent
:
function setRange() {
const event = new CustomEvent('range-set', {
detail: {
sliderId: 'yourSliderIdHere',
minValue: 350, // The minimum value you want to set the slider to
maxValue: 700, // The maximum value you want to set the slider to
}
});
document.dispatchEvent(event);
}
You can easily customize colors and other options like these examples:
Using an ID using id
so that it will be emitted on the range-changed
event and using min-label
and max-label
for accessibility. Also using number-of-legend-items-to-show
to show 6 values below the slider:
<range-selector
id="yearSelector"
min-label="Minimum"
max-label="Maximum"
min-range="1000"
max-range="2022"
number-of-legend-items-to-show="6"
/>
You can adjust the number of legend items to show and you can also
use the shorthand min
& max
instead of min-range
and max-range
:
<range-selector
min-label="Minimum"
max-label="Maximum"
min="99"
max="999"
number-of-legend-items-to-show="4"
hide-label
/>
You can set the preset values for the min and max easily using preset-min
and preset-max
:
<range-selector
min-label="Minimum"
max-label="Maximum"
min="99"
max="999"
preset-min="350"
preset-max="800"
number-of-legend-items-to-show="4"
/>
Using a custom range changed event name using event-name-to-emit-on-change
so that your consumer
of this component can listen for this specific event name when
the user has adjusted the ranges:
<range-selector
min-range="1092"
max-range="2022"
min-label="i18nMinLabel"
max-label="i18nMaxLabel"
id="yearRangeSelector"
event-name-to-emit-on-change="my-custom-range-changed-event"
/>
Hiding the legend using hide-legend
:
<range-selector
min-label="i18nLabel"
max-label="i18nLabel"
min-range="5"
max-range="100"
number-of-legend-items-to-show="6"
hide-legend
/>
Hiding the legend and the label using hide-legend
and hide-label
:
<range-selector
min-label="i18nLabel"
max-label="i18nLabel"
min-range="5"
max-range="100"
number-of-legend-items-to-show="6"
hide-legend
hide-label
/>
Altering the colors of the slider, slider circle, and accessibility focus color using slider-color
, circle-color
, circle-border-color
, and circle-focus-border-color
. Any valid CSS color, hex, etc will work:
<range-selector
min-label="Minimum Range"
max-label="Maximum Range"
min-range="5"
max-range="100"
slider-color="orange"
circle-color="lightblue"
circle-border-color="tomato"
circle-focus-border-color="lime"
/>
The min-label
and max-label
's are attributes so that they can be translated by the consumer and passed in with the proper language (i18n capable).
They are to used for accessibility and screen readers and if you want this to be accessible then it is mandatory to set these labels, they will default to "Minimum" and "Maximum" in English only!
Created by Max Poshusta
sincspecv added number-locale
Contributions are always welcome! Simply fork this repo and submit a PR.
Found a bug or want a new feature? Create an issue or a feature request here.
FAQs
A library of simple, lightweight, extensible, and accessible UI Components
We found that accessible-ui-components demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.