-
Notifications
You must be signed in to change notification settings - Fork 320
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
Conversation
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? |
Thanks for the review @36degrees 👍 I've added a test where the contents of the tab label are replaced with a DOM element. |
src/components/tabs/tabs.test.js
Outdated
}) | ||
|
||
// Click the second tab | ||
await page.click('.govuk-tabs__list-item:nth-child(2) .govuk-tabs__tab') |
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.
Should the click event be on the new <span>
element?
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.
…jinx? 😆
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.
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.
src/components/tabs/tabs.test.js
Outdated
}) | ||
|
||
// Click the second tab | ||
await page.click('.govuk-tabs__list-item:nth-child(2) .govuk-tabs__tab') |
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.
To test the bubbling, don't we need to click on the span?
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.
See comment above 🙏
eb8fd9e
to
c7aa29e
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.
This looks like a tricky one to figure out, nice work. 👍
c7aa29e
to
5317541
Compare
5317541
to
007b852
Compare
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
to
govuk-frontend/src/components/tabs/_tabs.scss
Line 46 in 840d019
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 setEdit: Had a discussion with the team. We currently can't see a user need to make larger changes to the API.| 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.Also created a tech debt issue to look at refactoring the tabs Javascript at some point.
Browser testing:
Fixes #1252