Problem/Motivation
Current implementation of dropdown is very complicated:
- split between dropdown & dropdown_item is useless
- call to button pattern is hardcoded in Twig (3 times!)
{% if variant|lower != 'btn_group__dropstart' %}
{{ pattern('button', {
label: title,
attributes: split_button_attributes
}, button_variant) }}
{% endif %}
{{ pattern('button', {
label: 'Toggle Dropdown'|t,
label_visually_hidden: true,
attributes: button_attributes.addClass('dropdown-toggle-split').setAttribute('id', false)
}, button_variant) }}
{% else %}
{{ pattern('button', {
label: title,
attributes: button_attributes
}, button_variant) }}
{% endif %}
Source: https://git.drupalcode.org/project/ui_suite_bootstrap/-/blob/5.0.x/templ...
- the different cases (split, button group, direction...) are managed by 6 variants & 8 settings
Source: https://git.drupalcode.org/project/ui_suite_bootstrap/-/blob/5.0.x/templ...
Proposed resolution
On ui_suite_bootstrap 4, we have a simpler implementation:
Of course, BS5 dropdown is a bit more complicated than BS4 dropdown:
But we guess it will be OK to add them while keeping the simple structure.
Remaining tasks
I will try to propose a MR soon.
This MR will also change the call to dropdown from navbar-nav.
API changes
Yes, but still in alpha so it is OK.
Comments
Comment #2
grimreaperComment #3
grimreaperComment #7
grimreaperI opened the new MR https://git.drupalcode.org/project/ui_suite_bootstrap/-/merge_requests/50, because previous one needed a rebase and to make the rebase easier I squashed the commits so to not lose the history, I pushed this squashed and rebased version on a new branch, so new MR.
Comment #10
grimreaperAs discussed, MR 50 had not been tested on real usage with menus, and modules like https://www.drupal.org/project/menu_link_attributes to allow to add classes/attributes on the link and/or on the wrapper.
Also, the nav pattern had been forgotten in the refactoring.
I tried to make it work, but it is too time consuming and I have side effects on side effects.
The main problems:
- in real menu links, "url" is a URL object which options contains the attributes that will be used on the a tag.
- also the route of the URL object can determine extra behavior like that will display a span and that will display a button.
- in real menu links, attributes is then for the link wrapper.
- not using the link() method bypass attributes put on the link. And do not use the link generator system of Drupal that can be altered.
- so I don't think the patterns should be done based on a structure easily manipulable in YAML preview structure but based on a "real" structure.
I know there is the subject of removing PHP preprocess from themes, but I think here it is needed.
Comment #11
grimreaperThe navbar rework had not taken into account:
- ui_suite_bootstrap/templates/overrides/block/block--system-branding-block.html.twig
- ui_suite_bootstrap/templates/overrides/system/page.html.twig
- adding a new region to the theme.
Also navbar-brand class should be added directly on the link not on a div around the link.
Comment #12
grimreaperCurrently navbar collapse does not work anymore on mobile.
I am trying to figure out why and when this happened.
Comment #13
pdureau commentedThe next opportunity to simplify this pattern will be by leevraging this new setting type: #3345071: Add links setting type
Comment #14
grimreaperI found the problem about the navbar on mobile #3346067: Page navbar action should be collapse.
I think I also found out (I need to check by settings back theme to Olivero or Bootstrap 3) that the attributes allowing to mark links as active are not properly transmitted.
So native active system does not work and it prevents modules like https://www.drupal.org/project/menu_trail_by_path to work.
Comment #15
grimreaperWhen updating #3292600: Bootstrap 5 : Components > Toasts MR, I found out that
|default('true')or|default(true)was bad for ensuring boolean settings default value. Ok for false, but as false or null is evaluated the same way having|default(true)force the setting value to true even when FALSE.The only pattern having that is the dropdown in:
{% set auto_close = auto_close|default('true') %}Comment #18
pdureau commentedWe move here #3369769: Bootstrap 5: Convert menu, breadcrumb and pagers to the links prop type