marimo icon indicating copy to clipboard operation
marimo copied to clipboard

drag range_slider to keep constant range

Open williambdean opened this issue 1 year ago • 9 comments

Description

With a range_slider with x_min and x_max defined, I would like to drag the middle of the range_slider and move that range such that x_max - x_min stays the same

Suggested solution

Provide a parameter to range_slider which allows this

Will you submit a PR?

  • [x] Yes

Alternative

Not that I know of. Would have to do something custom

Additional context

No response

williambdean avatar Jun 08 '25 21:06 williambdean

Thank you! This has been a feature desire for me too

dmadisetti avatar Jun 09 '25 05:06 dmadisetti

Awesome. It would be helpful feature I cannot make a PR at the moment but would slowly get to it. Feel free to open something. I would tag draft once I would start

williambdean avatar Jun 10 '25 10:06 williambdean

Hi! I'd like to work on this. My plan is to add a fixed_range: bool = False parameter to mo.ui.range_slider. When True, dragging between the handles moves both together keeping the range width constant. Does this API sound right before I start?

Sushit-prog avatar Mar 15 '26 18:03 Sushit-prog

Hm, I'm not certain it needs another flag at all. If you click on the middle it'll move the full range, but clicking on the ends keeps the same behavior

dmadisetti avatar Mar 15 '26 18:03 dmadisetti

Thanks for the quick response! I tried clicking the middle of the range slider but it doesn't seem to move both handles together, it just moves the nearest handle. Could you point me to where this behavior exists? I'm using the latest dev build.

Sushit-prog avatar Mar 15 '26 18:03 Sushit-prog

I tried clicking the middle of the range slider but it doesn't seem to move both handles together, it just moves the nearest handle

Sorry, I was suggesting how the functionality could work with dragging the range- not what's active

dmadisetti avatar Mar 15 '26 19:03 dmadisetti

Got it, thanks for clarifying! I'll go ahead and implement it with a fixed_range: bool = False parameter. I'll submit a PR once it's ready.

Sushit-prog avatar Mar 16 '26 01:03 Sushit-prog

I think what Dylan mentioned is that we don't need a new param at all. It can be the default behaviour

Light2Dark avatar Mar 16 '26 04:03 Light2Dark

Perfect, thanks @Light2Dark So the plan is: dragging the middle range bar moves both handles together as default behaviour, purely a frontend change in RangeSliderPlugin.tsx. I'll work on it and submit a PR!

Sushit-prog avatar Mar 16 '26 05:03 Sushit-prog