PepeElToro41 / ui-labs

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

`Slider` control initial position bug #51

Closed Nidoxs closed 2 months ago

Nidoxs commented 2 months 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 2 months 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

PepeElToro41 commented 2 months ago

No, I just checked this and it was in fact wrong.

It's called in a useUpdateEffect which wont run at start, I dont remember what I was doing there honestly

Thanks for pointing this out!