Skip to content
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

feat(slider): resolve parity issue two handle feature #18394

Draft
wants to merge 16 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat(slider): support two knobs
  • Loading branch information
sangeethababu9223 committed Jan 7, 2025
commit 64418bf8206ca44b28f9f0e4c8a75dcc4e20b820
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ class CDSSliderInput extends FocusMixin(LitElement) {
_handleChange: handleChange,
_handleInput: handleInput,
} = this;
console.log(value, 'value');

const classes = classMap({
[`${prefix}--text-input`]: true,
[`${prefix}--slider-text-input`]: true,
Expand Down
78 changes: 28 additions & 50 deletions packages/web-components/src/components/slider/slider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -219,53 +219,27 @@ 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;
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,
},
}
)
);
}
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,
},
}
)
);
}
}
}
Expand Down Expand Up @@ -667,9 +641,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 {
Expand Down