Skip to content

Commit 81ecc5e

Browse files
sookmaxsnowystingeryihuiliao
authored
Fix Combobox hidden input default value causing React warnings (name prop) (#6336)
* fix combobox hidden input default value causing React warnings * add name prop to ComboBox.test.js --------- Co-authored-by: Robert Snow <[email protected]> Co-authored-by: Yihui Liao <[email protected]>
1 parent 4a39740 commit 81ecc5e

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

packages/react-aria-components/src/ComboBox.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ function ComboBoxInner<T extends object>({props, collection, comboBoxRef: ref}:
223223
data-disabled={props.isDisabled || undefined}
224224
data-invalid={validation.isInvalid || undefined}
225225
data-required={props.isRequired || undefined} />
226-
{name && formValue === 'key' && <input type="hidden" name={name} value={state.selectedKey} />}
226+
{name && formValue === 'key' && <input type="hidden" name={name} value={state.selectedKey ?? ''} />}
227227
</Provider>
228228
);
229229
}

packages/react-aria-components/stories/ComboBox.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export default {
2121
};
2222

2323
export const ComboBoxExample = () => (
24-
<ComboBox data-testid="combo-box-example">
24+
<ComboBox name="combo-box-example" data-testid="combo-box-example">
2525
<Label style={{display: 'block'}}>Test</Label>
2626
<div style={{display: 'flex'}}>
2727
<Input />

packages/react-aria-components/test/ComboBox.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import React from 'react';
1717
import userEvent from '@testing-library/user-event';
1818

1919
let TestComboBox = (props) => (
20-
<ComboBox defaultInputValue="C" data-foo="bar" {...props}>
20+
<ComboBox name="test-combobox" defaultInputValue="C" data-foo="bar" {...props}>
2121
<Label>Favorite Animal</Label>
2222
<Input />
2323
<Button />

0 commit comments

Comments
 (0)