Skip to content

Implement ability to style progress of a range input #736

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 4 commits into from
Mar 22, 2025

Conversation

viseztrance
Copy link
Contributor

This adds the ability to style the current progress of a range input, similar to ::-moz-range-progress, :-webkit-slider-runnable-track.

Peek 2025-03-06 01-12

@viseztrance viseztrance marked this pull request as draft March 6, 2025 19:30
This adds the ability to style the current progress of a range input,
similar to `::-moz-range-progress`, `:-webkit-slider-runnable-track`.
@viseztrance viseztrance force-pushed the add-progress-to-range-input branch from bc80cdf to f3cca50 Compare March 6, 2025 19:56
@viseztrance viseztrance marked this pull request as ready for review March 6, 2025 19:57
@mikke89
Copy link
Owner

mikke89 commented Mar 6, 2025

Very cool, I like the idea! Thanks for making a pull request.

Is it working with decorators too?

I am a bit busy these days, but will take a closer look at it soon.

@viseztrance
Copy link
Contributor Author

If you mean, you can use decorators to style it, then yes (ninepatch works fine for example). Definitely take your time, I'm in no hurry over it.

Copy link
Owner

@mikke89 mikke89 left a comment

Choose a reason for hiding this comment

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

Thanks a lot for the pull request, it's a very nice addition! I like the subtle red you have added to the sample input range, the progress background gives some extra life to the element.

Overall, looks good to me code-wise, a couple smaller comments.

One issue I found is that if you press and drag the left mouse button from the progress area, then the slider doesn't move while dragging anymore. Compare this to the behavior to the right of the slider bar, where it still works as before.

I tested it in the benchmark sample, and didn't notice any significant degradation, maybe 2-3% max, but could be noise. This benchmark includes the extra decoration too, so I'm okay with this.

@viseztrance
Copy link
Contributor Author

viseztrance commented Mar 20, 2025

One issue I found is that if you press and drag the left mouse button from the progress area, then the slider doesn't move while dragging anymore. Compare this to the behavior to the right of the slider bar, where it still works as before.

I'm going to look into fixing this. I didn't knew this functionality existed.
Fixed!

@mikke89 mikke89 added the enhancement New feature or request label Mar 20, 2025
@mikke89
Copy link
Owner

mikke89 commented Mar 20, 2025

Nice, seems to work well for me now!

One perhaps slight change in behavior is that the progress blocks the :hover of the slidertrack. So users that used slidertrack:hover rules will see some changes here. The fix is rather simple though:

input.range sliderprogress {
	display: none;
}

But perhaps a bit confusing if the user don't know about the sliderprogress. Same thing with :active. Do you have some thoughts around this? It might be acceptable considering the simple fix, but maybe there are some ways we can retain the old behavior if the sliderprogress isn't used.

@viseztrance
Copy link
Contributor Author

Over the weekend I'll look into reparenting the element to slidertrack. This should handle hover events nicely, and maybe even styling will be easier this way.

It won't work for active however, but I don't think that's a big issue, because the moment you click, we move slidebar under the cursor.

@mikke89
Copy link
Owner

mikke89 commented Mar 21, 2025

Good idea, definitely worth investigating. Another option could be to make it zero height if height has not been explicitly set.

One thing I noticed about active is that we only set it on the bar once we start dragging, so not on mouse down directly. That could be improved separately I think, it would make sense to make it active immediately while moving the bar under the mouse. But for now it's fine to ignore the active behavior here as you say.

@viseztrance
Copy link
Contributor Author

I made some new changes. Seems like just reparenting was sufficient to fix the hover event.

Also had a quick look over the :active behaviour you mentioned when you click the track. It was a trivial one liner fix, so I added that in.

@mikke89
Copy link
Owner

mikke89 commented Mar 21, 2025

Thanks for continuing with the improvements!

It's a bit problematic to set the :active pseudo selector directly like this. We have a separate active chain controlled by the context, which is responsible for turning the pseudo selector off again as appropriate. When setting the pseudo class directly, it's not added to the active chain, and thus it won't always be deactivated when letting go of the mouse button. You can see this if you press on the progress element or one of the plus/minus buttons, and then let go. It will stay active. This stuff is a bit finicky.

@viseztrance viseztrance force-pushed the add-progress-to-range-input branch from 3694bee to c32d263 Compare March 22, 2025 05:32
@viseztrance
Copy link
Contributor Author

I removed the active "fix". Considering the problem existed before, this PR was not the best place to fix it either way.

@mikke89 mikke89 merged commit 2d9793f into mikke89:master Mar 22, 2025
32 checks passed
@mikke89
Copy link
Owner

mikke89 commented Mar 22, 2025

Great, thanks! Looks good to me. And I agree, let's rather do that fix separately.

It would be super helpful if you could add some quick details about these changes to the documentation as well.

@viseztrance viseztrance deleted the add-progress-to-range-input branch March 22, 2025 13:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants