Skip to content

Commit def92e2

Browse files
authored
feat: remove state management for Typeahead to allow RHF to control it (#564)
* feat: remove state management for Typeahead to allow RHF to control it * Keep a default value
1 parent 2a2b18b commit def92e2

3 files changed

Lines changed: 3 additions & 7 deletions

File tree

src/components/Molecules/SchoolLookup/__snapshots__/SchoolLookup.test.js.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,13 @@ exports[`renders correctly 1`] = `
9292
aria-describedby="school-lookup"
9393
autoComplete="off"
9494
className="c5"
95+
defaultValue=""
9596
id="school-lookup"
9697
name="school-lookup"
9798
onChange={[Function]}
9899
placeholder="Type to start search"
99100
required={false}
100101
type="text"
101-
value=""
102102
/>
103103
</div>
104104

src/components/Molecules/Typeahead/Typeahead.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ const Typeahead = React.forwardRef(
2424
},
2525
ref
2626
) => {
27-
const [value, setValue] = useState('');
2827
const [options, setOptions] = useState([]);
2928
const [errorMsg, setErrorMsg] = useState('');
3029

@@ -62,13 +61,11 @@ const Typeahead = React.forwardRef(
6261

6362
return (
6463
<TextInputWithDropdown
65-
value={value}
64+
defaultValue=""
6665
options={optionParser ? options.map(optionParser) : options}
6766
errorMsg={errorMsg}
6867
onChange={e => {
6968
const newValue = e.currentTarget.value;
70-
setValue(newValue);
71-
7269
debouncedHandleChange(newValue);
7370
}}
7471
onSelect={(parsedOption, optionIndex) => {
@@ -81,7 +78,6 @@ const Typeahead = React.forwardRef(
8178
// reset
8279
setOptions([]);
8380
setErrorMsg('');
84-
setValue('');
8581
}}
8682
id={id}
8783
label={label}

src/components/Molecules/Typeahead/__snapshots__/Typeahead.test.js.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,13 @@ exports[`renders correctly 1`] = `
9292
aria-describedby="typeahead-test"
9393
autoComplete="off"
9494
className="c5"
95+
defaultValue=""
9596
id="typeahead-test"
9697
name="q"
9798
onChange={[Function]}
9899
placeholder="Type to start searching..."
99100
required={false}
100101
type="text"
101-
value=""
102102
/>
103103
</div>
104104

0 commit comments

Comments
 (0)