Sphinxxxx/vanilla-picker

[Enhancement request] Cancel button to fire an onCancel event

Opened this issue · 2 comments

Hi Sphinxxxx,

Thank you for this great colour-picker. It's just what I needed for my site.

As an additional request to #18 , could the Cancel button fire an onCancel event (in addition to onClose, of course), please?

I did have a look at the code to see if I could create a pull-request, but am struggling.

Best,
DefCheese.

Hello!

I'll just leave this open for now, but you can add your own "onCancel" logic by replacing/extending the picker's closeHandler():

//Add custom "onClose" functionality:
picker._closeHandler = picker.closeHandler;
picker.closeHandler = function(e) {
    this._closeHandler(e);
    
    const source = e && e.currentTarget;
    if(source === this._domCancel) {
    	alert('CANCELED!!');
    }
};

Example: https://jsfiddle.net/Ld78jwmu/

Brilliant! Thank you.