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
Top menu entries for spaces are not highlighted when clicked #6721
Comments
@marc-farre Good point, I think the Javascript event is used, especially in conjunction with PJAX to change an active space. @yurabakhtin Any idea? |
@marc-farre I have tested your code but cannot reproduce the issue, I see the top menu is active in all cases:
Could you show please more details how to make the menu item is not highlighted? |
Isn't this why |
@yurabakhtin thanks for your tests. So once you have the "My space" top menu entry added with your event:
If you click a second time, refresh the page or click any link in the space, the menu entry is highlighted. The reason is https://github.com/humhub/humhub/blob/master/static/js/humhub/humhub.ui.navigation.js#L25C2-L27 screen-2023-12-11_16.33.21.mp4 |
Why not use something like this then? You're not implementing an active state to begin with in your public static function onTopMenuInit($event)
{
/** @var TopMenu $menu */
$menu = $event->sender;
$space = Space::findOne(1);
$currentContentContainer = ContentContainerHelper::getCurrent();
$menu->addEntry(new MenuLink([
'label' => "My space",
'url' => $space->getUrl(),
'icon' => 'inbox',
'sortOrder' => 100,
'isActive' => MenuLink::isActiveState(($currentContentContainer->id ?? null) === $space->id),
'isVisible' => true,
]));
} |
@ArchBlood thanks, but |
In your example all I am seeing is that it uses the null coalescing operator ( As I stated #6721 (comment) the JS code is used in the dropdown menu for My Spaces to remove the active state, the JS isn't much of an issue, don't get me wrong I don't see the need for it, but I also don't see the need to remove it either. |
@marc-farre Ok thank you for details. I could reproduce the issue only on Opera browser, but I cannot reproduce this on Chrome and FireFox, I don't know why, I even restored default browser settings. It looks like pjax doesn't work on the browsers because I have debugged the method var setSpace = function(spaceOptions, pjax) {
if(!module.options || module.options.guid !== spaceOptions.guid) {
module.options = spaceOptions;
if(pjax) {
alert('!!!!PJAX');
event.trigger('humhub:space:changed', $.extend({}, module.options));
}
}
}; I can see the alert only on Opera. Yes, it seems the code https://github.com/humhub/humhub/blob/master/static/js/humhub/humhub.ui.navigation.js#L25C2-L27 can be deleted because I don't find a reason: .on('humhub:space:changed', function () {
$('#top-menu-nav').find('li').removeClass('active');
}) But I am not sure fully, what is the code is needed for some case or theme where it should be reset? I can suggest another solution to fix this:
$menu->addEntry(new MenuLink([
'label' => "My space",
...,
'htmlOptions' => ['data-space-guid' => $space->guid]
]));
}).on('humhub:space:changed', function (evt, options) {
$('#top-menu-nav').find('li').removeClass('active');
if (typeof options.guid === 'string') {
$('#top-menu-nav').find('a[data-space-guid=' + options.guid + ']').parent().addClass('active');
}
}); What do you think? |
@ArchBlood Thank you for the help, but we cannot pass a bool value into the method public static function isActiveState($moduleId = null, $controllerIds = [], $actionIds = []) Samples of using:
|
Thanks @yurabakhtin Anyway, I would be in favor to simplify JS code and remove specific things in it, because it adds complexity and make Humhub more difficult to maintain with future updates and adding modules. Would you be OK if I remove this code in the dev branch: .on('humhub:space:changed', function () {
$('#top-menu-nav').find('li').removeClass('active');
}) and if we find a bug because of this removal, we'll see what to do? |
@marc-farre Ok, please try to create a PR for |
…ed (#6727) Co-authored-by: Lucas Bartholemy <luke-@users.noreply.github.com>
What steps will reproduce the problem?
Create a custom module.
Add this event:
Click on the "My space" top menu entry
What is the expected result?
The "My space" top menu entry is highlighted (
active
class is added).What do you get instead?
It is not highlighted.
Additional info
This is due to this JS on https://github.com/humhub/humhub/blob/master/static/js/humhub/humhub.ui.navigation.js#L26:
The text was updated successfully, but these errors were encountered: