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

fix(slider): fix slider (single-value) error when clicking range #5533

Merged
merged 1 commit into from
Oct 20, 2022
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
54 changes: 54 additions & 0 deletions src/components/slider/slider.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,60 @@ describe("calcite-slider", () => {
expect(changeEvent).toHaveReceivedEventTimes(1);
});

describe("thumb focus for single value", () => {
const sliderForThumbFocusTests = html`<calcite-slider
style="width:${sliderWidthFor1To1PixelValueTrack}"
min="0"
max="100"
snap
ticks="10"
value="50"
></calcite-slider>`;

it("should focus thumb when clicked near", async () => {
const page = await newE2EPage();
await page.setContent(html`${sliderForThumbFocusTests}`);
const slider = await page.find("calcite-slider");
const [trackX, trackY] = await getElementXY(page, "calcite-slider", ".track");

await page.mouse.move(trackX + 50, trackY);
await page.mouse.down();
await page.mouse.up();
await page.waitForChanges();

let isThumbFocused = await page.$eval("calcite-slider", (slider) =>
slider.shadowRoot.activeElement?.classList.contains("thumb--value")
);

expect(isThumbFocused).toBe(true);
expect(await slider.getProperty("value")).toBe(50);

await page.mouse.move(trackX + 40, trackY);
await page.mouse.down();
await page.mouse.up();
await page.waitForChanges();

isThumbFocused = await page.$eval("calcite-slider", (slider) =>
slider.shadowRoot.activeElement?.classList.contains("thumb--value")
);

expect(isThumbFocused).toBe(true);
expect(await slider.getProperty("value")).toBe(40);

await page.mouse.move(trackX + 60, trackY);
await page.mouse.down();
await page.mouse.up();
await page.waitForChanges();

isThumbFocused = await page.$eval("calcite-slider", (slider) =>
slider.shadowRoot.activeElement?.classList.contains("thumb--value")
);

expect(isThumbFocused).toBe(true);
expect(await slider.getProperty("value")).toBe(60);
});
});

describe("thumb focus in range", () => {
const sliderForThumbFocusTests = html`<calcite-slider
style="width:${sliderWidthFor1To1PixelValueTrack}"
Expand Down
7 changes: 4 additions & 3 deletions src/components/slider/slider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,6 @@ export class Slider
@Listen("pointerdown")
pointerDownHandler(event: PointerEvent): void {
const x = event.clientX || event.pageX;
this.focusActiveHandle(x);
const position = this.translate(x);
let prop: ActiveSliderProperty = "value";
if (isRange(this.value)) {
Expand All @@ -848,6 +847,7 @@ export class Slider
if (!isThumbActive) {
this.setValue(prop, this.clamp(position, prop));
}
this.focusActiveHandle(x);
}

handleTouchStart(event: TouchEvent): void {
Expand Down Expand Up @@ -913,6 +913,8 @@ export class Slider

defaultValue: Slider["value"];

private activeProp: ActiveSliderProperty = "value";

private guid = `calcite-slider-${guid()}`;

private dragProp: ActiveSliderProperty;
Expand All @@ -929,8 +931,6 @@ export class Slider

@State() effectiveLocale = "";

@State() private activeProp: ActiveSliderProperty = "value";

@State() private minMaxValueRange: number = null;

@State() private minValueDragRange: number = null;
Expand Down Expand Up @@ -1004,6 +1004,7 @@ export class Slider
this.minHandle.focus();
break;
case "maxValue":
case "value":
this.maxHandle.focus();
break;
case "minMaxValue":
Expand Down