Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Highlight active button in sidebar #13111

Closed
wants to merge 12 commits into from
12 changes: 11 additions & 1 deletion packages/rocketchat-ui-sidenav/client/sidebarItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,17 @@ Template.sidebarItem.onCreated(function() {
});

Template.sidebarItem.events({
'click [data-id], click .sidebar-item__link'() {
'click [data-id], click .sidebar-item__link'(e) {
const element = e.currentTarget;
const sidebarElements = document.getElementsByClassName('sidebar-item');
for (let i = sidebarElements.length - 5; i < sidebarElements.length; i++) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't rely on magic constants in expressions like sidebarElements.length - 5. What about using a more scoped query selector get the items?

const sidebarElements = document.querySelectorAll('.sidebar .flex-nav .sidebar-item');
for (const sidebarElement of Array.from(sidebarElements)) {
  ...
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, I'll make the changes and push asap.

const nonSelectedElement = sidebarElements[i].getElementsByTagName('a')[0];
if (nonSelectedElement.getAttribute('aria-label') === element.getAttribute('aria-label')) {
sidebarElements[i].classList.add('selected-bg-shade');
} else {
sidebarElements[i].classList.remove('selected-bg-shade');
}
}
return menu.close();
},
'mouseenter .sidebar-item__link'(e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
}
}

.selected-bg-shade {
background-color: var(--sidebar-background-light-active) !important;
}

.sidebar--hide-avatar .sidebar-item__picture {
display: none;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@
--sidebar-background-hover: var(--rc-color-primary-dark);
--sidebar-background-light: var(--rc-color-primary-lightest);
--sidebar-background-light-hover: var(--rc-color-primary-light);
--sidebar-background-light-active: var(--rc-color-primary-light);
--sidebar-default-padding: 24px;
--sidebar-small-default-padding: 16px;
--sidebar-extra-small-default-padding: 12px;
Expand Down