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 flash of unstyled content in tabs component #1000

Merged
merged 4 commits into from
Sep 17, 2018

Conversation

NickColley
Copy link
Contributor

@NickColley NickColley commented Sep 14, 2018

Closes #927

On slow connections or devices users can see a flash of the unstyled version of the tabs.

This PR updates the tab component so that it's initial state can be set without the need for JavaScript.

I experimented with being able to set a specific panel, which I thought would allow rendering of selected tabs without any flashing, but since the hash set in the URL is not available to the server this would not be practical. - https://stackoverflow.com/a/318581

Since I could not think of an immediate need for someone to set a default tab other than the first one it seemed over the top and something we could add later on.

Demonstrations

Before, flash of unstyled content

before-tabs-unstyled-flash

After, no flash with default tab

after-tabs-unstyled-flash

Flash when changing tabs and reloading

after-tabs-unstyled-flash-selected-tab

https://trello.com/c/sNeuUPNH/1386-2-fix-flashes-of-unstyled-content-caused-by-the-tabs-component

@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-review-pr-1000 September 14, 2018 15:46 Inactive
@NickColley NickColley changed the title Fix flash of unstyled content tabs Fix flash of unstyled content in tabs component Sep 14, 2018
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-review-pr-1000 September 14, 2018 16:11 Inactive
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-review-pr-1000 September 14, 2018 16:13 Inactive
Prior to this change the only way to avoid a flash of unstyled content was to add the aria-selected attribute into the markup.

But if this attribute requires JavaScript to make sense, since if JavaScript is disabled this markup is not semantically a tabs component.
@NickColley NickColley force-pushed the fix-flash-of-unstyled-content-tabs branch from db39241 to b69abb9 Compare September 14, 2018 16:17
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-review-pr-1000 September 14, 2018 16:17 Inactive
Copy link

@kr8n3r kr8n3r left a comment

Choose a reason for hiding this comment

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

great work !

@@ -80,7 +80,7 @@ Find out when to use the tabs component in your service in the [GOV.UK Design Sy

</section>

<section class="govuk-tabs__panel" id="past-week">
<section class="govuk-tabs__panel govuk-tabs__panel--hidden" id="past-week">
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need both the hidden modifier and the selected modifier? Can the tabs not be hidden by default unless they have the --selected modifier?

Only having one modifier simplifies the code a little bit and also avoids the possibility of a weird 'undefined' state where a tab has neither the selected modifier nor the hidden modifier.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The hidden modifier for the panel is consistent with the conditional reveals, so not sure if it's worth breaking consistency?

Copy link
Contributor

Choose a reason for hiding this comment

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

Possibly… for context ,I know that I ended up refactoring the mobile nav in the Design System so that it didn't have both active and hidden modifiers, because it was confusing (and broken, because sometimes a menu item had neither modifier, and that scenario was poorly defined – see the first commit) so a little wary of this pattern.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree it seems there could be a less error prone way of doing this, but given this is consistent with another component and making tab panels hidden by default would be a breaking change, could we raise that as a separate issue?

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@NickColley NickColley merged commit 58ca5e5 into master Sep 17, 2018
@NickColley NickColley deleted the fix-flash-of-unstyled-content-tabs branch September 17, 2018 16:38
@kr8n3r kr8n3r mentioned this pull request Sep 26, 2018
@dankmitchell dankmitchell mentioned this pull request Oct 3, 2018
92 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tabs result in a flash of unstyled content as the page loads
4 participants