Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
41 changes: 32 additions & 9 deletions packages/calcite-components/src/components/slider/slider.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -658,15 +658,15 @@ describe("calcite-slider", () => {

it("does not allow text selection when slider is used", async () => {
const page = await newE2EPage({
html: `<calcite-slider
value="30"
label-handles
label-ticks
max-label="100"
ticks="10"
min="0"
max="100"
value="50"
html: `<calcite-slider
value="30"
label-handles
label-ticks
max-label="100"
ticks="10"
min="0"
max="100"
value="50"
step="1"
>
</calcite-slider>`,
Expand Down Expand Up @@ -736,6 +736,7 @@ describe("calcite-slider", () => {
let changeEvent: EventSpy;
let inputEvent: EventSpy;
let element: E2EElement;
let handleRect: DOMRect;
let trackRect: DOMRect;

const commonSliderAttrs = `
Expand All @@ -760,6 +761,7 @@ describe("calcite-slider", () => {
await page.setContent(html`<calcite-slider ${sliderAttrs}></calcite-slider>`);

element = await page.find("calcite-slider");
handleRect = await getElementRect(page, "calcite-slider", `.${CSS.handle}`);
trackRect = await getElementRect(page, "calcite-slider", `.${CSS.track}`);
changeEvent = await element.spyOnEvent("calciteSliderChange");
inputEvent = await element.spyOnEvent("calciteSliderInput");
Expand Down Expand Up @@ -825,6 +827,27 @@ describe("calcite-slider", () => {
expect(isMinThumbFocused).toBe(true);
await assertValuesUnchanged(expectedValue);
});

it("pressing mouse down on right side of handle and dragging towards the left shifts drag to the min handle", async () => {
await setUpTest(`${commonSliderAttrs} min-value="${expectedValue}" max-value="${expectedValue}"`);

await assertValuesUnchanged(expectedValue);

const initialMinValue = expectedValue;
const rightHalfOfHandleCircleDragTarget = handleRect.x + handleRect.width - 2;

await page.mouse.move(rightHalfOfHandleCircleDragTarget, handleRect.y);
await page.mouse.down();
await page.mouse.move(rightHalfOfHandleCircleDragTarget - 10, handleRect.y);
await page.mouse.up();
await page.waitForChanges();

const isMinHandleFocused = await isElementFocused(page, `.${CSS.thumbMinValue}`, { shadowed: true });

expect(isMinHandleFocused).toBe(true);
const newMinValue = await element.getProperty("value")[0];
expect(newMinValue).not.toBe(initialMinValue);
});
});
});

Expand Down
19 changes: 19 additions & 0 deletions packages/calcite-components/src/components/slider/slider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,21 @@ export class Slider
this.maxValueDragRange = this.maxValue - value;
this.minMaxValueRange = this.maxValue - this.minValue;
}
} else if (
isRange(this.value) &&
isRange(this.previousEmittedValue) &&
this.dragProp === "maxValue"
) {
const [previousEmittedMinValue, previousEmittedMaxValue] = this.previousEmittedValue;
if (
previousEmittedMinValue === previousEmittedMaxValue &&
value < previousEmittedMinValue
) {
this.dragProp = "minValue";
this.minHandle.focus();
} else {
this.setValue({ [this.dragProp as SetValueProperty]: this.clamp(value, this.dragProp) });
}
} else {
this.setValue({ [this.dragProp as SetValueProperty]: this.clamp(value, this.dragProp) });
}
Expand Down Expand Up @@ -159,6 +174,8 @@ export class Slider
this.dragEnd(event);
};

private previousEmittedValue;

private trackEl: HTMLDivElement;

// #endregion
Expand Down Expand Up @@ -368,6 +385,7 @@ export class Slider
this.setValueFromMinMax();
connectLabel(this);
connectForm(this);
this.previousEmittedValue = this.value;
}

load(): void {
Expand Down Expand Up @@ -639,6 +657,7 @@ export class Slider

private emitChange(): void {
this.calciteSliderChange.emit();
this.previousEmittedValue = this.value;
}

private removeDragListeners() {
Expand Down
Loading