-
-
Notifications
You must be signed in to change notification settings - Fork 332
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dual Range Slider #2224
Comments
Forgot to paste the JS portion of the example: function controlFromInput(fromSlider, fromInput, toInput, controlSlider) {
const [from, to] = getParsed(fromInput, toInput);
fillSlider(fromInput, toInput, '#C6C6C6', '#25daa5', controlSlider);
if (from > to) {
fromSlider.value = to;
fromInput.value = to;
} else {
fromSlider.value = from;
}
}
function controlToInput(toSlider, fromInput, toInput, controlSlider) {
const [from, to] = getParsed(fromInput, toInput);
fillSlider(fromInput, toInput, '#C6C6C6', '#25daa5', controlSlider);
setToggleAccessible(toInput);
if (from <= to) {
toSlider.value = to;
toInput.value = to;
} else {
toInput.value = from;
}
}
function controlFromSlider(fromSlider, toSlider, fromInput) {
const [from, to] = getParsed(fromSlider, toSlider);
fillSlider(fromSlider, toSlider, '#C6C6C6', '#25daa5', toSlider);
if (from > to) {
fromSlider.value = to;
fromInput.value = to;
} else {
fromInput.value = from;
}
}
function controlToSlider(fromSlider, toSlider, toInput) {
const [from, to] = getParsed(fromSlider, toSlider);
fillSlider(fromSlider, toSlider, '#C6C6C6', '#25daa5', toSlider);
setToggleAccessible(toSlider);
if (from <= to) {
toSlider.value = to;
toInput.value = to;
} else {
toInput.value = from;
toSlider.value = from;
}
}
function getParsed(currentFrom, currentTo) {
const from = parseInt(currentFrom.value, 10);
const to = parseInt(currentTo.value, 10);
return [from, to];
}
function fillSlider(from, to, sliderColor, rangeColor, controlSlider) {
const rangeDistance = to.max-to.min;
const fromPosition = from.value - to.min;
const toPosition = to.value - to.min;
controlSlider.style.background = `linear-gradient(
to right,
${sliderColor} 0%,
${sliderColor} ${(fromPosition)/(rangeDistance)*100}%,
${rangeColor} ${((fromPosition)/(rangeDistance))*100}%,
${rangeColor} ${(toPosition)/(rangeDistance)*100}%,
${sliderColor} ${(toPosition)/(rangeDistance)*100}%,
${sliderColor} 100%)`;
}
function setToggleAccessible(currentTarget) {
const toSlider = document.querySelector('#toSlider');
if (Number(currentTarget.value) <= 0 ) {
toSlider.style.zIndex = 2;
} else {
toSlider.style.zIndex = 0;
}
}
const fromSlider = document.querySelector('#fromSlider');
const toSlider = document.querySelector('#toSlider');
const fromInput = document.querySelector('#fromInput');
const toInput = document.querySelector('#toInput');
fillSlider(fromSlider, toSlider, '#C6C6C6', '#25daa5', toSlider);
setToggleAccessible(toSlider);
fromSlider.oninput = () => controlFromSlider(fromSlider, toSlider, fromInput);
toSlider.oninput = () => controlToSlider(fromSlider, toSlider, toInput);
fromInput.oninput = () => controlFromInput(fromSlider, fromInput, toInput, toSlider);
toInput.oninput = () => controlToInput(toSlider, fromInput, toInput, toSlider); |
Hey @Silvallis, yeah we've heard this request on a number of occasions. Unfortunately it's not just a matter of sitting down and building this, but rather the fact this would go against our standards for handling form components. That being, we actively try to avoid creating new form components whenever possible and instead favor native options instead. In fact, most of our form component elements (ex: Range Slider) are just wrappers around the native implemented features, but with some nice quality of life added. For example, take the Range Slider. We generate the native datalist required to render tick marks: Our biggest hang up is introducing elements that are not fully accessible. A11y is a major concern of Skeleton, and we would rather go without a feature than implement one with poor support for accessibility. While your example shared above is likely functional, it doesn't appear to make considerations for a11y. If you or any other volunteers would like to take on the task of building a really first class a11y friendly dual range slider, we would gladly accept it. Otherwise this will likely remain pending for now. Just want to set clear expectations here. |
In an effort to prepare for Skeleton v3, we're consolidate some related issues down to a single ticket. This will ensure that we can see the full context of requests when the time comes to refactor and update this feature going forward. If you wish to add additional feedback or suggestions, please so here: |
Describe the feature in detail (code, mocks, or screenshots encouraged)
A new type of range slider with two pips commonly used for price ranges (for example).
![image](https://private-user-images.githubusercontent.com/33603070/280983227-66fcf90c-f81e-4927-8784-4fe3b1721fe1.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzg5MjU1MzAsIm5iZiI6MTczODkyNTIzMCwicGF0aCI6Ii8zMzYwMzA3MC8yODA5ODMyMjctNjZmY2Y5MGMtZjgxZS00OTI3LTg3ODQtNGZlM2IxNzIxZmUxLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMDclMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjA3VDEwNDcxMFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTdkZGJmYTVhODliMmFlNjZkMjU5MmJlNGFiYzRhOTdkYWViMTNkODJiOTk0ZWU3Y2NlZWNmZmYwZGFlMzc4ZjEmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.MDlhECUkdmzs-p7992Om3MZik5o_-L9tZa13eDhAt3s)
This feature could either be an enhancement of the existing RangeSlider component or be a new component.
I found this implementation of a dual range slider in pure HTML/CSS:
The biggest problem will be that there is no native option in the range input element, therefore it would need to be a custom option like the one provided.
What type of pull request would this be?
New Feature
Provide relevant links or additional information.
https://w3collective.com/double-range-slider-html-css-js/
https://medium.com/@predragdavidovic10/native-dual-range-slider-html-css-javascript-91e778134816
https://svelte.dev/repl/75d34e46cbe64bb68b7c2ac2c61931ce?version=4.2.2
https://codepen.io/predragdavidovic/pen/mdpMoWo
The text was updated successfully, but these errors were encountered: