Skip to content

Commit

Permalink
fix slider over anchoring
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesPHoughton committed Aug 26, 2024
1 parent 6523ebb commit cc3a24b
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 48 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@watts-lab/surveys",
"version": "1.17.2",
"version": "1.17.3",
"description": "",
"main": "dist/index.js",
"module": "dist/index.js",
Expand Down
56 changes: 26 additions & 30 deletions src/customQuestionTypes/labeledRange.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,6 @@
/* stop from overflowing sides and triggering horizontal scrollbar */
}

.slider {
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
background: transparent;
cursor: pointer;

padding-left: 2%;
padding-right: 2%;
border: 0;
/* remove bottom border line */
width: 100%;
}

.sliderLabels {
display: flex;
width: 100%;
Expand All @@ -33,23 +19,37 @@
overflow-wrap: break-word;
}

.slider::-webkit-slider-runnable-track {
input.sv-text[type="range"] {
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
background: transparent;
cursor: pointer;

padding-left: 2%;
padding-right: 2%;
border: 0;
/* remove bottom border line */
width: 100%;
}

input.sv-text[type="range"]::-webkit-slider-runnable-track {
width: 100%;
height: 5px;
background: #ddd;
border: none;
border-radius: 3px;
}

.slider::-moz-range-track {
input.sv-text[type="range"]::-moz-range-track {
width: 100%;
height: 5px;
background: #ddd;
border: none;
border-radius: 3px;
}

.slider::-webkit-slider-thumb {
input.sv-text[type="range"]::-webkit-slider-thumb {
-webkit-appearance: none;
border: none;
height: 20px;
Expand All @@ -60,7 +60,7 @@
visibility: hidden;
}

.slider::-moz-range-thumb {
input.sv-text[type="range"]::-moz-range-thumb {
border: none;
height: 20px;
width: 16px;
Expand All @@ -69,30 +69,26 @@
visibility: hidden;
}

.slider.sliderClicked::-webkit-slider-thumb {
input.sv-text.sliderClicked[type="range"]::-webkit-slider-thumb {
visibility: visible;
}

.slider.sliderClicked::-moz-range-thumb {
input.sv-text.sliderClicked[type="range"]::-moz-range-thumb {
visibility: visible;
}

.slider:focus {
input.sv-text[type="range"]:focus {
outline: none;
}

.slider:focus::-webkit-slider-runnable-track {
input.sv-text[type="range"]:focus::-webkit-slider-runnable-track {
background: #ccc;
}

.slider:focus::-moz-range-track {
input.sv-text[type="range"]:focus::-moz-range-track {
background: #ccc;
}

/* ----------------added styles to make required changes by Amir Rahman from upwork---------------- */

/* to resolve the issue : https://github.com/Watts-Lab/surveys/issues/110 */

.sliderLabel {
width: 0px;
left: 0px;
Expand Down Expand Up @@ -141,6 +137,6 @@ datalist.sliderLabels {
width: 100%;
}

.active {
font-weight: bold;
}
/* .active { */
/* font-weight: bold; */
/* } */
25 changes: 13 additions & 12 deletions src/customQuestionTypes/labeledRange.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,23 +90,24 @@ export function labeledRange(SurveyJS) {
el.appendChild(dl);

slider.setAttribute("list", dl.id);
slider.classList.add("slider");
// slider.classList.add("slider");

if (question.showProgressBar) slider.classList.add("progressBar");

slider.addEventListener("mousedown", () =>
slider.classList.add("sliderClicked")
);
slider.addEventListener("mousedown", () => {
// slider.classList.add("slider");
slider.classList.add("sliderClicked");
});

// added additionally for highlighting label
let last = null;
slider.addEventListener("input", (e) => {
let val = e.target.value;
last?.classList.remove("active");
const activeEl = dl.querySelector(`[value='${val}']`);
activeEl?.classList.add("active");
last = activeEl;
});
// let last = null;
// slider.addEventListener("input", (e) => {
// let val = e.target.value;
// last?.classList.remove("active");
// const activeEl = dl.querySelector(`[value='${val}']`);
// activeEl?.classList.add("active");
// last = activeEl;
// });
},
};

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from "react";
import { PartisanFeelingThermometerUS } from "../../src/index";

describe("PartisanFeelingThermometerUS", () => {
it("loads", () => {
cy.viewport("macbook-11");
cy.mount(<PartisanFeelingThermometerUS />);
cy.viewport("macbook-11");
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,15 @@
"step": 1,
"valueLabels": [
{ "value": 0, "text": "0: Very cold or unfavorable" },
{ "value": 25, "text": "" },
{ "value": 10, "text": "" },
{ "value": 20, "text": "" },
{ "value": 30, "text": "" },
{ "value": 40, "text": "" },
{ "value": 50, "text": "50: Neutral" },
{ "value": 75, "text": "" },
{ "value": 60, "text": "" },
{ "value": 70, "text": "" },
{ "value": 80, "text": "" },
{ "value": 90, "text": "" },
{ "value": 100, "text": "100: Very warm or favorable" }
]
},
Expand All @@ -43,9 +49,15 @@
"step": 1,
"valueLabels": [
{ "value": 0, "text": "0: Very cold or unfavorable" },
{ "value": 25, "text": "" },
{ "value": 10, "text": "" },
{ "value": 20, "text": "" },
{ "value": 30, "text": "" },
{ "value": 40, "text": "" },
{ "value": 50, "text": "50: Neutral" },
{ "value": 75, "text": "" },
{ "value": 60, "text": "" },
{ "value": 70, "text": "" },
{ "value": 80, "text": "" },
{ "value": 90, "text": "" },
{ "value": 100, "text": "100: Very warm or favorable" }
]
}
Expand Down
Binary file modified surveys/partisanFeelingThermometerUS/screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion surveys/partisanFeelingThermometerUS/sha.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"survey":"163f58cdc566f42014cecd7d4f02caac094bd194","score":"150210b7aba45083a2483b58e028c525b2e1fde7"}
{"survey":"53b6a48f3d80efcc1f8c1a8a165b60d363771d32","score":"150210b7aba45083a2483b58e028c525b2e1fde7"}

0 comments on commit cc3a24b

Please sign in to comment.