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

stopPropagation when clicking outside pickr #270

Closed GreenFootballs closed 2 years ago

GreenFootballs commented 3 years ago

I'm using pickr to select colors for objects that are selected by clicking on them, and deselected by clicking anywhere else in the document. The problem I'm having is that when the pickr is open and a user clicks outside it to close it, the click event bubbles up to whatever is there -- and that usually deselects the object, which is almost never what they want.

I think this is the section in question: https://github.com/Simonwep/pickr/blob/6e5d0fef71ea819888e22d1fbfbf1fae6f6c83ea/src/js/pickr.js#L443

A simple e.stopPropagation() right after the hide() would fix this. Maybe it could be a config option?

simonwep commented 3 years ago

A simple e.stopPropagation() right after the hide() would fix this. Maybe it could be a config option?

So why not a simple call to e.stopPropagation() in the hide event? I won't add anymore config options, see the status of this project.

GreenFootballs commented 3 years ago

I don't think the mousedown event is passed through to the hide() event - it just gets the instance. But I guess I can just hack the dist since it's not being updated.

GreenFootballs commented 3 years ago

Question: if I wanted to clone this project and do some tweaks, what's the process to build it?

simonwep commented 3 years ago

I don't think the mousedown event is passed through to the hide() event - it just gets the instance.

Sorry, you're correct - I forgot that these events are not passed down.

But I guess I can just hack the dist since it's not being updated.

Please avoid doing that, dist files are not readable, you make yourself dependent on some random build from a library and nobody will understand why your version works differently. This is really bad practice. Also, I'll still do "bug fixes" and with any kind of dev-dependency update the dist files may change entirely (variable / function names).

You'd assume here that I'll never change them again. Which is very unlikely.

Question: if I wanted to clone this project and do some tweaks, what's the process to build it?

See contributing.md. This would be the right way to do this.

GreenFootballs commented 3 years ago

Yes, I sort of knew hacking dist was a bad idea as soon as I typed it. If I fork and clone the repo, do you want me to do a PR for the change?

simonwep commented 3 years ago

Sorry for the late reply, I think it's better if we not make it part of the library as I don't want to add any functionality anymore :) Thank you!