Skip to content

[Amsterdam] Eui(Dual)Range styles #4815

Merged
elizabetdev merged 55 commits intoelastic:masterfrom
elizabetdev:ams/range
Jun 17, 2021
Merged

[Amsterdam] Eui(Dual)Range styles #4815
elizabetdev merged 55 commits intoelastic:masterfrom
elizabetdev:ams/range

Conversation

@elizabetdev
Copy link
Copy Markdown
Contributor

@elizabetdev elizabetdev commented May 20, 2021

Summary

This PR adds new styles for the Eui(Dual)Range.

Bug Fixes

Amsterdam Styles

Initially, I started by changing the highlight and thumbs to the primary color. But then I decided to leave the color as it was. This gives more margin to better handle states (like focus).

The changes make the compressed and non-compressed states behave more like other components. When it's compressed, the track, highlight, and ticks get smaller.

The major change is that now the ticks are below the track.

RangeSlider@2x

For the focus states we only highlight the thumb that is currently focused and also only the range highlight gets highlighted. This gives us more margin to handle better the focus states on #4776.

RangeSlider - focus@2x

Disabled states:

RangeSlider - disabled@2x

These styles also impact the EuiColorStops

RangeSlider - color-stops@2x

Known issue

We fixed the bug with the ticks not positioning properly, but the levels are also not positioned on the right place.

Checklist

  • Check against all themes for compatibility in both light and dark modes
  • Checked in mobile
  • Checked in Chrome, Safari, Edge, and Firefox
  • [ ] Props have proper autodocs and playground toggles
  • [ ] Added documentation
  • [ ] Checked Code Sandbox works for the any docs examples
  • Added or updated jest tests
  • [ ] Checked for breaking changes and labeled appropriately
  • [ ] Checked for accessibility including keyboard-only and screenreader modes
  • A changelog entry exists and is marked appropriately

@kibanamachine
Copy link
Copy Markdown

Preview documentation changes for this PR: https://eui.elastic.co/pr_4815/

@kibanamachine
Copy link
Copy Markdown

Preview documentation changes for this PR: https://eui.elastic.co/pr_4815/

