Problem/Motivation

Drupal.behaviors.verticalTabs and Drupal.verticalTab[.prototype] add some additional classes and wrapper elements to the vertical tabs component. Currently it isn't possible to override the classes or the wrapper elements without duplicating all of the logic inside the function in a theme.

  1. The Drupal.behavior.verticalTabs and Drupal.verticalTab object hard-code markup of the tab list and (the outermost) wrapper of the vertical tabs component.
  2. The Drupal.verticalTab object is built on the same (unprefixed) CSS classes that should be used only for theming the component.

Proposed resolution

Replace hard-coded markup with Drupal.theme functions and adds 'js-' prefixed CSS classes for the JavaScript functionality:

  1. New theme functions:
    • Provide a theme function for tabList:
      Drupal.theme.verticalTabsMenuListWrapper = () =>
                '<ul class="vertical-tabs__menu"></ul>';
    • Provide a theme function for the outermost wrapper element:
      Drupal.theme.verticalTabsWrapper = () =>
                '<div class="vertical-tabs clearfix"></div>';
  2. Use js-prefixed CSS classes for functionality:
    • Add .js-vertical-tabs-pane to the vertical tabs' details elements and use that CSS class for functionality.
    • Add .js-vertical-tabs-menu-item to the themed output of the vertical tabs menu item (Drupal.theme.verticalTab()) and use that CSS class for functionality.
    • Add .js-vertical-tab-hidden (with vertical-tab-hidden) to the hidden vertical tabs details element and use that CSS class for identifying hidden tabs.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

@todo

CommentFileSizeAuthor
#34 3081489-34-d10.patch33.63 KBlauriii

Issue fork drupal-3081489

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

huzooka created an issue. See original summary.

huzooka’s picture

Issue summary: View changes

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

bnjmnm’s picture

Status: Active » Postponed

Postponed on #1936708: Current element values missing from vertical tabs when shown in 2-column layout and #3081500: Accessibility bugs with vertical tabs as these may lead to structural changes that would make any work prior to that potentially useless.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

lauriii’s picture

Status: Postponed » Active

Discussed with @bnjmnm and @ckrina that we shouldn't block this on #3081500: Accessibility bugs with vertical tabs.

kostyashupenko made their first commit to this issue’s fork.

kostyashupenko’s picture

Status: Active » Needs review
andy-blum’s picture

Status: Needs review » Needs work

Is there a reason js- prefixed classes have to be used in this scenario? @nod_ advised in olivero to use data-attributes for javascript selectors where possible:

we prefer using data- attribute for JS related selection, that way themers are free to do whatever they need with classes without breaking the JS. It came up a few times the past weeks so something must not be clear on core side.

Essentially: js- prefix: better than a "simple" class, dedicated data- attribute = best.

As for the MR from #1, changing just the javascript files won't work, you'll also need to edit the twig markup to add those classes in as well. Additionally, there are no Drupal.theme functions added. This still has quite a ways to go before being ready for review.

kostyashupenko’s picture

Status: Needs work » Needs review

Done & ready for review

kostyashupenko’s picture

I also don't like the idea to add processing classnames (js prefixed, or processing data-attributes) into twig template

kostyashupenko’s picture

kostyashupenko’s picture

I'm just thinking that data attributes like data-olivero-tabs or other similar which were hardcoded in twig template, with disabled javascript these attributes gives nothing

kostyashupenko’s picture

Normally we can catch needed classname on js side and provide all related js prefixed classnames or data-attributes which are necessary to have for js functionality

mherchel made their first commit to this issue’s fork.

lauriii’s picture

I wanted to point out that the reason this is a Claro stable blocker is that Claro has a copy of the vertical tabs JavaScript. The goal of this issue is to be able to remove that, except what comes to the markup overrides. We should probably update the title and issue summary to make that clear.

yogeshmpawar made their first commit to this issue’s fork.

mherchel’s picture

Status: Needs review » Reviewed & tested by the community

Tests are passing! I reviewed the code (I only modified the tests in the MR), and tested the vertical tabs in Seven and Claro.

I did find a preexisting issue, but will open a separate issue against that.

All looks good!

lauriii’s picture

Status: Reviewed & tested by the community » Needs work

I think it's not apparent based on the issue summary / title, but the goal of this issue is that all of the vertical tabs logic is duplicated in Claro. On top of the changes here, we need to get rid of the duplicated code and ensure that works.

justafish’s picture

Assigned: Unassigned » justafish
justafish’s picture

Issue tags: +ddd2022
justafish’s picture

Assigned: justafish » Unassigned
Status: Needs work » Needs review
bnjmnm’s picture

Status: Needs review » Needs work

+1 the "needs issue summary update". Among other things, it is specifically requesting js- prefixed classes, but data attributes are fine as well. It may be worth clarifying that the presentation classes can remain intact, we just want to add js-prefix or data attributes for functionality.

This also strips out the majority of Claro's vertical tabs logic, and I think much of it still needs to be there. My comments on the MR elaborate on some of this, but the top of core/themes/claro/js/vertical-tabs.es6.js describes all the fixes provided. I'm not sure that much can be removed until the issues fixed in that file are addressed in core, but a more targeted extraction can certainly happen.

There's a meta tracking most/all(?) of the issues that would need to land for the big Claro extract
👉 #3081521: Refactor vertical tabs, remove vertical-tabs.js replacement when core issues are resolved

lauriii’s picture

Title: Move hard coded vertical tabs classes to a theme function and use js-prefixed classes for functionality » Remove duplicate code from veritcal-tabs.js in Claro

We need to update the issue summary with the latest approach for this. I closed #3081521: Refactor vertical tabs, remove vertical-tabs.js replacement when core issues are resolved based on discussion with @bnjmnm, @ckrina, @saschaeggi and @Gábor Hojtsy to focus on doing the minimum required work for removing the duplicate code from vertical-tabs.js in Claro – even if that means that we are causing accessibility regressions within Claro, so long as the experience takes the vertical tabs on par with the core experience. The accessibility issues with vertical tabs are not specific to Claro, and therefore they should not have an impact on Claro's stability.

mherchel’s picture

If we end up removing the bespoke Claro vertical tab code, then we can probably also close #3272316: Claro's vertical tabs' aria states don't always properly reflect state at mobile

bnjmnm’s picture

Re #28 that jogged my memory and you're right, we decided Claro regressing a bit is fine as long as it does not introduce problems not present in other themes.

I mention in the thread, but there is one bug introduced by the full removal that should be accounted for (unless it turns out to be an issue with my review instance). With this MR, if I load a page with vertical tabs on a wide viewport, then reduce to narrow, the inactive vertical tabs disappear entirely. I suspect a bit of CSS could address that, however.

webchick’s picture

HELLOOOOO from DrupalCon! :D

I was asked to weigh in here by @lauriii and @ckrina, after having the situation explained to me.

I'm in favour of removing the vertical-tabs.js overrides because a) it sounds like according to @mherchel they cause some ARIA problems, and b) falling back to default core behaviour sounds like the quickest way to get us stable Claro fastest. BUT it would be great not to lose those improvements, so if we could spin off a sub-issue for them to pursue after Claro's stable, that sounds great.

lauriii’s picture

Status: Needs work » Needs review
mherchel’s picture

Status: Needs review » Reviewed & tested by the community

Review and tested. Looks good with no regressions vs Seven.

RTBC per tests passing! 🎉

lauriii’s picture

StatusFileSize
new33.63 KB

  • ckrina committed dffe17c on 10.0.x
    Issue #3081489 by kostyashupenko, mherchel, justafish, andy-blum,...

  • ckrina committed 4b6a0ad on 9.4.x
    Issue #3081489 by kostyashupenko, mherchel, justafish, andy-blum,...
ckrina’s picture

Status: Reviewed & tested by the community » Fixed

Committed dffe17c and pushed to 10.0.x and 9.4.x. Thanks!

lauriii’s picture

🥳🥳🥳

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.