cocopon / tweakpane

:control_knobs: Compact GUI for fine-tuning parameters and monitoring value changes
https://tweakpane.github.io/docs/
MIT License
3.57k stars 90 forks source link

Way to set id of an element? #620

Closed aniongithub closed 1 month ago

aniongithub commented 1 month ago

Currently, there's no way to set the id of an element so it can be styled indpendent of all others that share its class. Providing a common way to set an id would make it possible to write CSS selectors that selectively style specific instances of an element.

cocopon commented 1 month ago

You can use .element to get an element of a blade:

const pane = new Pane();
const b = pane.addBinding(PARAMS, 'foo');
b.element.id = 'someid';

https://tweakpane.github.io/docs/api/classes/_internal_.BindingApi.html#element

aniongithub commented 1 month ago

Thank you! I think this works as a workaround, but it would be nice to have a common property in the constructor that can do this uniformly. If not specified it can remain blank, of course.

cocopon commented 1 month ago

If we add a new id option, another question arises: Should we also add className, style, ... and other attributes?

I believe the attributes of the element should be accessed via the element property. This approach is more robust.