-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BootstrapAdminUi] Fix missing menu search (#112)
- Loading branch information
Showing
3 changed files
with
72 additions
and
1 deletion.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* This file is part of the Sylius package. | ||
* | ||
* (c) Sylius Sp. z o.o. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
/* global document */ | ||
|
||
(function() { | ||
const menuSearchInput = document.querySelector('[data-menu-search]'); | ||
const menuClearButton = document.querySelector('[data-menu-search-clear]'); | ||
|
||
const clearInput = () => { | ||
menuSearchInput.value = ''; | ||
menuSearchInput.dispatchEvent(new Event('input')); | ||
}; | ||
|
||
if (menuSearchInput) { | ||
menuSearchInput.addEventListener('input', function(e) { | ||
const query = e.target.value.toLowerCase(); | ||
const navItems = document.querySelectorAll('.sidebar .nav-item'); | ||
|
||
navItems.forEach(navItem => { | ||
const navLink = navItem.querySelector('.nav-link'); | ||
const dropdownMenu = navItem.querySelector('.dropdown-menu'); | ||
const dropdownItems = navItem.querySelectorAll('.dropdown-item'); | ||
let matchFound = false; | ||
|
||
dropdownItems.forEach(item => { | ||
const text = item.textContent.toLowerCase(); | ||
if (query === '' || text.includes(query)) { | ||
item.style.display = ''; | ||
matchFound = true; | ||
} else { | ||
item.style.display = 'none'; | ||
} | ||
}); | ||
|
||
if (matchFound || query === '') { | ||
navItem.style.display = ''; | ||
} else { | ||
navItem.style.display = 'none'; | ||
} | ||
|
||
if (query !== '') { | ||
if (navLink) navLink.classList.add('d-flex'); | ||
if (dropdownMenu) dropdownMenu.classList.add('d-flex'); | ||
} else { | ||
if (navLink) navLink.classList.remove('d-flex'); | ||
if (dropdownMenu) dropdownMenu.classList.remove('d-flex'); | ||
} | ||
}); | ||
}); | ||
|
||
menuSearchInput.addEventListener('keydown', function(event) { | ||
if (event.key === 'Escape') { | ||
clearInput(); | ||
} | ||
}); | ||
} | ||
|
||
if (menuClearButton) { | ||
menuClearButton.addEventListener('click', function() { | ||
clearInput(); | ||
}); | ||
} | ||
})(); |
Large diffs are not rendered by default.
Oops, something went wrong.