Skip to content

fix(RadioGroup): forward parent scope id onto RadioGroupItem control (#2751) - #2755

Merged
zernonia merged 1 commit into
v2from
fix/radiogroupitem-scope-id-2751
Jun 24, 2026
Merged

zernonia merged 1 commit into
v2from
fix/radiogroupitem-scope-id-2751

Conversation

@zernonia

@zernonia zernonia commented Jun 24, 2026 •

Copy link
Copy Markdown
Member

Description

Fixes #2751.

RadioGroupItem sets inheritAttrs: false and renders the multi-root Radio (visible control + sibling hidden form input) as its root. Because of this, Vue's automatic parent scope-id fallthrough is dropped, so when a consumer uses RadioGroupItem as a styled element under <style scoped>, the data-v-xxxx attribute never lands on the rendered control and the scoped CSS rules don't apply.

The fix forwards the parent scope id with the existing useForwardScopeId() helper (the same approach introduced for the multi-root form controls in #2720) and spreads it onto the inner Radio.

Similar case caught

While auditing for the same pattern, ToggleGroupItem was found to wrap the multi-root Toggle in exactly the same way and had the identical bug (confirmed failing with a regression test before the fix). It gets the same useForwardScopeId() treatment.

Other multi-root form controls (Checkbox, Switch, Toggle, Radio) already forward the scope id, and the remaining *Root components render their hidden input nested inside a single Primitive root, so they are unaffected.

Tests

Added regression tests in useForwardScopeId.test.ts using scoped-style fixtures (_ScopedRadioGroup.vue, _ScopedToggleGroup.vue) that assert the parent scope id reaches the control's <button> for both RadioGroupItem and ToggleGroupItem.

  • pnpm --filter reka-ui exec vitest run (affected suites) ✅
  • pnpm lint (0 errors) ✅
  • pnpm --filter reka-ui type-check ✅

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Scoped CSS now applies correctly to items inside radio and toggle groups, even when they wrap other components.
    • Improved style inheritance so custom component styles continue to work as expected in nested setups.
  • Tests

    • Added coverage for scoped-style behavior in radio and toggle group examples.

…2751)

`RadioGroupItem` sets `inheritAttrs: false` and wraps the multi-root `Radio`,
so Vue's automatic parent scope-id fallthrough is dropped and a consumer's
`<style scoped>` rules never reach the rendered control.

Forward the parent scope id via `useForwardScopeId()` so scoped styles apply.
`ToggleGroupItem` wraps `Toggle` the same way and had the identical bug, so it
gets the same fix. Adds regression tests for both via scoped-style fixtures.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jun 24, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 69cde97d-1e6e-44c6-b09c-ef4b7011d638

📥 Commits

Reviewing files that changed from the base of the PR and between 178e6cd and d4e0d55.

📒 Files selected for processing (5)
  • packages/core/src/RadioGroup/RadioGroupItem.vue
  • packages/core/src/RadioGroup/story/_ScopedRadioGroup.vue
  • packages/core/src/ToggleGroup/ToggleGroupItem.vue
  • packages/core/src/ToggleGroup/story/_ScopedToggleGroup.vue
  • packages/core/src/shared/useForwardScopeId.test.ts

📝 Walkthrough

Walkthrough

RadioGroupItem and ToggleGroupItem now call useForwardScopeId() to obtain scopeIdAttrs and merge them into the v-bind of their inner Radio and Toggle components respectively. Two new story fixtures (_ScopedRadioGroup.vue, _ScopedToggleGroup.vue) and two new Vitest test cases are added to validate that data-v-* scope IDs propagate correctly to the inner button element.

Changes

Scoped Style ID Forwarding for RadioGroupItem and ToggleGroupItem

Layer / File(s) Summary
RadioGroupItem scope ID forwarding
packages/core/src/RadioGroup/RadioGroupItem.vue
Imports useForwardScopeId, computes scopeIdAttrs, and spreads them into the Radio component's v-bind ahead of $attrs and props.
ToggleGroupItem scope ID forwarding
packages/core/src/ToggleGroup/ToggleGroupItem.vue
Imports useForwardScopeId, computes scopeIdAttrs, and merges them into the Toggle component's v-bind alongside props.
Story fixtures and tests
packages/core/src/RadioGroup/story/_ScopedRadioGroup.vue, packages/core/src/ToggleGroup/story/_ScopedToggleGroup.vue, packages/core/src/shared/useForwardScopeId.test.ts
Adds two SFC story components each rendering a span.marker and a scoped item; two new Vitest cases mount each story, read the parent data-v-* id from the marker element, and assert the inner button receives the same attribute.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • unovue/reka-ui#2720: Introduces the useForwardScopeId hook and applies the same scope-ID forwarding pattern to other form control wrappers, which this PR extends to RadioGroupItem and ToggleGroupItem.

Poem

🐰 Hop hop, the scoped styles were lost,
A data-v-* missing — what a cost!
Now scopeIdAttrs lead the way,
Through Radio and Toggle they relay.
No CSS left behind today! 🎨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main RadioGroupItem scope-id forwarding fix and is concise.
Linked Issues check ✅ Passed The PR fixes RadioGroupItem's missing scoped attribute forwarding and adds regression tests, matching issue #2751.
Out of Scope Changes check ✅ Passed The ToggleGroupItem changes and tests are related to the same scope-id forwarding bug pattern, not unrelated additions.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/radiogroupitem-scope-id-2751

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.

@pkg-pr-new

pkg-pr-new Bot commented Jun 24, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/reka-ui@2755

commit: d4e0d55

@zernonia
zernonia merged commit c215ca6 into v2 Jun 24, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: RadioGroupItem misses data-v-* attribute when used as a root component with <style scoped>

1 participant