Skip to content

Commit

Permalink
Ignore Enter key up event on menu button toggles
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
danxuliu authored and skjnldsv committed Aug 28, 2019
1 parent 976625f commit cb93af6
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 18 deletions.
2 changes: 1 addition & 1 deletion core/js/dist/login.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion core/js/dist/login.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion core/js/dist/main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion core/js/dist/main.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion core/js/dist/maintenance.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion core/js/dist/maintenance.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions core/src/OC/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ let currentMenuToggle = null
export const registerMenu = ($toggle, $menuEl, toggle, headerMenu) => {
$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)
Expand Down
15 changes: 5 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit cb93af6

Please sign in to comment.