Skip to content

Commit

Permalink
fix(sc-slider): handle min === max case
Browse files Browse the repository at this point in the history
  • Loading branch information
b-ma committed Dec 5, 2023
1 parent e4c6d0b commit e1bdeee
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/sc-slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,20 +233,24 @@ class ScSliderBase extends ScElement {
// we could probably get rid of this._min and this._max
update(changedProperties) {
if (changedProperties.has('min') || changedProperties.has('max')) {
if (this.min > this.max) {
if (this._min > this._max) {
console.warn('sc-slider - min > max, inverting values');

const tmp = this._max;
this._max = this._min;
this._min = tmp;
}

if (this._min === this._max) {
console.warn('sc-slider - min === max, incrementing max');
this._max += 1;
}
}

if (changedProperties.has('min')
|| changedProperties.has('max')
|| changedProperties.has('step')
) {
console.log('heiho');
this._updateScales();
}

Expand Down
6 changes: 6 additions & 0 deletions tests/src/test-sc-slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,10 @@ export const template = html`
value="100"
number-box
></sc-slider>
<sc-slider
max="50"
min="50"
value="100"
number-box
></sc-slider>
`;

0 comments on commit e1bdeee

Please sign in to comment.