docbrown/app/javascript/admin/controllers/sidebar_controller.js
Ridhwana 320eb86dc2
RFC 50: Interaction tweaks (take two) (#13576)
* feat: add the collapse style css + a script for the intercepting the bootstrap event

* chore: remove old code

* Add some guards for missing elements and simplify show/hide collapse interaction

* Update app/assets/stylesheets/admin.scss

Co-authored-by: rhymes <rhymes@hey.com>

Co-authored-by: rhymes <rhymes@hey.com>
2021-04-30 13:01:55 +02:00

31 lines
774 B
JavaScript

import { Controller } from 'stimulus';
// eslint-disable-next-line no-restricted-syntax
export default class SidebarController extends Controller {
static targets = ['submenu'];
disableCurrentNavItem() {
if (this.submenuTargets.length > 0) {
const activeMenuId = this.submenuTargets.filter((item) =>
item.classList.contains('show'),
)[0]?.id;
if (activeMenuId) {
const activeButton = document.getElementById(`${activeMenuId}_button`);
activeButton.setAttribute('disabled', true);
}
}
}
expandDropdown() {
this.closeOtherMenus();
}
closeOtherMenus() {
this.submenuTargets.map((item) => {
if (item.classList.contains('show')) {
item.classList.remove('show');
}
});
}
}