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 issue with nested <Tabs> components #473

Merged
merged 2 commits into from
Aug 8, 2023

Conversation

HiDeoo
Copy link
Member

@HiDeoo HiDeoo commented Aug 8, 2023

What kind of changes does this PR include?

  • Changes to Starlight code

Description

This pull request fixes an issue reported on Discord regarding nested tabs.

The panels hidden property was not being set correctly due to the query selector matching all nested panels instead of just the direct children.

I updated it to use the :scope CSS pseudo-class to only match the direct children.

I don't think we have a proper way to test this yet so here is a video of a manual test:

demo.mp4

@changeset-bot
Copy link

changeset-bot bot commented Aug 8, 2023

🦋 Changeset detected

Latest commit: 3fbc696

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@astrojs/starlight Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@netlify
Copy link

netlify bot commented Aug 8, 2023

Deploy Preview for astro-starlight ready!

Name Link
🔨 Latest commit 3fbc696
🔍 Latest deploy log https://app.netlify.com/sites/astro-starlight/deploys/64d282472043080008f71eb4
😎 Deploy Preview https://deploy-preview-473--astro-starlight.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

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

@github-actions github-actions bot added the 🌟 core Changes to Starlight’s main package label Aug 8, 2023
Copy link
Member

@delucis delucis left a comment

Choose a reason for hiding this comment

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

Thanks for the quick fix @HiDeoo! First time I’ve seen :scope — super handy.

I’ll admit seeing your demo gives me UI anxiety — not sure anyone should be using nested tabs 😅 — but if people want to I guess we enable them 😆

One quick question: did you test the keyboard navigation by any chance to make sure it also works as expected with this set-up?

@@ -77,7 +77,7 @@ const { html, panels } = processPanels(panelHtml);
super();
const tablist = this.querySelector<HTMLUListElement>('[role="tablist"]')!;
this.tabs = [...tablist.querySelectorAll<HTMLAnchorElement>('[role="tab"]')];
Copy link
Member

Choose a reason for hiding this comment

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

Don’t we need a similar approach for this selector too?

Copy link
Member Author

@HiDeoo HiDeoo Aug 8, 2023

Choose a reason for hiding this comment

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

We actually do not (which is quite neat as those are not direct children and would need longer selectors):

  • The first one is using querySelector() and not querySelectorAll() so it only return the first result which is what we want.
  • The second one is based on the result of the first one so it's also what we want.

Basically only the last one was an issue as it was based on the component (this) and was using querySelectorAll().

@HiDeoo
Copy link
Member Author

HiDeoo commented Aug 8, 2023

First time I’ve seen :scope — super handy

Ah yeah definitely not the most common pseudo-class ^^

I’ll admit seeing your demo gives me UI anxiety

I lost myself in the tabs making that video 😆

did you test the keyboard navigation by any chance to make sure it also works as expected with this set-up?

I actually did and forgot to mention it. Here is a new video of only keyboard navigation which work as expected:

keyboard.mp4

Copy link
Member

@delucis delucis left a comment

Choose a reason for hiding this comment

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

This fix is much more lovely than nested tabs deserve. Thanks for that and the clear tests and explanations. Great work @HiDeoo 🙌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🌟 core Changes to Starlight’s main package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants