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

Improve step by step component double dot problem solving code #473

Merged

Conversation

andysellick
Copy link
Contributor

@andysellick andysellick commented Aug 7, 2018

  • shorten code
  • if no sessionStorage value (i.e. user is arriving at the page cold) highlight the first active link and active step, not the last
  • expand documentation to clarify how this behaves

See the documentation for full details. Expands the solution to this problem:

screen shot 2018-08-07 at 14 47 31


Trello card: https://trello.com/c/LTzIkmOX/776-optimise-default-open-step
Component guide for this PR:
https://govuk-publishing-compon-pr-473.herokuapp.com/component-guide/

@benthorner benthorner temporarily deployed to govuk-publishing-compon-pr-473 August 7, 2018 13:48 Inactive
@andysellick andysellick changed the title Improve double dot problem code Improve step by step component double dot problem solving code Aug 7, 2018
@andysellick andysellick force-pushed the step-nav-double-dot-highlight-first-active-link-and-step branch from 5fcb418 to f659fac Compare August 7, 2018 13:49
@benthorner benthorner temporarily deployed to govuk-publishing-compon-pr-473 August 7, 2018 13:49 Inactive
@andysellick andysellick force-pushed the step-nav-double-dot-highlight-first-active-link-and-step branch from f659fac to e1ae137 Compare August 7, 2018 13:50
@benthorner benthorner temporarily deployed to govuk-publishing-compon-pr-473 August 7, 2018 13:51 Inactive
@andysellick andysellick force-pushed the step-nav-double-dot-highlight-first-active-link-and-step branch from e1ae137 to 75164f9 Compare August 7, 2018 14:39

The current page in the step by step navigation is an anchor link to the top of the page. If there are more than one of these and the user clicks one that is not currently highlighted, that one will be highlighted.
If a user has not clicked a link (i.e. has visited the page without first clicking on a step by step navigation) only the first duplicate link will be highlighted. If that link is not in the active step, the JS makes the highlighted link's parent the active step. If there is no active step, the first active link will be highlighted (but there should always be an active step).
Copy link
Contributor

Choose a reason for hiding this comment

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

If that link is not in the active step, the JS makes the highlighted link’s parent the active step

How would this be possible?

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 code basically goes...

if we've got the same link twice in the component
AND
there's nothing in the session to tell us which link to highlight
AND
the first highlighted link is not in the active step
THEN
change the active step to be the one that the first highlighted link is in

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's the thing I was talking about where the frontend code no longer trusts the backend to be right about which step should be highlighted and expanded, and takes matters into its own hands.

@andysellick andysellick force-pushed the step-nav-double-dot-highlight-first-active-link-and-step branch from 75164f9 to 92d856d Compare August 8, 2018 12:37
@benthorner benthorner had a problem deploying to govuk-publishing-compon-pr-473 August 8, 2018 12:37 Failure
@andysellick andysellick force-pushed the step-nav-double-dot-highlight-first-active-link-and-step branch from 92d856d to 47cd87e Compare August 14, 2018 09:41

if (lastClicked) {
Copy link
Contributor

Choose a reason for hiding this comment

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

should you keep this in? What would happen if the active class couldn't be found either?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If the active class isn't found then this entire function has already exited on line 231. The rest only gets called if there's more than one active class found.

@DilwoarH
Copy link
Contributor

Other than that one comment, it looks good 👍

- shorten
- if no sessionStorage value (i.e. user is arriving at the page cold) highlight the first active link and active step, not the last
- expand documentation to clarify how this behaves
@andysellick andysellick force-pushed the step-nav-double-dot-highlight-first-active-link-and-step branch from 47cd87e to 45b1124 Compare August 15, 2018 07:56
@andysellick andysellick merged commit 98e807f into master Aug 15, 2018
@andysellick andysellick deleted the step-nav-double-dot-highlight-first-active-link-and-step branch August 15, 2018 08:03
@andysellick andysellick mentioned this pull request Aug 15, 2018
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.

None yet

4 participants