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

Tabs: Fix issue where selecting a tab in a set with no active tab errors out #2383

Merged
merged 3 commits into from
Apr 25, 2024

Conversation

austinoneil
Copy link
Contributor

@austinoneil austinoneil commented Apr 1, 2024

Description

Fix issue where selecting a tab in a set with no active tab errors out.

References #2197

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update

How Has This Been Tested?

Added E2E test, manually tested using provided HTML (thank you, reporter)

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules
  • I have checked my code and corrected any misspellings

Copy link

netlify bot commented Apr 1, 2024

Deploy Preview for moduswebcomponents ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 137c3ea
🔍 Latest deploy log https://app.netlify.com/sites/moduswebcomponents/deploys/660c80013f11c8000894644d
😎 Deploy Preview https://deploy-preview-2383--moduswebcomponents.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 28 (🟢 up 2 from production)
Accessibility: 98 (no change from production)
Best Practices: 92 (no change from production)
SEO: 92 (no change from production)
PWA: -
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify site configuration.

@coliff coliff changed the title Tabs:Fix issue where selecting a tab in a set with no active tab errors out Tabs: Fix issue where selecting a tab in a set with no active tab errors out Apr 1, 2024
@coliff coliff added the bug Something is wrong and needs to be addressed label Apr 1, 2024
if (id === this.tabs.find((tab) => tab.active).id) {
const activeTab = this.tabs.find((tab) => tab.active);

if (activeTab != undefined && activeTab.id) {
Copy link
Contributor

Choose a reason for hiding this comment

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

@austinoneil This can be simplified a bit further with

if (activeTab?.id != null) {
    return;
}

We can leverage optional chaining and != null for nullish coalescing. If you can make this small change I will go ahead and merge afterwards.

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 change was fixing an issue with an if statement that appeared to avoid emitting if the active tab was clicked. This change breaks some tests. That said, it looks like my change breaks some functionality. I'll fix it and add a test and push.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, though adding a test proved to be difficult (it uses spyOn for event emitters, which seems to be causing test issues in main with other tests as well)

Copy link
Contributor

Choose a reason for hiding this comment

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

@austinoneil Can you go more into detail about what you mean by "seems to be causing test issues in main"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@cjwinsor When I run npm run test locally on main, I get the failures for the following tests:

Both are related to using the spyOn method and both are failing on my machine on main. I do not know whether this is an issue with my setup or if it's failing across the board. I am running nvm use 18.17.0 when opening my IDE.

@cjwinsor
Copy link
Contributor

@austinoneil Very peculiar, I switched to 18.17.0 and ran tests against main without issue on my windows laptop. I'm going to keep my eye on this and get I get a chance try to run within a sandbox and wsl.

@cjwinsor cjwinsor merged commit 3fb8626 into trimble-oss:main Apr 25, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something is wrong and needs to be addressed modus-tabs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants