diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index bbea6f5..823b982 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -16,11 +16,11 @@ jobs:
pull-requests: write
id-token: write
steps:
- - uses: actions/checkout@v3
+ - uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node
- uses: actions/setup-node@v3
+ uses: actions/setup-node@v4
with:
node-version-file: '.node-version'
- name: Install
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index 519c867..060802f 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -10,9 +10,9 @@ jobs:
test:
runs-on: ubuntu-latest
steps:
- - uses: actions/checkout@v3
+ - uses: actions/checkout@v4
- name: Setup Node
- uses: actions/setup-node@v3
+ uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
- name: Install dependencies
diff --git a/__tests__/AutocompleteInput.spec.tsx b/__tests__/AutocompleteInput.spec.tsx
index bc0dd72..5a2c535 100644
--- a/__tests__/AutocompleteInput.spec.tsx
+++ b/__tests__/AutocompleteInput.spec.tsx
@@ -94,4 +94,30 @@ describe('', () => {
render();
expect(ref!.current?.constructor.name).toBe('TextInput');
});
+
+ it('should only pass text input props to the TextInput', () => {
+ const MockTextInput = jest.fn(() => null) as unknown as jest.Mock;
+
+ render(
+ <>>}
+ renderTextInput={MockTextInput}
+ />,
+ );
+
+ expect(MockTextInput).toHaveBeenCalledWith({
+ placeholder: 'Enter search',
+ ref: null,
+ style: [
+ {
+ backgroundColor: 'white',
+ height: 40,
+ paddingLeft: 3,
+ },
+ undefined,
+ ],
+ });
+ });
});
diff --git a/index.tsx b/index.tsx
index a6adaf4..c563dac 100644
--- a/index.tsx
+++ b/index.tsx
@@ -39,9 +39,23 @@ export const AutocompleteInput = React.forwardRef(function AutocompleteInputComp
ref: React.ForwardedRef[,
): React.ReactElement {
const defaultRenderItems: ListRenderItem]- = ({ item }) => {String(item)};
- function renderResultList(): React.ReactElement {
- const { data, renderResultList: renderFunction = DefaultResultList, flatListProps } = props;
+ const {
+ data,
+ containerStyle,
+ hideResults,
+ inputContainerStyle,
+ listContainerStyle,
+ onShowResults,
+ onStartShouldSetResponderCapture = () => false,
+ renderResultList: renderResultListFunction = DefaultResultList,
+ renderTextInput: renderTextInputFunction = DefaultTextInput,
+ flatListProps,
+ style,
+ ...textInputProps
+ } = props;
+
+ function renderResultList(): React.ReactElement {
const listProps: FlatListProps
- = {
data,
renderItem: defaultRenderItems,
@@ -50,30 +64,19 @@ export const AutocompleteInput = React.forwardRef(function AutocompleteInputComp
style: [styles.list, flatListProps?.style],
};
- return renderFunction(listProps);
+ return renderResultListFunction(listProps);
}
function renderTextInput() {
- const { renderTextInput: renderFunction = DefaultTextInput, style } = props;
- const textProps = {
- ...props,
+ const renderProps = {
+ ...textInputProps,
style: [styles.input, style],
ref,
};
- return renderFunction(textProps);
+ return renderTextInputFunction(renderProps);
}
- const {
- data,
- containerStyle,
- hideResults,
- inputContainerStyle,
- listContainerStyle,
- onShowResults,
- onStartShouldSetResponderCapture = () => false,
- } = props;
-
const showResults = data.length > 0;
onShowResults?.(showResults);