primefaces / primefaces/primereact
Cannot use Checkbox as an uncontrolled component
Nobody has claimed this yet.
- Dominant language
- CSS
- Stars
- 8.3k
- Forks
- 1.2k
- PR merge metrics
- No merged PRs in 30d
Description
Describe the bug
Checkboxes (and all other inputs) should be usable as uncontrolled components, allowing for native HTML Form behavior.
Reproducer
N/A
PrimeReact version
10.6.6
React version
18.x
Language
TypeScript
Build / Runtime
Vite
Browser(s)
Any/All
Steps to reproduce the behavior
- Add a Checkbox component inside a form without specifying a
checkedprop: - Click the checkbox
- Nothing happens
Expected behavior
The checkbox should behave as a native HTML checkbox, and only work as a controlled component when state is explicitly passed via the checked prop.
PS > I see that the current solution to this was to remove the defaultChecked prop from the Checkbox component to make it exclusively controlled. In my humble opinion, this is a step backwards as default HTML behavior should always be preserved in component libraries, at least for standard components that are already available in the browser.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the Checkbox component and inspect how it handles checked and defaultChecked when rendered inside a form. Reproduce the uncontrolled case described in the issue, then verify that clicking the checkbox updates native form behavior while explicitly controlled usage still works.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- react, typescript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100