Skip to content

Commit 6565c66

Browse files
committed
feat(Components): ✨ Wrap the TextInputField component with the Autocomplete component and add the items property for adding suggestions to the text field.
1 parent e2a692d commit 6565c66

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed
Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,33 @@
11
import React from 'react';
22

3-
import { TextInputField } from 'evergreen-ui';
3+
import { Autocomplete, TextInputField } from 'evergreen-ui';
44

55
import useFieldApi from '@data-driven-forms/react-form-renderer/use-field-api';
66
import { UseFieldApiProps } from '@data-driven-forms/react-form-renderer';
77

88
export interface TextFieldProps extends UseFieldApiProps<string> {
9-
name: string;
10-
isRequired?: boolean;
11-
};
9+
name: string;
10+
items: string[];
11+
isRequired?: boolean;
12+
}
1213

1314
const TextField: React.FC<TextFieldProps> = (props) => {
14-
const { input, meta, isRequired, ...rest } = useFieldApi(props);
15+
const { input, meta, isRequired, items, ...rest } = useFieldApi(props);
1516

16-
return <TextInputField
17-
{...input}
18-
required={isRequired}
19-
isInvalid={Boolean(meta.error)}
20-
validationMessage={meta.error}
21-
{...rest}
22-
/>;
17+
return (
18+
<Autocomplete {...input} items={items} {...rest}>
19+
{({ getInputProps, getRef, inputValue, openMenu }) => (
20+
<TextInputField
21+
ref={getRef}
22+
required={isRequired}
23+
isInvalid={Boolean(meta.error)}
24+
validationMessage={meta.error}
25+
{...getInputProps({ onFocus: () => openMenu() })}
26+
value={inputValue}
27+
/>
28+
)}
29+
</Autocomplete>
30+
);
2331
};
2432

2533
export default TextField;

0 commit comments

Comments
 (0)