Skip to content

Commit

Permalink
Fix hidden pickr instances issues
Browse files Browse the repository at this point in the history
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 ensuring the color is set on the first run of `show` after the picker is made visible.

Fixes simonwep#226
  • Loading branch information
DEfusion committed Jul 7, 2020
1 parent 9e21242 commit c82d534
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 8 deletions.
4 changes: 2 additions & 2 deletions dist/pickr.es5.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/pickr.es5.min.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/pickr.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/pickr.min.js.map

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions src/js/pickr.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,7 @@ class Pickr {
const that = this;
requestAnimationFrame((function cb() {

// TODO: Performance issue due to high call-rate?
if (!app.offsetWidth) {
if (!app.offsetWidth && app.parentElement !== opt.container) {
return requestAnimationFrame(cb);
}

Expand Down Expand Up @@ -736,6 +735,11 @@ class Pickr {

if (!this.options.disabled) {
this._root.app.classList.add('visible');
if (!this._ensuredColorSet) {
const {h, s, v, a} = this._color;
this.setHSVA(h, s, v, a, true);
this._ensuredColorSet = true;
}
this._rePositioningPicker();
this._emit('show', this);
}
Expand Down

0 comments on commit c82d534

Please sign in to comment.