Skip to content

fix(slider): align initial fill position with stepped midpoint#26408

Merged
AlexGaillard merged 5 commits intodirectus:mainfrom
DamnItAzriel:fix-slider-initial-fill
Dec 26, 2025
Merged

fix(slider): align initial fill position with stepped midpoint#26408
AlexGaillard merged 5 commits intodirectus:mainfrom
DamnItAzriel:fix-slider-initial-fill

Conversation

@DamnItAzriel
Copy link
Contributor

@DamnItAzriel DamnItAzriel commented Dec 21, 2025

Scope

What's changed:

  • Fixed incorrect initial slider fill and label position when the midpoint between min and max is not a valid stepped value
  • Aligned slider fill calculation with native <input type="range"> stepped behavior

Potential Risks / Drawbacks

  • Minimal UI-only change
  • No impact on persisted values or emitted events
  • Change is limited to initial render state

Tested Scenarios

  • Created a number field using the slider interface
  • Configured min = 0, max = 5, step = 1
  • Verified that on initial render the slider thumb and fill are aligned
  • Confirmed existing slider interactions remain unchanged

Review Notes / Questions

  • This change removes the hardcoded 50% default and derives the stepped midpoint to match browser behavior
  • This is my first PR for an open-source project - please let me know if there is anything that I am missing.

Checklist

  • Added or updated tests
  • Documentation PR created here or not required
  • OpenAPI package PR created here or not required

Fixes #26406

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes an issue where the slider component's initial fill and label position were incorrectly centered at 50% when no value was provided and the actual stepped midpoint differed from the arithmetic midpoint. The fix aligns the slider's behavior with native HTML5 range input stepped behavior by calculating the nearest valid stepped value to the midpoint.

Key Changes:

  • Updated the type definition for modelValue to explicitly accept null
  • Replaced hardcoded 50% default with a calculated stepped midpoint that respects the step prop
  • Added edge case handling for when max === min
  • Added test coverage for the stepped midpoint calculation

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
contributors.yml Added new contributor DamnItAzriel to the list
app/src/components/v-slider.vue Fixed slider fill calculation to use stepped midpoint instead of hardcoded 50% when modelValue is null/undefined
app/src/components/v-slider.test.ts Added test to verify stepped midpoint calculation produces correct percentage (60% for min=0, max=5, step=1)
.changeset/giant-buckets-spend.md Added changeset documenting the patch fix for the slider component

Copy link
Member

@AlexGaillard AlexGaillard left a comment

Choose a reason for hiding this comment

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

Thanks for this @DamnItAzriel. Just some small things and I think we're good to go. 😃

@DamnItAzriel
Copy link
Contributor Author

@AlexGaillard Thank you very much for your kind review. This means a lot as this is my first PR.

I have made the changes requested here. Please check and let me know if anything.

Copy link
Member

@AlexGaillard AlexGaillard left a comment

Choose a reason for hiding this comment

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

LGTM, nice one @DamnItAzriel 👍

@AlexGaillard AlexGaillard merged commit e38b5af into directus:main Dec 26, 2025
65 checks passed
@github-actions github-actions bot added this to the Next Release milestone Dec 26, 2025
@DamnItAzriel
Copy link
Contributor Author

LGTM, nice one @DamnItAzriel 👍

Thanks. 😃

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 25, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

UI glitches Slider

3 participants