leva
leva copied to clipboard
API Request: Order Inputs
It would be nice to be able to control the order of the inputs in a pane. From what I can see (if I'm not mistaken) control inputs rely on the order of an object.entries
iteration.
Can you expand on this and your use case? Maybe suggest an API for what you have in mind
@gsimone I want to be able to group controls logically or or otherwise specify an order that makes sense.
For an API a simple option for now would be allowing users to specify a sorting function that is called before rendering the controls.
I haven't thought much about the ideal API so this is just an off the top of my head :)
Just for clarification Leva renders input on call order, meaning parent inputs will be rendered before its children's.
This order is persisted across unmounting: if you have inputs from components A, B, C in that call order, if B unmounts and remounts later, its inputs are going to show in between A and C as they were initially.
Folders are a bit of an exception as you can't have repeated folders with the same name, so if a child reuses a folder from its parent, the inputs contained in that folder will "portal" up in the panel hierarchy.
Anyway Leva tries to order inputs in a predictable order and that was our first objective.
Having a sort or a preferred position per input is possible, but this boils down to having a simple and useful API as @gsimone pointed out.
Thanks for clarifying. The complex case sounds sensible (re parent child input ordering).
I'm coming at it more from how can inputs be ordered logically within a single component.
Will try to have a think about potential APIs for this case 👍🏻