primefaces / primefaces/primereact

Cannot use Checkbox as an uncontrolled component

Open
#6,753 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Status: Needs Triage
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
  1. Add a Checkbox component inside a form without specifying a checked prop:
  2. Click the checkbox
  3. 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.