Skip to content

Commit ec85943

Browse files
committed
Fix hidden pickr instances issues
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.
1 parent 1cc56c8 commit ec85943

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/js/pickr.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,13 @@ class Pickr {
193193
}
194194

195195
_finalBuild() {
196+
if (this._finalBuildComplete) { return; }
197+
196198
const opt = this.options;
197199
const root = this._root;
198200

201+
if (opt.container.offsetParent === null) { return; }
202+
199203
// Remove from body
200204
opt.container.removeChild(root.root);
201205

@@ -235,6 +239,7 @@ class Pickr {
235239
}
236240

237241
this.hide();
242+
this._finalBuildComplete = true;
238243
}
239244

240245
_buildComponents() {
@@ -732,8 +737,8 @@ class Pickr {
732737
* Shows the color-picker ui.
733738
*/
734739
show() {
735-
736740
if (!this.options.disabled) {
741+
this._finalBuild();
737742
this._root.app.classList.add('visible');
738743
this._rePositioningPicker();
739744
this._emit('show', this);

0 commit comments

Comments
 (0)