mdbassit / Coloris

A lightweight and elegant JavaScript color picker. Written in vanilla ES6, no dependencies. Accessible.
https://coloris.js.org/examples.html
MIT License
443 stars 58 forks source link

Allow el configuration property to be the dom element #106

Closed lavolpecheprogramma closed 1 year ago

lavolpecheprogramma commented 1 year ago

Hi! I'm watching the codebase, and it seems that it is not possible to pass a dom element to the el property(selector). it can be super useful if you want to use coloris with a framework like vue.

Thanks for your work, coloris have a very nice design!

mdbassit commented 1 year ago

Thank you for your kind words!

Indeed it is not possible to pass a single dom element as it is fairly inefficient. I currently have no plans to support that.

lavolpecheprogramma commented 1 year ago

Hi, thanks for your reply. Why do you think it is inefficient? You can bind the click and the input listeners directly to the dom node and not on document and then try to match the target :)

mdbassit commented 1 year ago

It is inefficient precisely because the event listeners have to be set for each DOM element separately, which for my specific use case is a big no-no. The other downside is having to reset the event listeners if the DOM tree is rewritten.

lavolpecheprogramma commented 1 year ago

Thanks for your reply :) In a webapp with large form with a lot of input and only one coloris instances it can be a bottleneck, because for every input and click your function will be invoked. i'm not sure that event delegation is better of have two event listeners for each coloris instances but i understand your point of view and if it works better in your use case, it's just fine! thanks a lot for your time!