Liferay DXP 2026.Q4    |    Release Webinar: 18 November 2026    |    Replay coming soon! 

Blogs

Display navigation drop down on click event

Bradley Wood
Bradley Wood
Uma leitura de menos de um minuto

Over the last few weeks I've been trying to figure out a way to make navigation's dropdown menus display on click instead of hover.

I added this code to the theme's main.js file.

AUI.add(
	'liferay-navigation-interaction-click',
	function(A) {
		A.mix(
			Liferay.NavigationInteraction.prototype,
			{
				_initChildMenuHandlers: function(navigation) {
      				var instance = this;

      				if (navigation) {
       					navigation.delegate(['click', 'clickoutside'], instance._onMouseToggle, '> li', instance);

       					navigation.delegate('keydown', instance._handleKeyDown, 'a', instance);
      				}
     			},
     			_onMouseToggle: function(event) {
						var instance = this;

						var mapHover = instance.MAP_HOVER;

						var eventType = 'hideNavigationMenu';

						if (event.type == 'click') {
							eventType = 'showNavigationMenu';
						}

						mapHover.menu = event.currentTarget;

						Liferay.fire(eventType, mapHover);
					},
			},
			true
		);
	},
	'',
	{
		requires: ['event-click', 'event-outside', 'liferay-navigation-interaction']
	}
);
 
the click outside event will fire when you click outside of the currently clicked item, which works great for drop downs. Let me know if you have a better way of doing it.
 
Note: you might need to pull in the newly created module ( liferay-navigation-interaction-click) in your AUI.ready or AUI.use part of your main.js
Comentários da Página

Related Assets...

Nenhum Resultado Encontrado

More Blog Entries...

Himanshu Chauhan
Novembro 20, 2026
Tony Lim
Novembro 19, 2026