NPM Resource Changed ? ? Failure

User tests: Successful: Unsuccessful:

avatar Subhang23
Subhang23
11 Feb 2020

Pull Request for Issue #27530 .

Summary of Changes

Added event listeners for certain areas and on checking if the dropdown is active it removes the active class

Testing Instructions

Open the administrator/index.php page and check the dropdown on top navbar after reducing the width of screen to a suitable size.

Expected result

The dropdown should close without having to click on the same place from where it was opened.

Actual result

Closes the dropdown on clicking on other regions also

Documentation Changes Required

avatar Subhang23 Subhang23 - open - 11 Feb 2020
avatar Subhang23 Subhang23 - change - 11 Feb 2020
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 11 Feb 2020
Category JavaScript Repository NPM Change
avatar Subhang23
Subhang23 - comment - 11 Feb 2020

@C-Lodder Is this good?

avatar Subhang23
Subhang23 - comment - 11 Feb 2020

ezgif com-optimize

avatar Quy Quy - change - 11 Feb 2020
Title
fixed error of dropdown not closing
[4.0] fixed error of dropdown not closing
avatar Quy Quy - edited - 11 Feb 2020
avatar brianteeman brianteeman - test_item - 11 Feb 2020 - Tested unsuccessfully
avatar brianteeman
brianteeman - comment - 11 Feb 2020

I have tested this item ? unsuccessfully on b636bac


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/27895.

avatar brianteeman
brianteeman - comment - 11 Feb 2020

Sorry this is not correct.

First I am getting a js error

TypeError: Cannot read property 'classList' of null
 /joomla-cms/media/templates/atum/js/template.js?70c984df970dc8781e009aafec6cfab4:299:51

This is how it should work. The dropdown stays open and selected until you select something else when it closes and stops being selected.

should

What this PR does is to

  • keep it selected but closed if you click on the desktop
  • keep it selected and still open if you click on another menu item
  • You can open the dropdown by clicking on the desktop

wrong

wrong2

avatar Subhang23
Subhang23 - comment - 11 Feb 2020

@brianteeman I am running it on Chrome on an Ubuntu(18.04-VirtualBox) and I can't seem to replicate either the js error or the gif you have shown. Can you please tell as to how to replicate it?

avatar brianteeman
brianteeman - comment - 11 Feb 2020

My test is on chrome windows

avatar Subhang23
Subhang23 - comment - 11 Feb 2020

ezgif com-optimize (1)
@brianteeman This is what I am getting

avatar C-Lodder
C-Lodder - comment - 11 Feb 2020

@Subhang23 You don't need two event listeners. The dropdown already opens, so you don't need to toggle any classes.

You only need a single event listener. Something like this:

document.addEventListener('click', (event) => {
  if (!document.querySelector('.header-more-menu').contains(event.target)) {
    document.getElementById('header-more-items').classList.remove('active');
  }
});

Note: I haven't tested the above so don't assume it will work. Please test it first.

avatar brianteeman
brianteeman - comment - 11 Feb 2020

Yes exactly and that is wrong. As you open the user menu the other dropdown does not close.

avatar jwaisner jwaisner - change - 11 Feb 2020
Labels Added: ?
avatar Subhang23
Subhang23 - comment - 12 Feb 2020

@brianteeman @C-Lodder I think I got confused as to what to do. So if I click on the other dropdown the header-item-more dropdown should be gone(if active) while this doesn't happen in the PR I have made.

avatar Subhang23
Subhang23 - comment - 12 Feb 2020

@brianteeman @C-Lodder Is this fine?

avatar Subhang23 Subhang23 - change - 12 Feb 2020
Labels Added: NPM Resource Changed
avatar Subhang23 Subhang23 - change - 13 Feb 2020
Title
[4.0] fixed error of dropdown not closing
[4.0][W.I.P] fixed error of dropdown not closing
avatar Subhang23 Subhang23 - edited - 13 Feb 2020
avatar Subhang23
Subhang23 - comment - 13 Feb 2020

This is what I have been testing at present

document.addEventListener('click', (event) => {
    console.log(document.querySelector('.active'));
    if (document.querySelector('.header-item-more') && document.querySelector('header').querySelector('.active') && !document.querySelector('.header-item-more').contains(event.target)) {
      document.getElementById('header-more-items').classList.remove('active');
    }
  });

But I am facing some problems. On clicking some of the elements in the top navbar(the ones with a dropdown) there is no event being triggered.(The message in console.log is just for checking for any response )
ezgif com-optimize (2)
@C-Lodder @brianteeman Can you help me out as to what is wrong here?
Edit:- Surprisingly the div that gets rendered(containing the links) responds to the eventLisnter

avatar Subhang23
Subhang23 - comment - 14 Feb 2020

This is what I have been testing at present

document.addEventListener('click', (event) => {
    console.log(document.querySelector('.active'));
    if (document.querySelector('.header-item-more') && document.querySelector('header').querySelector('.active') && !document.querySelector('.header-item-more').contains(event.target)) {
      document.getElementById('header-more-items').classList.remove('active');
    }
  });

But I am facing some problems. On clicking some of the elements in the top navbar(the ones with a dropdown) there is no event being triggered.(The message in console.log is just for checking for any response )
ezgif com-optimize (2)
@C-Lodder @brianteeman Can you help me out as to what is wrong here?
Edit:- Surprisingly the div that gets rendered(containing the links) responds to the eventLisnter

I have found an event listener attached to the dropdown buttons at the top nav which is giving me the problem. This eventListener gets loaded only after the first click on those buttons. Removing that listener has not caused any issues (removed it in the console) and solves the issue.
listener
(The one which is button.dropdown-toggle)

@C-Lodder is it fine if I remove it?

avatar Subhang23 Subhang23 - change - 15 Feb 2020
Title
[4.0][W.I.P] fixed error of dropdown not closing
[4.0]fixed error of dropdown not closing
avatar Subhang23 Subhang23 - edited - 15 Feb 2020
avatar Subhang23
Subhang23 - comment - 15 Feb 2020

@C-Lodder @brianteeman Can you review this?

avatar brianteeman
brianteeman - comment - 15 Feb 2020

I cannot comment on the code but it does do what it is supposed to do

avatar Subhang23
Subhang23 - comment - 15 Feb 2020

The dropdown.js file attaches a click event listener which has .stopPropagation() function due to which a listener attached on the document was not working. So that is why I had to attach a listener to those elements

avatar Subhang23
Subhang23 - comment - 18 Feb 2020

@C-Lodder what more changes should I do?

avatar C-Lodder
C-Lodder - comment - 18 Feb 2020

Code seems a bit "dirty" and trying to reinvent the wheel but if it works then fine.
I haven't really got the time to look further into it.

avatar Quy Quy - change - 29 Oct 2020
Status Pending Closed
Closed_Date 0000-00-00 00:00:00 2020-10-29 17:47:11
Closed_By Quy
avatar Quy Quy - close - 29 Oct 2020

Add a Comment

Login with GitHub to post a comment