Created
February 2, 2018 12:22
-
-
Save Kiwka/a0aabbec9c3bbaf2f1ee9eeeaa6a25fa to your computer and use it in GitHub Desktop.
Toggle dropdown on keydown
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
document.addEventListener("DOMContentLoaded", () => { | |
$('.w-dropdown-toggle').on('keydown', e => { | |
if (e.keyCode === 13) { | |
const $toggle = $(e.target).closest('.w-dropdown-toggle'); | |
const $list = $toggle.closest('.w-dropdown').children('.w-dropdown-list'); | |
const opened = 'w--open'; | |
if ($toggle.hasClass(opened)) { | |
$toggle.removeClass(opened); | |
$list.removeClass(opened); | |
} else { | |
$('.w-dropdown-toggle').removeClass(opened); | |
$('.w-dropdown-list').removeClass(opened); | |
$toggle.addClass(opened); | |
$list.addClass(opened); | |
} | |
} | |
}); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment