Skip to content

Commit e90c9b4

Browse files
committed
fixes #3 Slider does not work for small ranges
1 parent ff81974 commit e90c9b4

File tree

2 files changed

+21
-13
lines changed

2 files changed

+21
-13
lines changed

sample/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
</script>
1919
</head>
2020
<body>
21-
<node-projects-slider style="position: absolute; width: 500px; height: 300px;" value-min="1234"; value-max="88888" min="0"; max="100000">
21+
<node-projects-slider style="position: absolute; width: 500px; height: 300px;" value-min="10"; value-max="90" min="0"; max="100">
2222

2323
</node-projects-slider>
2424
</body>

src/slider/SliderWebcomponent.ts

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ export class SliderWebcomponent extends BaseCustomWebComponentConstructorAppend
2626
/* Remove Arrows/Spinners */
2727
input::-webkit-outer-spin-button,
2828
input::-webkit-inner-spin-button {
29-
-webkit-appearance: none;
29+
appearance: none;
3030
margin: 0;
3131
}
3232
3333
.slider-container {
34-
width: 100%;
34+
width: 100%;
3535
}
3636
3737
.slider-container {
@@ -62,7 +62,7 @@ export class SliderWebcomponent extends BaseCustomWebComponentConstructorAppend
6262
top: -8px;
6363
pointer-events: none;
6464
cursor: pointer;
65-
-webkit-appearance: none;
65+
appearance: none;
6666
}
6767
6868
/* Styles for the range thumb in WebKit browsers */
@@ -72,8 +72,17 @@ export class SliderWebcomponent extends BaseCustomWebComponentConstructorAppend
7272
border-radius: 70%;
7373
background: #555;
7474
pointer-events: auto;
75-
-webkit-appearance: none;
75+
appearance: none;
7676
}
77+
78+
input[type="range"]::-moz-range-thumb {
79+
height: 18px;
80+
width: 18px;
81+
border-radius: 70%;
82+
background: #555;
83+
pointer-events: auto;
84+
appearance: none;
85+
}
7786
7887
`;
7988

@@ -122,6 +131,7 @@ export class SliderWebcomponent extends BaseCustomWebComponentConstructorAppend
122131
private _inputs: HTMLInputElement[];
123132
private _rangeInputs: HTMLInputElement[];
124133
private _ready: Boolean = false;
134+
private _valuesGap: number = 1;
125135

126136
public get valueMin() {
127137
return this._valueMin;
@@ -187,8 +197,6 @@ export class SliderWebcomponent extends BaseCustomWebComponentConstructorAppend
187197

188198
const rangevalue: HTMLDivElement = this._getDomElement("slider");
189199

190-
let valuesGap = 500;
191-
192200
for (let i = 0; i < this._inputs.length; i++) {
193201
this._inputs[i].addEventListener("blur", this._handleInputChange.bind(this));
194202
this._inputs[i].addEventListener("keydown", (e) => {
@@ -207,13 +215,13 @@ export class SliderWebcomponent extends BaseCustomWebComponentConstructorAppend
207215
let diff = maxVal - minVal;
208216

209217
// Check if the values gap is exceeded
210-
if (diff < valuesGap) {
218+
if (diff < this._valuesGap) {
211219

212220
// Check if the input is the min range input
213221
if ((e.target as HTMLInputElement).className === "min-range") {
214-
this._rangeInputs[0].value = (maxVal - valuesGap).toString();
222+
this._rangeInputs[0].value = (maxVal - this._valuesGap).toString();
215223
} else {
216-
this._rangeInputs[1].value = (minVal + valuesGap).toString();
224+
this._rangeInputs[1].value = (minVal + this._valuesGap).toString();
217225
}
218226
} else {
219227

@@ -257,13 +265,13 @@ export class SliderWebcomponent extends BaseCustomWebComponentConstructorAppend
257265
let diff = maxp - minp;
258266

259267
if (minp < this._min) {
260-
alert(`Minimum value cannot be less than ${this.min.toString()}`);
268+
console.log(`Minimum value cannot be less than ${this.min.toString()}`);
261269
this._inputs[0].value = this._min.toString();
262270
minp = 0;
263271
}
264272

265273
if (maxp > this._max) {
266-
alert(`Maximum value cannot be greater than ${this.max.toString()}`);
274+
console.log(`Maximum value cannot be greater than ${this.max.toString()}`)
267275
this._inputs[1].value = this._max.toString();
268276
maxp = this._max;
269277
}
@@ -278,7 +286,7 @@ export class SliderWebcomponent extends BaseCustomWebComponentConstructorAppend
278286
}
279287
}
280288

281-
if (diff >= 500 && maxp <= parseInt(this._rangeInputs[1].max)) {
289+
if (diff >= this._valuesGap && maxp <= parseInt(this._rangeInputs[1].max)) {
282290
if (inputIndex === 0) {
283291
this._rangeInputs[0].value = minp.toString();
284292
let value1 = parseInt(this._rangeInputs[0].max);

0 commit comments

Comments
 (0)