Like links, buttons generate a "click" event as well as the regular
"keydown" and "keyup" events when pressing Enter. Due to this, if both
the "click" and the "keyup" events are handled, when the menu is open
and Enter is pressed in the toggle the menu is first hidden when the
first event is handled, but then shown again when the second event is
handled. To prevent that only the "click" event should be handled when
the toggle is a button, like it is already done with links.
Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
var self = this;
$menuEl.addClass('menu');
- // On link, the enter key trigger a click event
+ // On link and button, the enter key trigger a click event
// Only use the click to avoid two fired events
- $toggle.on($toggle.prop('tagName') === 'A'
+ $toggle.on(($toggle.prop('tagName') === 'A' || $toggle.prop('tagName') === 'BUTTON')
? 'click.menu'
: 'click.menu keyup.menu', function(event) {
// prevent the link event (append anchor to URL)