Skip to content

can't put a click handler on a b-button with href or to #2938

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

Closed
rothskeller opened this issue Mar 28, 2019 · 2 comments · Fixed by #2943
Closed

can't put a click handler on a b-button with href or to #2938

rothskeller opened this issue Mar 28, 2019 · 2 comments · Fixed by #2943

Comments

@rothskeller
Copy link

If a b-button component has an href or to attribute, its click handler does not get called. One key reason for a click handler on a link is to check preconditions and, if they are not met, call evt.preventDefault() to prevent the link action. This is not possible with b-button as currently coded.

This problem was reported in #1146, but that submitter wanted a click handler for a different reason and was given a suitable workaround. I do not know of any workaround for needing a pre-check and preventDefault. I did consider making a plain button rather than a link button, and invoking the router from the click handler, but that doesn't behave like a link in most browsers (e.g. showing the destination URL in the lower left corner).

The reason the click handler is not called is because the code for b-button adds its own click handler, so by the time we get to the code for b-link, on.click is an array of two functions. When that gets into b-link's clickHandlerFactory, it does not call either of those functions because typeof suppliedHandler === 'function' is not true. It would seem that a likely solution would be to handle the case where typeof suppliedHandler is an array of functions, and call each of them.

@tmorehouse tmorehouse self-assigned this Mar 28, 2019
jacobmllr95 pushed a commit that referenced this issue Mar 29, 2019
…) (#2943)

* Update link.js

* Update link.html

* Update link.js

* Update link.js

* Update link.spec.js
@rothskeller
Copy link
Author

Amazingly fast response. Thank you!

@tmorehouse
Copy link
Member

Will be available in c2.0.0-rc.17 next week.

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

Successfully merging a pull request may close this issue.

2 participants