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.29k stars 287 forks source link

There is no way to clear picker input #258

Closed CodeExplore closed 3 years ago

CodeExplore commented 3 years ago

Your environment:

Version (see Pickr.version): any
Used bundle (es5 or normal one): any
Used theme (default is classic):  any
Browser-version:  any
Operating-system:  any

The problem is: There is no way to clear picker input if we set clear: false, the users never can't clear the input. This lines force us to update it.

https://github.com/Simonwep/pickr/blob/c1ebb361a2f31d19e3fc88355bf4f961b4fb591d/src/js/pickr.js#L415-L416

Also do you know, Popular WordPress Elementor Plugin removes this line in source code as well. because there is no option for disable update.

What we need: If users clear input field by manually, don't force to update input.

Solution: We can add a option (allowEmpty) like this:

// configuration
allowEmpty: true,
// Line 415 from:
this._recalc = e.type === 'blur'; 
// to
this._recalc = ( !options.allowEmpty || e.target.value ) && e.type === 'blur';

Test: https://jsfiddle.net/odhr1vzn/3/ Edit: https://github.com/CodeExplore/pickr/commit/fb0f8ed587f1e1c78866b6013d0ca3541c35a6c7

Regards

simonwep commented 3 years ago

Here you go. There is a bug though, fixed in ae4145029c1f1fd01df91d767b3bb87f798688a3, I'll release a patch version later this week.

CodeExplore commented 3 years ago

Thanks for time @Simonwep