simonwep / pickr

🎨 Flat, simple, multi-themed, responsive and hackable Color-Picker library. No dependencies, no jQuery. Compatible with all CSS Frameworks e.g. Bootstrap, Materialize. Supports alpha channel, rgba, hsla, hsva and more!
https://simonwep.github.io/pickr
MIT License
4.31k stars 285 forks source link

Fix hidden pickr instances issues #227

Closed DEfusion closed 4 years ago

DEfusion commented 4 years ago

If the container the pickr is output in is not visible when it is created the position of the movable handles is not shown correctly on opening, this then has the knock-on effect of not setting the color correctly on interaction unless you click on the palette or a swatch first.

This change addresses that by checking if the container is visible via a offsetParent check in _finalBuild and does not finalize the build until it is by calling _finalBuild on show calls.

Fixes #226

DEfusion commented 4 years ago

Note I'm not totally happy with this approach but it seemed the easiest way to address this particular issue after exploring other avenues.

simonwep commented 4 years ago

Oh my, I'm so sorry I only saw the issue and fixed it immediately on my own :/ Thank you a lot for your efforts! Yes, yours seem to be a solution, in my case I just remove the alternative condition for the widget to be visible :) It's basically the same as yours but in my case I do the whole check-if-it-is-visible thing at the very beginning.

DEfusion commented 4 years ago

@Simonwep Yeah I wasn't sure about this approach as I said in my comment and you're obviously much more familiar with the code; however the change 0d445e57 does cause the callback to run continuously on every frame until the pickr is opened, which in some cases may be never.

I know it's a cheap callback which exits quickly but I wondered if that could be avoided, so I've given it another stab in #229