PepeElToro41 / ui-labs

UI Labs is a storybook plugin for Roblox
https://pepeeltoro41.github.io/ui-labs/
44 stars 8 forks source link

`Slider` control initial position bug #51

Open Nidoxs opened 3 hours ago

Nidoxs commented 3 hours ago

It seems that the Slider control has a visual bug where regardless of the initial value, the dragger is always at 50%. I took a look at the source code and the initial spring value for percent is 0.5.

As far as I can see from the component props and general source code of Slider, the initial value should be (props.Current - props.Min) / (Props.Max - Props.Min). I could be wrong here though, not looked at it too deeply so there may be a reason why you've got that 0.5 default value.

Let me know what you think 👍

Nidoxs commented 3 hours ago

Ah I can see you do have this already:

function GetPercent(control: AdvancedTypes.Slider, current: number) {
    const gap = control.Max - control.Min;
    return (current - control.Min) / gap;
}

This is then called in a useEffect upon first render and when there are any subsequent changes to props.Current