Sphinxxxx/vanilla-picker

Please make parent click handling optional.

Closed this issue · 2 comments

In use case of sharing one picker instance across multiple buttons the 'parent'/container element may be different from the button (body or section). Click on parent should not always open the picker. So please add option to ignore handling on parent click

if (!settings.preventOpeningOnParentClick) {
                      this._events.add(parent, 'click', openProxy);
                  }    

Hello! Have you looked at the "Shared picker" example in the demo?

https://codepen.io/Sphinxxxx/pen/zRmKBX

If you still need more custom behavior, try attaching the picker to a common parent element and then hijack the openHandler() method to control when the picker should open:

const picker = new Picker({
    parent: document.body,
    ...
});

picker.__originalOpenHandler = picker.openHandler;
picker.openHandler = function(e) {
    if (shouldActuallyOpen) {
        this.__originalOpenHandler();
    }
};

Here is a working example of that last method:

https://jsfiddle.net/9g4nsdz3/2/