Skip to content

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

Closed
@rothskeller

Description

@rothskeller

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.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions