Problem/Motivation
The behavior of vertical tabs Drupal.behaviors.verticalTabs applies the JavaScript features only when the actual screen width is bigger than 640 pixels (or the value of drupalSettings.widthBreakpoint). In the Claro theme, we want to switch between the accordion look and tab look dynamically, right after the browser viewport was resized, without relying on a page (re)load.
Right now, this is not possible without replacing the whole core/misc/vertical-tabs.js; by defining drupalSettings.widthBreakpoint with 0 (or 1?..). Now, this setting is used only by vertical tabs, but since the name of this configuration does not suggest that it is (and will be) used only by vertical tabs, it seems to be safer to remove the unneeded condition from the functionality and replace the original JavaScript asset with our own implementation.
Proposed resolution
Add an another (optional) width breakpoint settings that is used only by vertical tabs, and fall back to the original values if it is undefined:
Replace const width = drupalSettings.widthBreakpoint || 640; with something like const width = drupalSettings.verticalTabsWidthBreakpoint || drupalSettings.widthBreakpoint || 640;.
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | 3081519-4.patch | 1.06 KB | bnjmnm |
Comments
Comment #4
bnjmnmComment #5
bnjmnmComment #6
nod_Let's not add more tech debt, also scoping this type of change to claro only is staring to be concerning. If there is so much override needed in claro it means the core version has problems, either for altering the feature or the markup or something.
The breakpoint was added as a quick & dirty fix. Not as something that should stay or be extended. See the discussion here #1277352: Responsive vertical tabs. The solution should be driven mainly by CSS to simplify (or avoid doing) #2971840: Make responsiveness for vertical tabs configurable. And this issue is part of #1812298: Handle mobile orientation change for JS widgets.
Check out backdrop, they have responsive vertical tabs based on the patch submitted in the first issue: https://github.com/backdrop/backdrop/blob/1.x/core/misc/vertical-tabs.js https://github.com/backdrop/backdrop/blob/1.x/core/misc/vertical-tabs.css
I want to do a proper fix this time and not add more tech debt.
Comment #7
bnjmnm#6 makes sense. This issue may not needed at all, but I'll set it to postponed since there are other issues that should be addressed regardless of the final approach, but it may still be necessary to have width checking in JavaScript. This is due to
the narrow and wide implementations having two different UI patterns. Currently, both Drupal and Backdrop fail to communicate this to assistive tech. A group of details elements is quite different to a screenreader than a tablist. I just added a patch to #3081500: Accessibility bugs with vertical tabs that properly represents vertical tabs as a tablist. It may be possible to achieve this with only CSS via careful hiding/showing of elements, but I'm not certain of this.