Date: Thu, 22 Feb 2024 11:49:10 +0530
Subject: [PATCH 2/7] feat(slider): two knobs
---
.../src/components/slider/slider-input.ts | 15 ++--
.../src/components/slider/slider.ts | 90 ++++++++++---------
2 files changed, 56 insertions(+), 49 deletions(-)
diff --git a/packages/carbon-web-components/src/components/slider/slider-input.ts b/packages/carbon-web-components/src/components/slider/slider-input.ts
index ca2ba4f2de9..2ce218dbfe7 100644
--- a/packages/carbon-web-components/src/components/slider/slider-input.ts
+++ b/packages/carbon-web-components/src/components/slider/slider-input.ts
@@ -45,14 +45,13 @@ class CDSSliderInput extends FocusMixin(LitElement) {
* Handles `change` event to fire a normalized custom event.
*/
private _handleChange({ target }: Event) {
- console.log('here 1');
-
+ this.value = Number((target as HTMLInputElement).value);
this.dispatchEvent(
new CustomEvent((this.constructor as typeof CDSSliderInput).eventChange, {
bubbles: true,
composed: true,
detail: {
- value: Number((target as HTMLInputElement).value),
+ value: this.value,
},
})
);
@@ -62,14 +61,13 @@ class CDSSliderInput extends FocusMixin(LitElement) {
* Handles `input` event to fire a normalized custom event.
*/
private _handleInput({ target }: Event) {
- console.log('here 2');
-
+ this.value = Number((target as HTMLInputElement).value);
this.dispatchEvent(
new CustomEvent((this.constructor as typeof CDSSliderInput).eventChange, {
bubbles: true,
composed: true,
detail: {
- value: Number((target as HTMLInputElement).value),
+ value: this.value,
intermediate: true,
},
})
@@ -168,9 +166,8 @@ class CDSSliderInput extends FocusMixin(LitElement) {
_handleChange: handleChange,
_handleInput: handleInput,
} = this;
- console.log('here mainxss');
- console.log('value',value);
-
+ console.log(value,'value');
+
const classes = classMap({
[`${prefix}--text-input`]: true,
[`${prefix}--slider-text-input`]: true,
diff --git a/packages/carbon-web-components/src/components/slider/slider.ts b/packages/carbon-web-components/src/components/slider/slider.ts
index 127b777c96a..edf4bc61982 100644
--- a/packages/carbon-web-components/src/components/slider/slider.ts
+++ b/packages/carbon-web-components/src/components/slider/slider.ts
@@ -216,24 +216,45 @@ class CDSSlider extends HostListenerMixin(FormMixin(FocusMixin(LitElement))) {
})
);
}else{
- const stepCount = (value + diff) / step;
- this.value = Math.min(
- max,
- Math.max(
- min,
- (diff >= 0 ? Math.floor(stepCount) : Math.ceil(stepCount)) * step
- )
- );
- this.dispatchEvent(
- new CustomEvent((this.constructor as typeof CDSSlider).eventChange, {
- bubbles: true,
- composed: true,
- detail: {
- value: this.value,
- intermediate: false,
- },
- })
- );
+ if(eventContainer == 'thumb-upper'){
+ const stepCount = (valueUpper + diff) / step;
+ this.valueUpper = Math.min(
+ max,
+ Math.max(
+ min,
+ (diff >= 0 ? Math.floor(stepCount) : Math.ceil(stepCount)) * step
+ )
+ );
+ this.dispatchEvent(
+ new CustomEvent((this.constructor as typeof CDSSlider).eventChange, {
+ bubbles: true,
+ composed: true,
+ detail: {
+ value: this.valueUpper,
+ intermediate: false,
+ },
+ })
+ );
+ }else{
+ const stepCount = (value + diff) / step;
+ this.value = Math.min(
+ max,
+ Math.max(
+ min,
+ (diff >= 0 ? Math.floor(stepCount) : Math.ceil(stepCount)) * step
+ )
+ );
+ this.dispatchEvent(
+ new CustomEvent((this.constructor as typeof CDSSlider).eventChange, {
+ bubbles: true,
+ composed: true,
+ detail: {
+ value: this.value,
+ intermediate: false,
+ },
+ })
+ );
+ }
}
}
}
@@ -412,32 +433,21 @@ class CDSSlider extends HostListenerMixin(FormMixin(FocusMixin(LitElement))) {
const { detail } = event;
const { intermediate, value } = detail;
if (eventContainer === 'upper') {
- console.log('yes');
-
this.valueUpper = value;
- this.dispatchEvent(
- new CustomEvent((this.constructor as typeof CDSSlider).eventChange, {
- bubbles: true,
- composed: true,
- detail: {
- value: this.valueUpper,
- intermediate,
- },
- })
- );
} else {
this.value = value;
- this.dispatchEvent(
- new CustomEvent((this.constructor as typeof CDSSlider).eventChange, {
- bubbles: true,
- composed: true,
- detail: {
- value,
- intermediate,
- },
- })
- );
}
+ const valueMain = eventContainer === 'upper' ? this.valueUpper : this.value;
+ this.dispatchEvent(
+ new CustomEvent((this.constructor as typeof CDSSlider).eventChange, {
+ bubbles: true,
+ composed: true,
+ detail: {
+ value: valueMain,
+ intermediate,
+ },
+ })
+ );
};
/**
From d3d400401015d3af98e05fcfdd560fc24ee4dcd5 Mon Sep 17 00:00:00 2001
From: Sangeetha Babu <58620134+sangeethababu9223@users.noreply.github.com>
Date: Thu, 22 Feb 2024 17:31:00 +0530
Subject: [PATCH 3/7] feat(slider): support two knobs
---
.../src/components/slider/slider-input.ts | 1 -
.../src/components/slider/slider.ts | 33 +++++--------------
2 files changed, 8 insertions(+), 26 deletions(-)
diff --git a/packages/carbon-web-components/src/components/slider/slider-input.ts b/packages/carbon-web-components/src/components/slider/slider-input.ts
index 2ce218dbfe7..a0dcf603846 100644
--- a/packages/carbon-web-components/src/components/slider/slider-input.ts
+++ b/packages/carbon-web-components/src/components/slider/slider-input.ts
@@ -166,7 +166,6 @@ class CDSSliderInput extends FocusMixin(LitElement) {
_handleChange: handleChange,
_handleInput: handleInput,
} = this;
- console.log(value,'value');
const classes = classMap({
[`${prefix}--text-input`]: true,
diff --git a/packages/carbon-web-components/src/components/slider/slider.ts b/packages/carbon-web-components/src/components/slider/slider.ts
index edf4bc61982..ea9c3675015 100644
--- a/packages/carbon-web-components/src/components/slider/slider.ts
+++ b/packages/carbon-web-components/src/components/slider/slider.ts
@@ -117,7 +117,7 @@ class CDSSlider extends HostListenerMixin(FormMixin(FocusMixin(LitElement))) {
Number(step);
}
/**
- * The rate of the thumb position in the track.
+ * The rate of the upper thumb position in the track.
* When we try to set a new value, we adjust the value considering `step` property.
*/
private get _rateUpper() {
@@ -216,27 +216,7 @@ class CDSSlider extends HostListenerMixin(FormMixin(FocusMixin(LitElement))) {
})
);
}else{
- if(eventContainer == 'thumb-upper'){
- const stepCount = (valueUpper + diff) / step;
- this.valueUpper = Math.min(
- max,
- Math.max(
- min,
- (diff >= 0 ? Math.floor(stepCount) : Math.ceil(stepCount)) * step
- )
- );
- this.dispatchEvent(
- new CustomEvent((this.constructor as typeof CDSSlider).eventChange, {
- bubbles: true,
- composed: true,
- detail: {
- value: this.valueUpper,
- intermediate: false,
- },
- })
- );
- }else{
- const stepCount = (value + diff) / step;
+ const stepCount = (value + diff) / step;
this.value = Math.min(
max,
Math.max(
@@ -254,7 +234,6 @@ class CDSSlider extends HostListenerMixin(FormMixin(FocusMixin(LitElement))) {
},
})
);
- }
}
}
}
@@ -656,9 +635,13 @@ class CDSSlider extends HostListenerMixin(FormMixin(FocusMixin(LitElement))) {
}
if (input) {
if (this.valueUpper && index > 0) {
- ['max', 'min', 'step', 'value'].forEach((name) => {
+ ['max', 'min', 'step', 'valueUpper'].forEach((name) => {
if (changedProperties.has(name)) {
- input[name] = name === 'value' ? this.valueUpper : this[name];
+ if(name === 'valueUpper'){
+ input.value = this.valueUpper
+ }else{
+ this[name]
+ }
}
});
} else {
From 9ba98bdfe07648de22294c04dc8ae7663034a5d4 Mon Sep 17 00:00:00 2001
From: Sangeetha Babu <58620134+sangeethababu9223@users.noreply.github.com>
Date: Mon, 26 Feb 2024 14:30:47 +0530
Subject: [PATCH 4/7] feat(slider): update slider functionality for two knobs
---
.../src/components/slider/slider-story.ts | 2 +-
.../src/components/slider/slider.ts | 74 +++++++++++++------
2 files changed, 53 insertions(+), 23 deletions(-)
diff --git a/packages/carbon-web-components/src/components/slider/slider-story.ts b/packages/carbon-web-components/src/components/slider/slider-story.ts
index 136b3adecee..c302ac6c02b 100644
--- a/packages/carbon-web-components/src/components/slider/slider-story.ts
+++ b/packages/carbon-web-components/src/components/slider/slider-story.ts
@@ -128,7 +128,7 @@ export const TwoHandleSlider = () => {
+ id="lower" slot="lower-input">
this.value ? position - this.value : this.value - position;
+ const differenceValueUpper = position > this.valueUpper ? position - this.valueUpper : this.valueUpper - position;
+ differenceValue > differenceValueUpper ? this._rateUpper = position/100 : this._rate = position/100;
+ this.dispatchEvent(
+ new CustomEvent((this.constructor as typeof CDSSlider).eventChange, {
+ bubbles: true,
+ composed: true,
+ detail: {
+ value: this.value,
+ },
+ })
+ );
+
+ }
}
}
}
@@ -636,18 +656,24 @@ class CDSSlider extends HostListenerMixin(FormMixin(FocusMixin(LitElement))) {
if (input) {
if (this.valueUpper && index > 0) {
['max', 'min', 'step', 'valueUpper'].forEach((name) => {
- if (changedProperties.has(name)) {
- if(name === 'valueUpper'){
- input.value = this.valueUpper
- }else{
- this[name]
- }
+ if(name === 'valueUpper'){
+ input.value = this.valueUpper
+ }else if(name === 'min'){
+ input[name] = this.value;
+ }
+ else{
+ this[name]
}
+
});
} else {
['max', 'min', 'step', 'value'].forEach((name) => {
if (changedProperties.has(name)) {
- input[name] = this[name];
+ if(this.valueUpper && name === 'max'){
+ input[name] = this.valueUpper;
+ }else{
+ input[name] = this[name];
+ }
}
});
}
@@ -720,6 +746,10 @@ class CDSSlider extends HostListenerMixin(FormMixin(FocusMixin(LitElement))) {
${labelText}
+ ${valueUpper ?
+ html `
+
`
+ : '' }
${formatMinText(min, minLabel)}
From ddd82ff843be0bd27a9f69bec7c7c333687421b6 Mon Sep 17 00:00:00 2001
From: Sangeetha Babu <58620134+sangeethababu9223@users.noreply.github.com>
Date: Mon, 26 Feb 2024 14:40:09 +0530
Subject: [PATCH 5/7] feat(slider): fomat files
---
.../src/components/slider/slider-input.ts | 2 +-
.../src/components/slider/slider-story.ts | 3 +-
.../src/components/slider/slider.ts | 140 ++++++++++--------
3 files changed, 81 insertions(+), 64 deletions(-)
diff --git a/packages/carbon-web-components/src/components/slider/slider-input.ts b/packages/carbon-web-components/src/components/slider/slider-input.ts
index a0dcf603846..27e60ce4e66 100644
--- a/packages/carbon-web-components/src/components/slider/slider-input.ts
+++ b/packages/carbon-web-components/src/components/slider/slider-input.ts
@@ -166,7 +166,7 @@ class CDSSliderInput extends FocusMixin(LitElement) {
_handleChange: handleChange,
_handleInput: handleInput,
} = this;
-
+
const classes = classMap({
[`${prefix}--text-input`]: true,
[`${prefix}--slider-text-input`]: true,
diff --git a/packages/carbon-web-components/src/components/slider/slider-story.ts b/packages/carbon-web-components/src/components/slider/slider-story.ts
index c302ac6c02b..f74fba7317e 100644
--- a/packages/carbon-web-components/src/components/slider/slider-story.ts
+++ b/packages/carbon-web-components/src/components/slider/slider-story.ts
@@ -128,7 +128,8 @@ export const TwoHandleSlider = () => {
+ id="lower"
+ slot="lower-input">
= 0 ? Math.floor(stepCount) : Math.ceil(stepCount)) * step
- )
- );
- this.dispatchEvent(
- new CustomEvent((this.constructor as typeof CDSSlider).eventChange, {
+ // Snaps to next
+ if (eventContainer == 'thumb-upper') {
+ const stepCount = (valueUpper + diff) / step;
+ this.valueUpper = Math.min(
+ max,
+ Math.max(
+ min,
+ (diff >= 0 ? Math.floor(stepCount) : Math.ceil(stepCount)) * step
+ )
+ );
+ this.dispatchEvent(
+ new CustomEvent(
+ (this.constructor as typeof CDSSlider).eventChange,
+ {
bubbles: true,
composed: true,
detail: {
value: this.valueUpper,
intermediate: false,
},
- })
- );
- }else{
+ }
+ )
+ );
+ } else {
const stepCount = (value + diff) / step;
- this.value = Math.min(
- max,
- Math.max(
- min,
- (diff >= 0 ? Math.floor(stepCount) : Math.ceil(stepCount)) * step
- )
- );
- this.dispatchEvent(
- new CustomEvent((this.constructor as typeof CDSSlider).eventChange, {
+ this.value = Math.min(
+ max,
+ Math.max(
+ min,
+ (diff >= 0 ? Math.floor(stepCount) : Math.ceil(stepCount)) * step
+ )
+ );
+ this.dispatchEvent(
+ new CustomEvent(
+ (this.constructor as typeof CDSSlider).eventChange,
+ {
bubbles: true,
composed: true,
detail: {
value: this.value,
intermediate: false,
},
- })
- );
+ }
+ )
+ );
}
}
}
@@ -281,39 +287,54 @@ class CDSSlider extends HostListenerMixin(FormMixin(FocusMixin(LitElement))) {
},
})
);
- } else{
- if(!this.valueUpper){
+ } else {
+ if (!this.valueUpper) {
this._rate =
(isRtl
? trackLeft + trackWidth - thumbPosition
: thumbPosition - trackLeft) / trackWidth;
this.dispatchEvent(
- new CustomEvent((this.constructor as typeof CDSSlider).eventChange, {
- bubbles: true,
- composed: true,
- detail: {
- value: this.value,
- },
- })
+ new CustomEvent(
+ (this.constructor as typeof CDSSlider).eventChange,
+ {
+ bubbles: true,
+ composed: true,
+ detail: {
+ value: this.value,
+ },
+ }
+ )
);
- }else{
+ } else {
const position =
((isRtl
? trackLeft + trackWidth - thumbPosition
- : thumbPosition - trackLeft) / trackWidth)*100;
- const differenceValue = position > this.value ? position - this.value : this.value - position;
- const differenceValueUpper = position > this.valueUpper ? position - this.valueUpper : this.valueUpper - position;
- differenceValue > differenceValueUpper ? this._rateUpper = position/100 : this._rate = position/100;
+ : thumbPosition - trackLeft) /
+ trackWidth) *
+ 100;
+ const differenceValue =
+ position > this.value
+ ? position - this.value
+ : this.value - position;
+ const differenceValueUpper =
+ position > this.valueUpper
+ ? position - this.valueUpper
+ : this.valueUpper - position;
+ differenceValue > differenceValueUpper
+ ? (this._rateUpper = position / 100)
+ : (this._rate = position / 100);
this.dispatchEvent(
- new CustomEvent((this.constructor as typeof CDSSlider).eventChange, {
- bubbles: true,
- composed: true,
- detail: {
- value: this.value,
- },
- })
+ new CustomEvent(
+ (this.constructor as typeof CDSSlider).eventChange,
+ {
+ bubbles: true,
+ composed: true,
+ detail: {
+ value: this.value,
+ },
+ }
+ )
);
-
}
}
}
@@ -656,22 +677,20 @@ class CDSSlider extends HostListenerMixin(FormMixin(FocusMixin(LitElement))) {
if (input) {
if (this.valueUpper && index > 0) {
['max', 'min', 'step', 'valueUpper'].forEach((name) => {
- if(name === 'valueUpper'){
- input.value = this.valueUpper
- }else if(name === 'min'){
+ if (name === 'valueUpper') {
+ input.value = this.valueUpper;
+ } else if (name === 'min') {
input[name] = this.value;
+ } else {
+ this[name];
}
- else{
- this[name]
- }
-
});
} else {
['max', 'min', 'step', 'value'].forEach((name) => {
if (changedProperties.has(name)) {
- if(this.valueUpper && name === 'max'){
+ if (this.valueUpper && name === 'max') {
input[name] = this.valueUpper;
- }else{
+ } else {
input[name] = this[name];
}
}
@@ -746,10 +765,7 @@ class CDSSlider extends HostListenerMixin(FormMixin(FocusMixin(LitElement))) {
${labelText}
- ${valueUpper ?
- html `
-
`
- : '' }
+ ${valueUpper ? html`
` : ''}
${formatMinText(min, minLabel)}
From 30767a7d71ed15d06112d0c713c09df589baec5c Mon Sep 17 00:00:00 2001
From: Sangeetha Babu <58620134+sangeethababu9223@users.noreply.github.com>
Date: Wed, 28 Feb 2024 15:20:04 +0530
Subject: [PATCH 6/7] feat(slider): hadnle style and function update
---
.../src/components/slider/slider-input.ts | 1 -
.../src/components/slider/slider-story.ts | 6 +-
.../src/components/slider/slider.scss | 2 +-
.../src/components/slider/slider.ts | 178 ++++++++++++++----
4 files changed, 142 insertions(+), 45 deletions(-)
diff --git a/packages/carbon-web-components/src/components/slider/slider-input.ts b/packages/carbon-web-components/src/components/slider/slider-input.ts
index 27e60ce4e66..b149043d197 100644
--- a/packages/carbon-web-components/src/components/slider/slider-input.ts
+++ b/packages/carbon-web-components/src/components/slider/slider-input.ts
@@ -166,7 +166,6 @@ class CDSSliderInput extends FocusMixin(LitElement) {
_handleChange: handleChange,
_handleInput: handleInput,
} = this;
-
const classes = classMap({
[`${prefix}--text-input`]: true,
[`${prefix}--slider-text-input`]: true,
diff --git a/packages/carbon-web-components/src/components/slider/slider-story.ts b/packages/carbon-web-components/src/components/slider/slider-story.ts
index f74fba7317e..dd59723f7d4 100644
--- a/packages/carbon-web-components/src/components/slider/slider-story.ts
+++ b/packages/carbon-web-components/src/components/slider/slider-story.ts
@@ -123,15 +123,15 @@ export const TwoHandleSlider = () => {
max="100"
min="0"
step="1"
- value="50"
+ value="10"
value-upper="90">
diff --git a/packages/carbon-web-components/src/components/slider/slider.scss b/packages/carbon-web-components/src/components/slider/slider.scss
index f4ef412b652..1e580f356e6 100644
--- a/packages/carbon-web-components/src/components/slider/slider.scss
+++ b/packages/carbon-web-components/src/components/slider/slider.scss
@@ -33,7 +33,7 @@ $css--plex: true !default;
transform: translate(-50%, -50%) #{'/*rtl:ignore*/'};
}
-
+
.#{$prefix}--slider__thumb:focus
~ .#{$prefix}-ce--slider__filled-track-container
.#{$prefix}--slider__filled-track {
diff --git a/packages/carbon-web-components/src/components/slider/slider.ts b/packages/carbon-web-components/src/components/slider/slider.ts
index cf852487b37..f37816b19d1 100644
--- a/packages/carbon-web-components/src/components/slider/slider.ts
+++ b/packages/carbon-web-components/src/components/slider/slider.ts
@@ -198,13 +198,16 @@ class CDSSlider extends HostListenerMixin(FormMixin(FocusMixin(LitElement))) {
// Snaps to next
if (eventContainer == 'thumb-upper') {
const stepCount = (valueUpper + diff) / step;
- this.valueUpper = Math.min(
+ const position = Math.min(
max,
Math.max(
min,
(diff >= 0 ? Math.floor(stepCount) : Math.ceil(stepCount)) * step
)
);
+ if (position >= this.value) {
+ this.valueUpper = position;
+ }
this.dispatchEvent(
new CustomEvent(
(this.constructor as typeof CDSSlider).eventChange,
@@ -220,13 +223,16 @@ class CDSSlider extends HostListenerMixin(FormMixin(FocusMixin(LitElement))) {
);
} else {
const stepCount = (value + diff) / step;
- this.value = Math.min(
+ const position = Math.min(
max,
Math.max(
min,
(diff >= 0 ? Math.floor(stepCount) : Math.ceil(stepCount)) * step
)
);
+ if (!this.valueUpper || position <= this.valueUpper) {
+ this.value = position;
+ }
this.dispatchEvent(
new CustomEvent(
(this.constructor as typeof CDSSlider).eventChange,
@@ -249,7 +255,17 @@ class CDSSlider extends HostListenerMixin(FormMixin(FocusMixin(LitElement))) {
* Handles `pointerdown` event on the thumb to start dragging.
*/
private _startDrag(event: PointerEvent) {
- const eventContainer = (event.target as HTMLElement).id;
+ let eventContainer = (event.target as HTMLElement).id;
+ if (!eventContainer) {
+ const element = (event.target as HTMLInputElement).nodeName;
+ if (element == 'path' || element == 'svg') {
+ eventContainer = (
+ (
+ (event.target as HTMLInputElement).parentElement as HTMLElement
+ ).closest('.cds--slider__thumb-wrapper') as HTMLInputElement
+ ).id;
+ }
+ }
if (eventContainer === 'thumb') {
this._dragging = true;
this._thumbNode.style.touchAction = 'none';
@@ -263,7 +279,17 @@ class CDSSlider extends HostListenerMixin(FormMixin(FocusMixin(LitElement))) {
* Handles `pointerdown` event on the track to update the thumb position and the value as necessary.
*/
private _handleClick(event: PointerEvent) {
- const eventContainer = (event.target as HTMLInputElement).id;
+ let eventContainer = (event.target as HTMLInputElement).id;
+ if (!eventContainer) {
+ const element = (event.target as HTMLInputElement).nodeName;
+ if (element == 'path' || element == 'svg') {
+ eventContainer = (
+ (
+ (event.target as HTMLInputElement).parentElement as HTMLElement
+ ).closest('.cds--slider__thumb-wrapper') as HTMLInputElement
+ ).id;
+ }
+ }
if (!this.disabled) {
const { _trackNode: trackNode } = this;
const isRtl =
@@ -320,9 +346,19 @@ class CDSSlider extends HostListenerMixin(FormMixin(FocusMixin(LitElement))) {
position > this.valueUpper
? position - this.valueUpper
: this.valueUpper - position;
- differenceValue > differenceValueUpper
- ? (this._rateUpper = position / 100)
- : (this._rate = position / 100);
+ if (differenceValue > differenceValueUpper) {
+ this._rateUpper = position / 100;
+ } else if (differenceValue < differenceValueUpper) {
+ this._rate = position / 100;
+ } else if (
+ !this._dragging &&
+ !this._draggingUpper &&
+ differenceValue === differenceValueUpper
+ ) {
+ Math.round(position) > this.valueUpper
+ ? (this._rateUpper = position / 100)
+ : (this._rate = position / 100);
+ }
this.dispatchEvent(
new CustomEvent(
(this.constructor as typeof CDSSlider).eventChange,
@@ -379,35 +415,47 @@ class CDSSlider extends HostListenerMixin(FormMixin(FocusMixin(LitElement))) {
const { left: trackLeft, width: trackWidth } =
this._trackNode.getBoundingClientRect();
if (dragging) {
- this._rate =
+ const position =
(isRtl
? trackLeft + trackWidth - thumbPosition
: thumbPosition - trackLeft) / trackWidth;
- this.dispatchEvent(
- new CustomEvent((this.constructor as typeof CDSSlider).eventChange, {
- bubbles: true,
- composed: true,
- detail: {
- value: this.value,
- intermediate: true,
- },
- })
- );
+ if (!this.valueUpper || position * 100 <= this.valueUpper) {
+ this._rate = position;
+ this.dispatchEvent(
+ new CustomEvent(
+ (this.constructor as typeof CDSSlider).eventChange,
+ {
+ bubbles: true,
+ composed: true,
+ detail: {
+ value: this.value,
+ intermediate: true,
+ },
+ }
+ )
+ );
+ }
} else if (draggingUpper) {
- this._rateUpper =
+ const position =
(isRtl
? trackLeft + trackWidth - thumbPosition
: thumbPosition - trackLeft) / trackWidth;
- this.dispatchEvent(
- new CustomEvent((this.constructor as typeof CDSSlider).eventChange, {
- bubbles: true,
- composed: true,
- detail: {
- value: this.valueUpper,
- intermediate: true,
- },
- })
- );
+ if (position * 100 >= this.value) {
+ this._rateUpper = position;
+ this.dispatchEvent(
+ new CustomEvent(
+ (this.constructor as typeof CDSSlider).eventChange,
+ {
+ bubbles: true,
+ composed: true,
+ detail: {
+ value: this.valueUpper,
+ intermediate: true,
+ },
+ }
+ )
+ );
+ }
}
}
}
@@ -687,12 +735,10 @@ class CDSSlider extends HostListenerMixin(FormMixin(FocusMixin(LitElement))) {
});
} else {
['max', 'min', 'step', 'value'].forEach((name) => {
- if (changedProperties.has(name)) {
- if (this.valueUpper && name === 'max') {
- input[name] = this.valueUpper;
- } else {
- input[name] = this[name];
- }
+ if (this.valueUpper && name === 'max') {
+ input[name] = this.valueUpper;
+ } else {
+ input[name] = this[name];
}
});
}
@@ -779,33 +825,85 @@ class CDSSlider extends HostListenerMixin(FormMixin(FocusMixin(LitElement))) {
role="presentation">
+ @pointerdown="${startDrag}">
+ ${valueUpper
+ ? html`
+
+ `
+ : ``}
+
${valueUpper
? html`
+ @pointerdown="${startDrag}">
+
+
`
: html``}
+ style="transform: ${valueUpper
+ ? `translate(${rate * 100}%, -50%) scaleX(${rateUpper - rate})`
+ : `translate(0%, -50%) scaleX(${rate})`}">