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 tabs label child elements breaking #1351

Merged
merged 3 commits into from
May 20, 2019
Merged

Fix tabs label child elements breaking #1351

merged 3 commits into from
May 20, 2019

Conversation

hannalaakso
Copy link
Member

@hannalaakso hannalaakso commented May 15, 2019

Using HTML elements inside the tabs label breaks as event.target is looking at the child element instead of the tab label.

This fix checks for the class of the target to allow the event to bubble up to the parent which is the label.

(Looks like this can also be fixed by adding

    & * {
      pointer-events: none;
    }

to

but it makes more sense to fix this in JS rather than couple the fix with the stylesheet).

Question: Should we change the public API to accommodate adding markup inside the label by having a text and html option? It seems like it would be useful. At the moment it's not possible to add a test (I don't think) to check for this as you can't add Nunjucks from the example yaml to set | safe, it needs to be done in the template. I've tested this locally by amending one of the full page examples following @fofr's example Nunjucks. Edit: Had a discussion with the team. We currently can't see a user need to make larger changes to the API.

Also created a tech debt issue to look at refactoring the tabs Javascript at some point.

Browser testing:

  • Chrome 74
  • Firefox 65
  • OS Safari 11
  • Android Samsung Galaxy (Chrome)
  • iOS XS / 8 (Safari)
  • Edge 18
  • IE 8 - 11

Fixes #1252

@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-review-pr-1351 May 15, 2019 10:48 Inactive
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-review-pr-1351 May 15, 2019 10:49 Inactive
@hannalaakso hannalaakso marked this pull request as ready for review May 17, 2019 09:35
@36degrees
Copy link
Contributor

Seems like a great way to fix this issue. I wonder if we should have a test for this? I know when I was looking at this it was difficult, because we don't have a way to pass HTML for tab labels (yet) – but perhaps we could fake it in the tests by injecting an extra element?

@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-review-pr-1351 May 17, 2019 15:45 Inactive
@hannalaakso
Copy link
Member Author

Thanks for the review @36degrees 👍 I've added a test where the contents of the tab label are replaced with a DOM element.

})

// Click the second tab
await page.click('.govuk-tabs__list-item:nth-child(2) .govuk-tabs__tab')
Copy link
Contributor

Choose a reason for hiding this comment

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

Should the click event be on the new <span> element?

Copy link
Contributor

Choose a reason for hiding this comment

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

…jinx? 😆

Copy link
Member Author

Choose a reason for hiding this comment

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

Okay I've added span to the selector. As the span covers the whole label, the test was actually correctly failing without the bubbling fix as the span was always clicked on - whereas adding more text inside the label made the test pass as the span wasn't clicked on anymore. But agree that it's more correct / explicit clicking on the span.

})

// Click the second tab
await page.click('.govuk-tabs__list-item:nth-child(2) .govuk-tabs__tab')
Copy link
Contributor

Choose a reason for hiding this comment

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

To test the bubbling, don't we need to click on the span?

Copy link
Member Author

Choose a reason for hiding this comment

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

See comment above 🙏

@aliuk2012 aliuk2012 added this to the v3.0.0 milestone May 20, 2019
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-review-pr-1351 May 20, 2019 14:31 Inactive
Copy link
Contributor

@NickColley NickColley left a comment

Choose a reason for hiding this comment

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

This looks like a tricky one to figure out, nice work. 👍

@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-review-pr-1351 May 20, 2019 14:37 Inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

6 participants