ionic-team / ionic-team/ionic-framework

feat: Ionic form controls should support `defaultValue` and `defaultChecked` properties

Open
#28,193 6 comments 1 reaction 0 assignees View on GitHub
package: core type: feature request
Dominant language
TypeScript
Stars
52.7k
Forks
13.3k
Avg merge
1d 15h
Merged PRs (30d)
51

Description

### Prerequisites

- [X] I have read the [Contributing Guidelines](https://github.com/ionic-team/ionic-framework/blob/main/.github/CONTRIBUTING.md#creating-an-issue).
- [X] I agree to follow the [Code of Conduct](https://ionicframework.com/code-of-conduct).
- [X] I have searched for [existing issues](https://github.com/ionic-team/ionic-framework/issues) that already report this problem, without success.

### Ionic Framework Version

v7.x

### Current Behavior

When using uncontrolled form inputs, it is not possible to set default values. The `defaultValue` prop is ostensibly available according to the types, but setting it does not result in the `value` prop initially getting set during the first render. This differs from [React's expected behavior for providing an initial value](https://react.dev/reference/react-dom/components/input#providing-an-initial-value-for-an-input).

### Expected Behavior

`defaultValue` is initially set to the input's value on first render

### Steps to Reproduce

1. Add `defaultValue` as a prop to an input
2. Render the component
3. Value is not set

### Code Reproduction URL

https://stackblitz.com/edit/vxete3

### Ionic Info

**Ionic**:
Ionic CLI : 5.4.16

**Utility**:
cordova-res : not installed
native-run : not installed

**System**:
NodeJS : v16.20.0
npm : 9.4.2
OS : Linux 5.0

(this is from Stackblitz)

### Additional Information

Technically `defaultValue` is not listed as a property in the Ionic docs (https://ionicframework.com/docs/api/input#properties), but it is an accepted value according to the component's types (`React.ForwardRefExoticComponent, "style"> & StyleReactProps & React.RefAttributes>`).

If there's another way to use uncontrolled inputs in @ionic/react, please let me know!

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.