Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix hidden pickr instances issues #227

Closed

Conversation

DEfusion
Copy link
Contributor

@DEfusion DEfusion commented Jul 6, 2020

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

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](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/offsetParent) in `_finalBuild` and does not finalize the build until it is by calling `_finalBuild` on `show` calls.
@DEfusion DEfusion force-pushed the handle-hidden-pickr-instances branch from ec85943 to 9435392 Compare July 6, 2020 19:08
@DEfusion
Copy link
Contributor Author

DEfusion commented Jul 6, 2020

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
Copy link
Owner

simonwep commented Jul 6, 2020

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
Copy link
Contributor Author

DEfusion commented Jul 7, 2020

@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 0d445e5 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

@DEfusion DEfusion closed this Jul 7, 2020
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Initial color not set correctly when pickr parent is not visible.
2 participants