@elizabetdev elizabetdev added the skip-changelog Use on PRs to skip changelog requirement (Don't delete - used for automation) label May 27, 2021
@kibanamachine
Copy link
Copy Markdown

Preview documentation changes for this PR: https://eui.elastic.co/pr_4815/

@kibanamachine
Copy link
Copy Markdown

Preview documentation changes for this PR: https://eui.elastic.co/pr_4815/

@thompsongl
Copy link
Copy Markdown
Contributor

The ticks are not centered with the thumbs

The solution for this will largely come down to how we want to handle truncation.
If truncation continues to be a requirement for the labels, I don't yet have a good way to position the ticks correctly. Shifting the ticks to the correct locations causes other layout and overlap issues.
If truncation is deemed no longer important, I have some calculations that could work.

//cc @cchaos

@thompsongl
Copy link
Copy Markdown
Contributor

thompsongl commented Jun 1, 2021

And just to show how strange the native <input type=range> scale is:

Kapture.2021-06-01.at.15.45.42.mp4

10, 30, 40, 50 are spot on with a scaling calculation, but 20 is off. Not sure how to account for this with math.
I'll also throw in that Firefox appears to use a different scale/offset than Chromium browsers.
This scale offset could be the reason we hid the tick marks behind the thumb in the first iterations; it hides the visual offset.

@elizabetdev
Copy link
Copy Markdown
Contributor Author

My best attempt was to replace the native thumb with EuiRangeThumb. Then I improved the calculateThumbPositionStyle() to make the thumb be better positioned. But then it didn't work well when fullWidth={true}. Also as we can notice the thumbs are not 100% centered with the ticks

Screen+Recording+2021-06-02+at+12.32+PM.mov

I think the best solution is if we don't rely on the native <input type="range" />. Moving to custom components would allow us to better position both thumbs and ticks, to have better styles and more consistency across both components.

I think this is a good example of what we can achieve: https://github.com/sghall/react-compound-slider.

What do you think @thompsongl? (Maybe it's not achievable for 7.14).

@thompsongl
Copy link
Copy Markdown
Contributor

My preference is to find a compromise that allows continued use of <input type="range" />, such as making some adjustments to get closer to centered ticks but being ok with some slight offset.

We note in the documentation that sliders are not meant to be used for precision, so there is some precedence for keeping with native elements at the expense of perfection:

Range sliders should only be used when the precise value is not considered important. If the precise value does matter, add the showInput prop or use a EuiFieldNumber instead.

@thompsongl
Copy link
Copy Markdown
Contributor

My best attempt was to replace the native thumb with EuiRangeThumb

Looking into this as well. Interestingly, the math that makes the most sense places the thumb exactly where the native thumb would be 😅

@thompsongl
Copy link
Copy Markdown
Contributor

The solution for this will largely come down to how we want to handle truncation.

Although still true, I found a way to enforce desired truncation while achieving the label positioning we need. Still a couple layout discrepancies to work out between default and custom labels, but I hope to have a PR for you tomorrow.

@thompsongl
Copy link
Copy Markdown
Contributor

👉 elizabetdev#17
Still off center by a pixel or two in some spots depending on how the labels are configured, but it's much closer than before.

@kibanamachine
Copy link
Copy Markdown

Preview documentation changes for this PR: https://eui.elastic.co/pr_4815/

Copy link
Copy Markdown
Contributor

@chandlerprall chandlerprall left a comment

Choose a reason for hiding this comment

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

Code changes LGTM!

@kibanamachine
Copy link
Copy Markdown

Preview documentation changes for this PR: https://eui.elastic.co/pr_4815/

@kibanamachine
Copy link
Copy Markdown

Preview documentation changes for this PR: https://eui.elastic.co/pr_4815/

@elizabetdev
Copy link
Copy Markdown
Contributor Author

Thanks @thompsongl for elizabetdev#18. It looks great. 🎉

@cchaos the // sass-lint:disable-block no-color-literals comments had to stay:

Screenshot 2021-06-16 at 19 36 00

Safari improvements

The inline color picker in Safari now shares the same focus states as in other browsers:

Screenshot 2021-06-17 at 11 47 12

The single range now has focus states. The only difference in Safari is when we have the "highlight". We need to start moving the thumb to make it focused. In other browsers once we focus the thumb the highlight is focused tight away.

Screen+Recording+2021-06-17+at+11.47+AM.mov

Another limitation or issue I couldn't solve in Safari is when we click the thumb of the color stops there’s a flash of the outline. I tried different things to solve and no luck.

Screen+Recording+2021-06-17+at+11.46+AM.mov

@elizabetdev elizabetdev requested a review from cchaos June 17, 2021 11:35
@kibanamachine
Copy link
Copy Markdown

Preview documentation changes for this PR: https://eui.elastic.co/pr_4815/

@cchaos
Copy link
Copy Markdown
Contributor

cchaos commented Jun 17, 2021

Another limitation or issue I couldn't solve in Safari is when we click the thumb of the color stops there’s a flash of the outline. I tried different things to solve and no luck.

Maybe this is a terrible idea, but what if we added a transition delay for outline JUST for this component? Something just enough for it to maybe not show during that quick focus transition to the popover. I tried something pretty short like 100ms which negated it on click but was still snappy enough when tabbing.

Screen.Recording.2021-06-17.at.02.23.04.PM.mp4

@kibanamachine
Copy link
Copy Markdown

Preview documentation changes for this PR: https://eui.elastic.co/pr_4815/

Copy link
Copy Markdown
Contributor

@cchaos cchaos left a comment

Choose a reason for hiding this comment

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

😍 I can't express how much I love these new styles!!! Ship it! Feel free to address the Safari idea or do a follow up.

Co-authored-by: Caroline Horn <549577+cchaos@users.noreply.github.com>
@kibanamachine
Copy link
Copy Markdown

Preview documentation changes for this PR: https://eui.elastic.co/pr_4815/

@kibanamachine
Copy link
Copy Markdown

Preview documentation changes for this PR: https://eui.elastic.co/pr_4815/

@elizabetdev
Copy link
Copy Markdown
Contributor Author

Thanks @cchaos! As suggested I added the transition delay. Tried different speeds and the outline still appears for me in Safari. I left a very fast transition delay for now (it might solve for some users).

I'm merging the PR and then I can follow up on this.

@elizabetdev elizabetdev merged commit fb286cb into elastic:master Jun 17, 2021
@cchaos
Copy link
Copy Markdown
Contributor

cchaos commented Jun 17, 2021

@miukimiu You also have to add an overall transition. In my video, I added transition: outline; to the regular non-focused state.

@elizabetdev
Copy link
Copy Markdown
Contributor Author

@cchaos it seems that I forgot to commit the transition: outline; as you noticed.

But I actually tried with the transition: outline; and it definitely improved the issue. But sometimes the outline appears.

Screen+Recording+2021-06-18+at+11.23+AM.mov

I'll follow up with a PR.

@kibanamachine
Copy link
Copy Markdown

Preview documentation changes for this PR: https://eui.elastic.co/pr_4815/

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.

5 participants