Skip to content

[4.0] Collapse / accordion function for categories list#33052

Merged
wilsonge merged 5 commits intojoomla:4.0-devfrom
drmenzelit:4.0-dev-accordion
Aug 9, 2021
Merged

[4.0] Collapse / accordion function for categories list#33052
wilsonge merged 5 commits intojoomla:4.0-devfrom
drmenzelit:4.0-dev-accordion

Conversation

@drmenzelit
Copy link
Copy Markdown
Collaborator

Pull Request for Issue #33042 and #33037 .

Summary of Changes

Extended existent Javascript (shared-categories-accordion.js) to a collapse function for categories with subcategories.
Removed Bootstrap collapse attributes
Added a css for the view

Testing Instructions

See issues

Actual result BEFORE applying this Pull Request

See issues

Expected result AFTER applying this Pull Request

The collapse function works with and without published menu (see explanation in issue #33042

grafik

Documentation Changes Required

@chmst
Copy link
Copy Markdown
Contributor

chmst commented Apr 7, 2021

What do you think about removing line 29 in components/com_content/tmpl/categories/default_items.php? Or at least hide it?
We have nowhere else a text for article counts.

@drmenzelit drmenzelit marked this pull request as draft April 7, 2021 18:54
@drmenzelit
Copy link
Copy Markdown
Collaborator Author

@Fedik it is possible to solve this with Joomla custom elements? I saw a collapse.js, but I'm not good in Javascript and I'm not sure if it can be used in replacement of Bootstrap collapse.

@Fedik
Copy link
Copy Markdown
Member

Fedik commented Apr 7, 2021

What you did is also okay.

If you mean bootstrap/collapse.js, it part of Bootstrap 5 changes
https://getbootstrap.com/docs/5.0/components/collapse/

@dgrammatiko
Copy link
Copy Markdown
Contributor

it is possible to solve this with Joomla custom elements?

Yes and No. Yes as the collapse.js will do the accordion thing but No as the repo is basically abandoned. Even the existing elements that Joomla is using have several defects...

@Fedik she means https://github.com/joomla-projects/custom-elements/blob/master/src/js/collapse/collapse.js which in theory should be CSS framework agnostic

@drmenzelit
Copy link
Copy Markdown
Collaborator Author

@Fedik , @dgrammatiko thank you guys for the answers

@drmenzelit drmenzelit marked this pull request as ready for review April 8, 2021 06:53
@hans2103
Copy link
Copy Markdown
Contributor

hans2103 commented Apr 10, 2021

@drmenzelit what if... we change it into <detail> and <summary>?
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/details

It will collapse out of the box.

@dgrammatiko
Copy link
Copy Markdown
Contributor

what if... we change it into and

We are already doing it in

<details open>
<summary>${this.summarytext}</summary>
<div class="">
<div class="form-group">
<div class="input-group">
<label class="input-group-text" for="${this.parentId}-alt">${this.alttext}</label>
<input class="form-control" type="text" id="${this.parentId}-alt" />
</div>
</div>
<div class="form-group">
<div class="form-check">
<input class="form-check-input" type="checkbox" id="${this.parentId}-alt-check">
<label class="form-check-label" for="${this.parentId}-alt-check">${this.altchecktext}</label>
<div><small class="form-text text-muted">${this.altcheckdesctext}</small></div>
</div>
</div>
<div class="form-group">
<div class="form-check">
<input class="form-check-input" type="checkbox" id="${this.parentId}-lazy" checked>
<label class="form-check-label" for="${this.parentId}-lazy">${this.lazytext}</label>
</div>
</div>
<div class="form-group">
<div class="input-group">
<label class="input-group-text" for="${this.parentId}-classes">${this.classestext}</label>
<input class="form-control" type="text" id="${this.parentId}-classes" />
</div>
</div>
<div class="form-group">
<div class="input-group">
<label class="input-group-text" for="${this.parentId}-figclasses">${this.figclassestext}</label>
<input class="form-control" type="text" id="${this.parentId}-figclasses" />
</div>
</div>
<div class="form-group">
<div class="input-group">
<label class="input-group-text" for="${this.parentId}-figcaption">${this.figcaptiontext}</label>
<input class="form-control" type="text" id="${this.parentId}-figcaption" />
</div>
</div>
</div>
</details>`;

@drmenzelit
Copy link
Copy Markdown
Collaborator Author

@drmenzelit what if... we change it into <detail> and <summary>?
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/details

It will collapse out of the box.

That is a good idea! I will look into it

@drmenzelit
Copy link
Copy Markdown
Collaborator Author

summary / detail will not fit in this case, because we need a link to the category too.

@joomdonation
Copy link
Copy Markdown
Contributor

I tested this and it worked. So if one of our frontend dev looks at this and confirm that the solution is OK, I will post my test result. Hope it will be merged before next RC.

@Fedik
Copy link
Copy Markdown
Member

Fedik commented Jul 25, 2021

It looks good to me,
I only think that the CSS added here need to be part of the template style

@drmenzelit
Copy link
Copy Markdown
Collaborator Author

I think a little bit of CSS is important to make the categories list looks good independently of the template used (we have CSS also on some core modules). We can improve things in Cassiopeia and other templates can use or override the CSS here.

@dgrammatiko
Copy link
Copy Markdown
Contributor

I only think that the CSS added here need to be part of the template style

No, the css should not be monolithic. Joomla is modular and the css/js should be modular

@joomdonation
Copy link
Copy Markdown
Contributor

@dgrammatiko So this PR is fine as how it is? Or should the css/js code be moved to system assets so that we can use accordion anywhere we want? If it is fine, I will submit my test result as I tested the feature and it is working well.

@dgrammatiko
Copy link
Copy Markdown
Contributor

Or should the css/js code be moved to system assets so that we can use accordion anywhere we want?

Good question. Turns out that this is the 3rd accordion that Joomla 4 will ship:

  • Bootstrap accordion
  • Joomla Custom Elements tabs (which also renders accordions)
  • this one

But then again if this is working as expected and passes the a11y reqs it's fine

@drmenzelit
Copy link
Copy Markdown
Collaborator Author

it is possible to solve this with Joomla custom elements?

Yes and No. Yes as the collapse.js will do the accordion thing but No as the repo is basically abandoned. Even the existing elements that Joomla is using have several defects...

@Fedik she means https://github.com/joomla-projects/custom-elements/blob/master/src/js/collapse/collapse.js which in theory should be CSS framework agnostic

@dgrammatiko I asked for Joomla Custom Elements before...
I don't mind, if this PR get rejected, if there is another thing that do the job. I wanted to have a framework agnostic solution....

@dgrammatiko
Copy link
Copy Markdown
Contributor

@dgrammatiko I asked for Joomla Custom Elements before...

I know and I answered that you shouldn't use that code (collapse) which is still true today. What changed is that I rewrote from scratch the Tabs but for this particular instance a plain (ie non CE) implementation is better (ie less code)
The PR is totally fine as is

@dgrammatiko
Copy link
Copy Markdown
Contributor

@drmenzelit since the js file is loaded as a module the code shouldn't use the iife, should be like:

/**
 * @copyright  (C) 2018 Open Source Matters, Inc. <https://www.joomla.org>
 * @license    GNU General Public License version 2 or later; see LICENSE.txt
 */

if (!Joomla || !Joomla.Text) {
  throw new Error('core.js was not properly initialised');
}

// Selectors used by this script
const buttonsSelector = '[id^=category-btn-]';

/**
 * Handle the category toggle button click event
 * @param event
 */
const handleCategoryToggleButtonClick = ({ currentTarget }) => {
  const button = currentTarget;
  const icon = button.querySelector('span');

  // Toggle icon class
  icon.classList.toggle('icon-plus');
  icon.classList.toggle('icon-minus');

  // Toggle aria label, aria-expanded
  const ariaLabel = button.getAttribute('aria-label');
  const ariaExpanded = button.getAttribute('aria-expanded');
  button.setAttribute(
    'aria-label',
    (
      ariaLabel === Joomla.Text._('JGLOBAL_EXPAND_CATEGORIES') ? Joomla.Text._('JGLOBAL_COLLAPSE_CATEGORIES') : Joomla.Text._('JGLOBAL_EXPAND_CATEGORIES')
    ),
  );
  button.setAttribute(
    'aria-expanded',
    (
      ariaExpanded === 'false' ? 'true' : 'false'
    ),
  );

  const target = button.nextElementSibling;
  target.toggleAttribute('hidden');
};

Array.from(document.querySelectorAll(buttonsSelector)).forEach((button) => {
  button.addEventListener('click', handleCategoryToggleButtonClick);
});

@Fedik
Copy link
Copy Markdown
Member

Fedik commented Jul 25, 2021

No, the css should not be monolithic. Joomla is modular and the css/js should be modular

If you look in CSS it doing nothing "category specific", it just a general styling like display:flex and stuff, which I suspect can be done with .d-flex and other bootstrap. classes.

It not much important to me, I only saying that it can be done without this file

@drmenzelit
Copy link
Copy Markdown
Collaborator Author

I have modified the JS file as suggested by @dgrammatiko

@dgrammatiko
Copy link
Copy Markdown
Contributor

@drmenzelit you have to push the changes to Github...

@drmenzelit
Copy link
Copy Markdown
Collaborator Author

@drmenzelit you have to push the changes to Github...

My notebook is driving me crazy today... push is done now

@joomdonation
Copy link
Copy Markdown
Contributor

I have tested this item ✅ successfully on acca0c3

I don't have good enough frontend skill to confirm the solution is valid or not. But it is working as expected, tested it again today.


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

@hans2103
Copy link
Copy Markdown
Contributor

I have tested this item ✅ successfully on acca0c3


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

@chmst
Copy link
Copy Markdown
Contributor

chmst commented Jul 30, 2021

RTC


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

@joomla-cms-bot joomla-cms-bot added the RTC This Pull Request is Ready To Commit label Jul 30, 2021
@wilsonge
Copy link
Copy Markdown
Contributor

One question about presets otherwise fine to merge for 4.0.0 as this is core functionality. Thanks for reviewing the JS @dgrammatiko !

@wilsonge wilsonge merged commit c2740e9 into joomla:4.0-dev Aug 9, 2021
@wilsonge
Copy link
Copy Markdown
Contributor

wilsonge commented Aug 9, 2021

Thanks!

@joomla-cms-bot joomla-cms-bot removed the RTC This Pull Request is Ready To Commit label Aug 9, 2021
@wilsonge wilsonge added this to the Joomla 4.0 milestone Aug 9, 2021
@drmenzelit drmenzelit deleted the 4.0-dev-accordion branch September 26, 2021 17:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

NPM Resource Changed This Pull Request can't be tested by Patchtester

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants