Skip to content

Conversation

@lazd
Copy link
Member

@lazd lazd commented Oct 8, 2021

Description

This PR adds two optional containers to contain the tracks and the handle, making handles align with all ticks most of the time (different sizes and positions of ticks are subject to off-by-one errors, but it's much closer than before). It also fixes the position of the first and last ticks, which were off by 1px.

Finally, it adds some JS to update the value of the slider in the docs on drag and restricts slider values to whole numbers.

Fixes #927

How and where has this been tested?

  • How this was tested: I poked it
  • Browser(s) and OS(s) this was tested with: Chrome on macOS

Screenshots

100%
image

75%
image

50%
image

To-do list

  • Someone else take over this work from @lazd
  • Check the fact that the handle goes to the end of the track with design
  • Maybe add this container to the rest of the Slider examples

/* backwards compatibility: these are not required, but they make the handle go to the edegs and align right */
.spectrum-Slider-handleContainer,
.spectrum-Slider-trackContainer {
width: calc(100% + var(--spectrum-slider-handle-width-adjusted));
Copy link
Contributor

Choose a reason for hiding this comment

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

These changes will effectively widen the overall slider bounding box right (potentially leading to clients needing layout changes)?

I'm wondering if it'd be helpful to add another css variable for this context (so clients can reset it to 0 for the old behavior more easily, particularly in the web component implementation), and also potentially making a major version bump since this is likely a breaking change for some clients. I also know that the spectrum designs on this are unclear about what the behavior should be (though this change certainly seems correct to me). I posted in the spectrum design slack channel and can follow up there to make sure the designs are less ambiguous.

Copy link
Member Author

@lazd lazd Oct 8, 2021

Choose a reason for hiding this comment

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

It does not widen the bounding box actually, because those elements are positioned absolute inside of the slider's overall container. It does, however, overlap the bounding box visually. This could result in half of the slider handle being invisible if it's placed in a scrollable panel (with overflow-y: auto) that didn't have enough padding and the handle was at 0 or 100:

image

As far as backwards compatibility, the containers that make this change are optional, and existing markup works and looks exactly as it did before, so there is no breaking change in this PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

Awesome -- makes total tense. Nice work!

@lazd lazd changed the title fix: make tick slider handles align to ticks perfectly fix: make tick slider handles align to ticks Oct 8, 2021
bernhard-adobe added a commit to bernhard-adobe/spectrum-css that referenced this pull request Dec 19, 2022
@castastrophe
Copy link
Contributor

I suspect PR #1547 will end up superseding this so I've highlighted this PR there to ensure changes address this concern.

@bernhard-adobe
Copy link
Contributor

I suspect PR #1547 will end up superseding this so I've highlighted this PR there to ensure changes address this concern.

Indeed, I had this on my radar in https://jira.corp.adobe.com/browse/CSS-332 Clean up old Slider PRs.
I added it to PR #1547. Thank you so much @lazd for re-iterating some of the code, I added it to the commit:

[feat: make tick slider handles align to ticks (follow up on #1289)]

@castastrophe
Copy link
Contributor

Thank so much for tackling this work. Closing it out in favor of the token migration effort but we're making sure this update is integrated. 🎉

@castastrophe castastrophe deleted the slider-ticks branch March 7, 2023 02:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Slider: ticks are not aligned to slider value

6 participants