Skip to content
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

Merged
merged 9 commits into from
Sep 12, 2018

Conversation

ncoden
Copy link
Contributor

@ncoden ncoden commented Aug 26, 2018

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:

  • Save up the active panel/tab at Accordion/Tabs initialization (_initialAnchor)
  • Display the initial panel/tab when the hash change to "".

Types of changes

  • Documentation
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (anything that would change an existing functionality)
  • Maintenance (refactor, code cleaning, development tools...)

Checklist

  • I have read and follow the CONTRIBUTING.md document.
  • The pull request title and template are correctly filled.
  • The pull request targets the right branch (develop or develop-v...).
  • My commits are correctly titled and contain all relevant information.
  • I have updated the documentation accordingly to my changes (if relevant).
  • I have added tests to cover my changes (if relevant).

…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>
@ncoden ncoden force-pushed the fix/initial-tab-deep-linking-11100 branch from d01d8b6 to 5ea51f3 Compare August 26, 2018 21:48
@SassNinja SassNinja self-requested a review August 29, 2018 09:48
Copy link
Contributor

@SassNinja SassNinja left a 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.

//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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the course of testing the tabs I noticed the focus style remains when using history back.

tabs_deep_linking_480px_low

What do you think about auto focusing the link to fix this?

if ($link.length) {
  $link.focus();
  this.selectTab($(anchor), true);

Copy link
Contributor Author

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.

Copy link
Contributor

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

ncoden added 4 commits August 29, 2018 23:57
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
@ncoden
Copy link
Contributor Author

ncoden commented Aug 30, 2018

@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.

@ncoden
Copy link
Contributor Author

ncoden commented Aug 31, 2018

@SassNinja Could you review this again please ? :)

@SassNinja
Copy link
Contributor

SassNinja commented Sep 8, 2018

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:
when I start without an initially opened tab, click on a tab and go back in history, I don't get the original active state (none tab opened). Instead the previously clicked tab is active (although the page url has changed).

@ncoden
Copy link
Contributor Author

ncoden commented Sep 8, 2018

Shall I provide an example repo or is it clear what I mean?

I understood the issue, and thought I resolved it. If you look at the code, you can see that _closeAll() is called if we go back to a state where no link is active.

@ncoden
Copy link
Contributor Author

ncoden commented Sep 8, 2018

Actually, I fixed this issue in the Accordion component, but not in Tabs. 😄

@SassNinja
Copy link
Contributor

Just to be clear: the accordion component works as expected.
The issues described above only refers to the tabs components.

Here's a quick gist with the content of my \test\visual\tabs\deep-linking.html
https://gist.github.com/SassNinja/c194da0830de81a510061c99ffcb8938

@ncoden
Copy link
Contributor Author

ncoden commented Sep 8, 2018

Just to be clear: the accordion component works as expected.
The issues described above only refers to the tabs components.

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.

@ncoden
Copy link
Contributor Author

ncoden commented Sep 10, 2018

@SassNinja I made the requested changes. 👋 Could you test it again?

@ncoden ncoden added this to the 6.5.0 milestone Sep 10, 2018
@SassNinja
Copy link
Contributor

@ncoden lgtm 👍

Just two things don't look nice

  • focus state doesn't get reseted on history back (as mentioned earlier)
  • the hash tag in the browser url doesn't get removed when I toggle a tab, so that no panel is opened (when using data-active-collapse="true")

But nothing related to this PR – so good to merge imo.

@ncoden ncoden merged commit 0358198 into foundation:develop Sep 12, 2018
ncoden added a commit to ncoden/foundation-sites that referenced this pull request Sep 12, 2018
…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>
@ncoden ncoden mentioned this pull request Sep 12, 2018
10 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tabs: Browser back doesn't take us back to default tab
2 participants