Skip to content

fix: applies-switch and tab-set first tab hidden when block contains a comment#3255

Open
Mpdreamz wants to merge 1 commit intomainfrom
fix/tab-rendering
Open

fix: applies-switch and tab-set first tab hidden when block contains a comment#3255
Mpdreamz wants to merge 1 commit intomainfrom
fix/tab-rendering

Conversation

@Mpdreamz
Copy link
Copy Markdown
Member

@Mpdreamz Mpdreamz commented May 6, 2026

Why

Any non-item block inside {applies-switch} or {tab-set} — such as a MyST % comment — occupies index 0 in Markdig's child list, pushing all {applies-item} / {tab-item} blocks to indices 1, 2, 3 …

The Razor templates use Model.Index == 0 to emit checked="checked" on the first radio input, which is what the pure-CSS tab mechanism relies on to show the first panel. When Index is never 0, no radio is checked, and all tab content stays hidden until the user clicks a tab.

The real-world trigger was a % TODO comment in the query-logs source:

::::::{applies-switch}

% TODO: Update ECH and ECE tabs when Cloud UI supports configuring query logging settings directly.

:::::{applies-item} ess:
…

This caused #3254.

What

Changed AppliesItemBlock and TabItemBlock to compute their index relative to sibling items only, rather than among all children of the parent block:

// Before — breaks when any non-item block precedes the first item
Index = Parent!.IndexOf(this);

// After — always yields 0, 1, 2 … regardless of other block types
Index = Parent!.OfType<AppliesItemBlock>().ToList().IndexOf(this);

Added a regression test (ApplicabilitySwitchWithCommentTests) that places a % comment before the first {applies-item} and asserts both that indices are 0-based and that the first radio renders with checked="checked".

…b selection

Any non-item block inside {applies-switch} or {tab-set} (e.g. a % comment)
occupies index 0 in the Markdig child list, pushing all {applies-item} /
{tab-item} blocks to indices 1, 2, 3 …  The Razor templates use
`Model.Index == 0` to emit `checked="checked"` on the first radio input;
when that condition never fires no tab content is visible on initial load.

Before — broken when a comment precedes the first item:

  ::::::{applies-switch}

  % TODO: update when Cloud UI supports this

  :::::{applies-item} ess:
  …content…
  :::::
  ::::::{applies-switch}

  The first radio renders without `checked`; all tab panels stay hidden
  until the user clicks a tab.

After — counts only sibling items, ignoring other block types:

  Index = Parent!.OfType<AppliesItemBlock>().ToList().IndexOf(this);

Fixes #3254

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
@Mpdreamz Mpdreamz requested a review from a team as a code owner May 6, 2026 07:33
@Mpdreamz Mpdreamz added the bug label May 6, 2026
@Mpdreamz Mpdreamz requested a review from reakaleek May 6, 2026 07:33
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 6, 2026

Warning

Rate limit exceeded

@Mpdreamz has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 39 minutes and 12 seconds before requesting another review.

To continue reviewing without waiting, purchase usage credits in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 6068b4a6-8606-4e65-87b5-e4a597f82441

📥 Commits

Reviewing files that changed from the base of the PR and between b31505c and 555a521.

📒 Files selected for processing (3)
  • src/Elastic.Markdown/Myst/Directives/AppliesSwitch/AppliesSwitchBlock.cs
  • src/Elastic.Markdown/Myst/Directives/Tabs/TabSetBlock.cs
  • tests/Elastic.Markdown.Tests/Directives/ApplicabilitySwitchTests.cs
✨ Finishing Touches
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch fix/tab-rendering

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants