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

chore(slider): slider handle alignment fix #3860

Merged
merged 11 commits into from
Dec 12, 2023
4 changes: 1 addition & 3 deletions packages/slider/src/HandleController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -493,10 +493,8 @@ export class HandleController {
[this.host.isLTR ? 'left' : 'right']: `${
model.normalizedValue * 100
}%`,
right: 'auto',
'z-index': zIndex.toString(),
// Allow setting background per-handle
Rajdeepc marked this conversation as resolved.
Show resolved Hide resolved
'background-color': `var(--spectrum-slider-handle-background-color-${index}, var(--spectrum-slider-handle-background-color))`,
'border-color': `var(--spectrum-slider-handle-border-color-${index}, var(--spectrum-slider-handle-border-color))`,
};
const ariaLabelledBy = isMultiHandle ? `label input-${index}` : 'label';
return html`
Expand Down
26 changes: 18 additions & 8 deletions packages/slider/src/Slider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,12 +350,12 @@ export class Slider extends SizedMixin(ObserveSlotText(SliderHandle, ''), {

private renderTrack(): TemplateResult {
const segments = this.handleController.trackSegments();

const handleItems = [
{ id: 'handles', html: this.handleController.render() },
];
const trackItems = [
{ id: 'track0', html: this.renderTrackSegment(...segments[0]) },
{ id: 'ramp', html: this.renderRamp() },
{ id: 'ticks', html: this.renderTicks() },
{ id: 'handles', html: this.handleController.render() },
...segments.slice(1).map(([start, end], index) => ({
id: `track${index + 1}`,
html: this.renderTrackSegment(start, end),
Expand All @@ -375,11 +375,21 @@ export class Slider extends SizedMixin(ObserveSlotText(SliderHandle, ''), {
})}
>
<div id="controls">
${repeat(
trackItems,
(item) => item.id,
(item) => item.html
)}
${this.renderTicks()}
<div class="trackContainer">
${repeat(
trackItems,
(item) => item.id,
(item) => item.html
)}
</div>
<div class="handleContainer">
${repeat(
handleItems,
(item) => item.id,
(item) => item.html
)}
</div>
</div>
</div>
`;
Expand Down
8 changes: 8 additions & 0 deletions packages/slider/src/spectrum-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,14 @@ const config = {
'tickLabel'
),
converter.classToClass('spectrum-Slider-ticks', 'ticks'),
converter.classToClass(
'spectrum-Slider-trackContainer',
'trackContainer'
),
converter.classToClass(
'spectrum-Slider-handleContainer',
'handleContainer'
),
converter.classToClass('spectrum-Slider-track', 'track'),
converter.classToClass('is-focused', 'handle-highlight'),
converter.classToClass('is-dragged', 'dragging'),
Expand Down
8 changes: 4 additions & 4 deletions packages/slider/src/spectrum-slider.css
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ governing permissions and limitations under the License.
);
z-index: 0;
}
.ticks ~ .spectrum-Slider-handleContainer .handle {
.ticks ~ .handleContainer .handle {
background: var(
--mod-slider-ticks-handle-background-color,
var(--spectrum-slider-ticks-handle-background-color)
Copy link
Contributor

Choose a reason for hiding this comment

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

This value doesn't seem to be available, yet:
image
Vs the CSS implementation:
image
See the "tick" sticking through.

Do we maybe need to update @spectrum-css/tokens as part of this change? Or report missing values back to CSS?

Copy link
Contributor Author

@Rajdeepc Rajdeepc Dec 11, 2023

Choose a reason for hiding this comment

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

background color property in handleController.ts was overriding the tick css. Should be solved now

Expand Down Expand Up @@ -713,14 +713,14 @@ governing permissions and limitations under the License.
)
);
}
.spectrum-Slider-handleContainer,
.spectrum-Slider-trackContainer {
.handleContainer,
.trackContainer {
inline-size: calc(100% + var(--spectrum-slider-handle-size));
inset-block-start: 0;
margin-inline-start: calc(var(--spectrum-slider-handle-size) / 2 * -1);
position: absolute;
}
.spectrum-Slider-trackContainer {
.trackContainer {
block-size: var(
--mod-slider-control-height,
var(--spectrum-slider-control-height)
Expand Down
Loading