-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: return to initial state when reseting hash in Accordion & Tabs #11100 #11477
fix: return to initial state when reseting hash in Accordion & Tabs #11100 #11477
Conversation
…oundation#11100 When deep-linking is enabled and the user goes back in the history up to when no hash is set, display the initially-selected content/tab instead of staying with the content/tab that was selected the first. Closes foundation#11100 Replaces foundation#11101 Co-authored-by: Jamie Chong <jamie@hippocurious.com>
d01d8b6
to
5ea51f3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ncoden I've tested the accordion and it works – but only if an item is initially active!
If no item has initially the class is-active
is fails.
I think we should cover that case, too.
js/foundation.tabs.js
Outdated
//need a hash and a relevant anchor in this tabset | ||
if(anchor.length) { | ||
if (anchor.length) { | ||
var anchorNoHash = (anchor.indexOf('#') >= 0 ? anchor.slice(1) : anchor); | ||
var $link = this.$element.find(`[href$="${anchor}"],[data-tabs-target="${anchorNoHash}"]`).first(); | ||
if ($link.length) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an other issue, not related to this pull request. Why not, but I wonder what's the impact on accessibility to move the focus like this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Talking abt accessibility: I've noticed the tabindex
gets always set to -1
for the inactive tabs what makes it impossible to navigate through the tabs via keyboard (quite bad imo)
but you're right, it's not supposed to be part of this PR
When going back in history, the Accordion without any panel active is still considered as in its "initial state".
Split DOM operations from logics in Accordion "up" and "down" methods
@SassNinja I refactored the component to clean up a bit the logic and split the options processing/component logic from simple DOM manipulations. It should resolve the first bug you pointed out. |
@SassNinja Could you review this again please ? :) |
It's working better now: history back adjust the adressbar as expected. But the active state is not working as expected: |
|
Actually, I fixed this issue in the Accordion component, but not in Tabs. 😄 |
Just to be clear: the accordion component works as expected. Here's a quick gist with the content of my |
Yeah I got it. I need to do the same refactor in Tabs as I did in Accordion to resolve it. I'll take care of this sunday. |
@SassNinja I made the requested changes. 👋 Could you test it again? |
@ncoden lgtm 👍 Just two things don't look nice
But nothing related to this PR – so good to merge imo. |
…nking-11100 for v6.5.0 5ea51f3 fix: return to initial state when reseting hash in Accordion & Tabs foundation#11100 314b4ee fix: fix initial state for Accordion without any panel active abbbdbf refactor: split DOM operations from logics in Accordion e261905 refactor: move "init only" Accordion logic to its own methods b819faf docs: remove outdated comments in Accordion related to the initial state 7307c43 feat: add "Tabs._collapse()" to collapse the active tab 012db10 refactor: clean up the Tab initialization c6d37c4 fix: close the active Tab when going back to a "tab-less" history state 2673567 docs: fix "zplugin" typo in Accordion & Tabs events Signed-off-by: Nicolas Coden <nicolas@ncoden.fr>
Description
When deep-linking is enabled and the user goes back in the history up to when no hash is set, the active panel or tab does not change and is still the one that was selected the first.
This pull request make Accordion and Tabs displaying the panel or tab that was active at the component initialization.
Changes:
_initialAnchor
)""
.Types of changes
Checklist
develop
ordevelop-v...
).I have updated the documentation accordingly to my changes (if relevant).I have added tests to cover my changes (if relevant).