mirror of
https://github.com/jgthms/bulma.git
synced 2025-01-09 15:44:25 +00:00
Add escape to close dropdowns
This commit is contained in:
parent
7b395a8ad8
commit
39a09d204a
@ -7,17 +7,19 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
if ($dropdowns.length > 0) {
|
||||
$dropdowns.forEach($el => {
|
||||
$el.addEventListener('click', event => {
|
||||
console.log('dropdown', event);
|
||||
event.stopPropagation();
|
||||
$el.classList.toggle('is-active');
|
||||
});
|
||||
});
|
||||
|
||||
document.addEventListener('click', event => {
|
||||
console.log('document', event);
|
||||
$dropdowns.forEach($el => {
|
||||
$el.classList.remove('is-active');
|
||||
});
|
||||
closeDropdowns();
|
||||
});
|
||||
}
|
||||
|
||||
function closeDropdowns() {
|
||||
$dropdowns.forEach($el => {
|
||||
$el.classList.remove('is-active');
|
||||
});
|
||||
}
|
||||
|
||||
@ -57,20 +59,21 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
if ($modalCloses.length > 0) {
|
||||
$modalCloses.forEach($el => {
|
||||
$el.addEventListener('click', () => {
|
||||
$html.classList.remove('is-clipped');
|
||||
closeModals();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
document.addEventListener('keydown', e => {
|
||||
document.addEventListener('keydown', event => {
|
||||
const e = event || window.event;
|
||||
if (e.keyCode === 27) {
|
||||
$html.classList.remove('is-clipped');
|
||||
closeModals();
|
||||
closeDropdowns();
|
||||
}
|
||||
});
|
||||
|
||||
function closeModals() {
|
||||
$html.classList.remove('is-clipped');
|
||||
$modals.forEach($el => {
|
||||
$el.classList.remove('is-active');
|
||||
});
|
||||
|
@ -9,17 +9,19 @@ document.addEventListener('DOMContentLoaded', function () {
|
||||
if ($dropdowns.length > 0) {
|
||||
$dropdowns.forEach(function ($el) {
|
||||
$el.addEventListener('click', function (event) {
|
||||
console.log('dropdown', event);
|
||||
event.stopPropagation();
|
||||
$el.classList.toggle('is-active');
|
||||
});
|
||||
});
|
||||
|
||||
document.addEventListener('click', function (event) {
|
||||
console.log('document', event);
|
||||
$dropdowns.forEach(function ($el) {
|
||||
$el.classList.remove('is-active');
|
||||
});
|
||||
closeDropdowns();
|
||||
});
|
||||
}
|
||||
|
||||
function closeDropdowns() {
|
||||
$dropdowns.forEach(function ($el) {
|
||||
$el.classList.remove('is-active');
|
||||
});
|
||||
}
|
||||
|
||||
@ -59,20 +61,21 @@ document.addEventListener('DOMContentLoaded', function () {
|
||||
if ($modalCloses.length > 0) {
|
||||
$modalCloses.forEach(function ($el) {
|
||||
$el.addEventListener('click', function () {
|
||||
$html.classList.remove('is-clipped');
|
||||
closeModals();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
document.addEventListener('keydown', function (e) {
|
||||
document.addEventListener('keydown', function (event) {
|
||||
var e = event || window.event;
|
||||
if (e.keyCode === 27) {
|
||||
$html.classList.remove('is-clipped');
|
||||
closeModals();
|
||||
closeDropdowns();
|
||||
}
|
||||
});
|
||||
|
||||
function closeModals() {
|
||||
$html.classList.remove('is-clipped');
|
||||
$modals.forEach(function ($el) {
|
||||
$el.classList.remove('is-active');
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user