Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please make parent click handling optional. #47

Closed
roman-makaroff opened this issue Jul 10, 2022 · 2 comments
Closed

Please make parent click handling optional. #47

roman-makaroff opened this issue Jul 10, 2022 · 2 comments

Comments

@roman-makaroff
Copy link

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);
                  }    
@Sphinxxxx
Copy link
Owner

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/

@roman-makaroff
Copy link
Author

roman-makaroff commented Jul 13, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants