Activate tab by link anchor is broken

Created on 5 August 2021, over 3 years ago
Updated 8 September 2024, 4 months ago

Problem/Motivation

In our project, we use field group to create horizontal tabs for the node edit form. So we have the following tabs
- Core details (default open, #edit-group-core-details)
- Content components (closed, #edit-group-content-components)
- Others (closed #edit-group-others)

When we open the node edit page, the tab defaults to 'Core details' which is expected. When we open the page with anchor like '/node/add/page#edit-group-content-components', the second tab is expected to be activated by default.

This is working in ver 8.x-1.0. However this is broken after field_group has been upgraded from ver 1.0 to 3.1. The Drupal version is 8.9.17

Steps to reproduce

- install field_group 3.1
- add horizontal tabs with
- Core details (default open, #edit-group-core-details)
- Content components (closed, #edit-group-content-components)
- Others (closed #edit-group-others)
- add dummy fields to those group and save
- open page to check the first tab should be activated
- open page with anchor to check the second tab should be activated but not

Proposed resolution

I have checked that the default value has been added to the hidden input and it always output a default value in HTML changed by #3066522: Wrong default tab on page load β†’ .

So here is the html of the hidden input when we use ver 1.0

<input class="horizontal-tabs-active-tab" type="hidden" />

Here is the html of the hidden input when we use ver 3.1

<input class="horizontal-tabs-active-tab" data-drupal-selector="edit-group-tabs-group-tabs-active-tab" type="hidden" name="group_tabs[group_tabs__active_tab]" value="edit-group-core-details" />

The logic to find tab_focus is
1. check default value from hidden input
2. if no default value check URL fragment
3. if the default value is found, make it focused

As the default value is always provided in step 1, so activating link from URL fragment does not happen anymore.

Ideally, activating link fragment should take precedence over default tab.

Remaining tasks

N/A

User interface changes

N/A

API changes

N/A

Data model changes

N/A

πŸ› Bug report
Status

Needs work

Version

4.0

Component

Code

Created by

πŸ‡¦πŸ‡ΊAustralia eric.chenchao

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024