Skip to content

Commit 352d174

Browse files
Rating | MUI needs null to avoid warning (#149)
Rating | MUI needs null to avoid warning
1 parent 0035cc2 commit 352d174

2 files changed

Lines changed: 13 additions & 10 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Fixed
11+
12+
- `RatingInput` controlled/uncontrolled state warning by ensuring value prop is always defined.
13+
1014
## [3.11.1] - 2025-09-30
1115

1216
### Fixed

src/lib/RatingInput.tsx

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ const RatingInput = <T extends FieldValues>(props: RatingInputProps<T>) => {
2121
sx,
2222
disabled,
2323
readOnly,
24-
onBlur,
25-
onChange,
2624
...rest
2725
} = props;
2826
const { name, id } = useSafeNameId(props.name, props.id);
@@ -32,7 +30,7 @@ const RatingInput = <T extends FieldValues>(props: RatingInputProps<T>) => {
3230
<Controller
3331
control={control}
3432
name={props.name}
35-
render={({ field }) => (
33+
render={({ field: { value, onBlur, onChange, ...fieldRest } }) => (
3634
<FormGroupLayout
3735
name={name}
3836
id={id}
@@ -46,8 +44,9 @@ const RatingInput = <T extends FieldValues>(props: RatingInputProps<T>) => {
4644
inputGroupStyle={inputGroupStyle}
4745
>
4846
<Rating
49-
{...field}
5047
{...rest}
48+
{...fieldRest}
49+
value={value ?? null}
5150
sx={{
5251
...sx,
5352
label: {
@@ -58,16 +57,16 @@ const RatingInput = <T extends FieldValues>(props: RatingInputProps<T>) => {
5857
disabled={disabled || formDisabled}
5958
readOnly={readOnly || formDisabled}
6059
onBlur={(e) => {
61-
if (onBlur) {
62-
onBlur(e);
60+
if (props.onBlur) {
61+
props.onBlur(e);
6362
}
64-
field.onBlur();
63+
onBlur();
6564
}}
6665
onChange={(e, value) => {
67-
if (onChange) {
68-
onChange(e, value);
66+
if (props.onChange) {
67+
props.onChange(e, value);
6968
}
70-
field.onChange(value);
69+
onChange(value);
7170
}}
7271
/>
7372
</FormGroupLayout>

0 commit comments

Comments
 (0)