Skip to content

fix(slider): slider handle aligns with track when font size changes #5372

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

Merged
merged 18 commits into from
Feb 16, 2023
Merged
Show file tree
Hide file tree
Changes from 15 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
1 change: 0 additions & 1 deletion src/components/slider/slider.scss
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@
bg-transparent
p-0
outline-none;
transform: translate(var(--calcite-slider-thumb-x-offset), var(--calcite-slider-thumb-y-offset));

.handle__label {
&.static,
Expand Down
16 changes: 16 additions & 0 deletions src/components/slider/slider.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,3 +279,19 @@ export const wordBreakDoesNotAffectLabels_TestOnly = (): string =>
></calcite-slider>`;

export const WithLabelHandlesAndNoValue_TestOnly = (): string => html` <calcite-slider max="750"></calcite-slider> `;

export const WithLargeFontSize_TestOnly = (): string => html`<html lang="en">
<head>
<style>
html {
font-size: 20px;
}
</style>
</head>
<body>
<div style="width: 400px; height: 400px ; padding : 10px">
<calcite-slider label-handles min-value="50" max-value="70" range></calcite-slider>
<calcite-slider label-handles value="70"></calcite-slider>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we add all types of slider's available to users in this test?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ended up adding more slider variants in a single test. This can be hard to maintain in terms of updating the test but adds value in identifying regression for larger font-size.

<div style="width: 400px; height: 400px">
</body>
</html>`;
47 changes: 31 additions & 16 deletions src/components/slider/slider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,6 @@ export class Slider
}
}

componentDidLoad(): void {
setComponentLoaded(this);
}

componentDidRender(): void {
if (this.labelHandles) {
this.adjustHostObscuredHandleLabel("value");
Expand All @@ -242,6 +238,11 @@ export class Slider
updateHostInteraction(this);
}

componentDidLoad(): void {
setComponentLoaded(this);
this.setHandlePosition();
}

render(): VNode {
const id = this.el.id || this.guid;
const maxProp = isRange(this.value) ? "maxValue" : "value";
Expand Down Expand Up @@ -280,7 +281,7 @@ export class Slider
style={{ right: rightThumbOffset }}
tabIndex={0}
>
<div class="handle" />
<div class="handle" ref={(el) => (this.handleEl = el as HTMLDivElement)} />
</div>
);

Expand Down Expand Up @@ -314,7 +315,7 @@ export class Slider
<span aria-hidden="true" class={`${handleLabelValueClasses} transformed`}>
{displayedValue}
</span>
<div class="handle" />
<div class="handle" ref={(el) => (this.handleEl = el as HTMLDivElement)} />
</div>
);

Expand All @@ -339,7 +340,7 @@ export class Slider
style={{ right: rightThumbOffset }}
tabIndex={0}
>
<div class="handle" />
<div class="handle" ref={(el) => (this.handleEl = el as HTMLDivElement)} />
<span aria-hidden="true" class={handleLabelValueClasses}>
{displayedValue}
</span>
Expand Down Expand Up @@ -374,7 +375,7 @@ export class Slider
style={{ right: rightThumbOffset }}
tabIndex={0}
>
<div class="handle" />
<div class="handle" ref={(el) => (this.handleEl = el as HTMLDivElement)} />
<div class="handle-extension" />
</div>
);
Expand Down Expand Up @@ -402,7 +403,7 @@ export class Slider
tabIndex={0}
>
<div class="handle-extension" />
<div class="handle" />
<div class="handle" ref={(el) => (this.handleEl = el as HTMLDivElement)} />
</div>
);

Expand Down Expand Up @@ -437,7 +438,7 @@ export class Slider
<span aria-hidden="true" class={`${handleLabelValueClasses} transformed`}>
{displayedValue}
</span>
<div class="handle" />
<div class="handle" ref={(el) => (this.handleEl = el as HTMLDivElement)} />
<div class="handle-extension" />
</div>
);
Expand Down Expand Up @@ -465,7 +466,7 @@ export class Slider
tabIndex={0}
>
<div class="handle-extension" />
<div class="handle" />
<div class="handle" ref={(el) => (this.handleEl = el as HTMLDivElement)} />
<span aria-hidden="true" class={handleLabelValueClasses}>
{displayedValue}
</span>
Expand Down Expand Up @@ -499,7 +500,7 @@ export class Slider
style={{ left: leftThumbOffset }}
tabIndex={0}
>
<div class="handle" />
<div class="handle" ref={(el) => (this.handleEl = el as HTMLDivElement)} />
</div>
);

Expand Down Expand Up @@ -533,7 +534,7 @@ export class Slider
<span aria-hidden="true" class={`${handleLabelMinValueClasses} transformed`}>
{displayedMinValue}
</span>
<div class="handle" />
<div class="handle" ref={(el) => (this.handleEl = el as HTMLDivElement)} />
</div>
);

Expand All @@ -558,7 +559,7 @@ export class Slider
style={{ left: leftThumbOffset }}
tabIndex={0}
>
<div class="handle" />
<div class="handle" ref={(el) => (this.handleEl = el as HTMLDivElement)} />
<span aria-hidden="true" class={handleLabelMinValueClasses}>
{displayedMinValue}
</span>
Expand Down Expand Up @@ -594,7 +595,7 @@ export class Slider
tabIndex={0}
>
<div class="handle-extension" />
<div class="handle" />
<div class="handle" ref={(el) => (this.handleEl = el as HTMLDivElement)} />
</div>
);

Expand All @@ -621,7 +622,7 @@ export class Slider
tabIndex={0}
>
<div class="handle-extension" />
<div class="handle" />
<div class="handle" ref={(el) => (this.handleEl = el as HTMLDivElement)} />
<span aria-hidden="true" class={handleLabelMinValueClasses}>
{displayedMinValue}
</span>
Expand Down Expand Up @@ -949,6 +950,8 @@ export class Slider

private trackEl: HTMLDivElement;

private handleEl: HTMLDivElement;

@State() effectiveLocale = "";

@State() private minMaxValueRange: number = null;
Expand Down Expand Up @@ -1493,4 +1496,16 @@ export class Slider
return numberStringFormatter.localize(value.toString());
}
};

private setHandlePosition(): void {
const { y: handleY, width: handleWidth } = this.handleEl.getBoundingClientRect();
console.log(handleY, handleWidth);
const adjustedHandleY = `-${
handleY - this.trackEl.getBoundingClientRect().y + handleWidth / 2
}px)`;
if (isRange(this.value)) {
this.minHandle.style.transform = `translate( calc(var(--calcite-slider-thumb-x-offset)*-1), ${adjustedHandleY}`;
}
this.maxHandle.style.transform = `translate(var(--calcite-slider-thumb-x-offset),${adjustedHandleY}`;
}
}