Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/wise-boats-flow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/starlight': patch
---

Fix issue with nested `<Tabs>` components
2 changes: 1 addition & 1 deletion packages/starlight/user-components/Tabs.astro
Original file line number Diff line number Diff line change
Expand 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().

this.panels = [...this.querySelectorAll<HTMLElement>('[role="tabpanel"]')];
this.panels = [...this.querySelectorAll<HTMLElement>(':scope > [role="tabpanel"]')];

this.tabs.forEach((tab, i) => {
// Handle clicks for mouse users
Expand Down