fix: 3.7_Radio_isuue#1413
Open
deepakoram-juspay wants to merge 1 commit into
Open
Conversation
commit: |
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes the Radio component to avoid passing both checked and defaultChecked to the underlying <input type="radio">, eliminating React’s controlled/uncontrolled warning and aligning styling with the native :checked state.
Changes:
- Updated
Radioto conditionally pass eitherchecked(controlled) ordefaultChecked(uncontrolled), and addedreadOnlyfor controlled-without-onChangecases to avoid React warnings. - Refactored
StyledRadioInputto use CSS:checkedselectors instead of a custom$isCheckedprop. - Added an accessibility test to ensure no console error occurs when both props are provided to
Radio(withcheckedtaking precedence).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| packages/blend/lib/components/Radio/StyledRadio.tsx | Removes $isChecked and switches styling to native :checked state. |
| packages/blend/lib/components/Radio/Radio.tsx | Ensures input is either controlled or uncontrolled by conditionally spreading checked vs defaultChecked. |
| packages/blend/tests/components/Radio/Radio.accessibility.test.tsx | Adds coverage to guard against the React warning about mixing checked and defaultChecked. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+273
to
+291
| render( | ||
| <Radio | ||
| value="controlled" | ||
| checked={false} | ||
| defaultChecked | ||
| onChange={() => {}} | ||
| > | ||
| Controlled radio | ||
| </Radio> | ||
| ) | ||
|
|
||
| const radio = screen.getByRole('radio', { | ||
| name: 'Controlled radio', | ||
| }) | ||
|
|
||
| expect(radio).not.toBeChecked() | ||
| expect(consoleError).not.toHaveBeenCalled() | ||
|
|
||
| consoleError.mockRestore() |
Comment on lines
7
to
12
| export const StyledRadioInput = styled.input<{ | ||
| size: RadioSize | ||
| $isDisabled: boolean | ||
| $isChecked: boolean | ||
| $error?: boolean | ||
| $tokens: RadioTokensType | ||
| }>` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
styled.input contains an input of type radio with both checked and defaultChecked props. Input elements must be either controlled or uncontrolled
Issue Ticket
Closes #1443