Skip to content

Commit

Permalink
fix(search): added forward ref for search input #25
Browse files Browse the repository at this point in the history
  • Loading branch information
petrovakd committed Nov 28, 2023
1 parent 811ce00 commit 8da674e
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions packages/core/src/inputs/components/Search/Search.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import React, {FC, useCallback} from 'react';
import React, {forwardRef, useCallback} from 'react';

import useStyles from '../../../styles/theme/hooks/useStyles';
import View from '../../../basic/components/View/View';
import SimpleIcon from '../../../styles/icons/font/SimpleIcon';
import TextInput from '../../../basic/components/TextInput/TextInput';
import {ITextInput} from '../../../basic';
import Pressable from '../../../basic/components/Pressable/Pressable';
import rem from '../../../styles/spaces/rem';
import {LABELS} from '../../../other';
Expand All @@ -12,19 +13,20 @@ import {strings} from './constants';
import stylesCreate from './stylesCreate';
import {ISearchProps} from './types';

const Search: FC<ISearchProps> = ({
placeholder = strings.search,
value,
onChangeText = text => {
console.log(
`Search says: "Add onChangeText (╯°□°)╯︵ ┻━┻". Current value=${text}`,
);
},
containerStyle,
leftIcon,
textInputContainerStyle,
...otherProps
}) => {
const Search = forwardRef<ITextInput, ISearchProps>((props, ref) => {
const {
placeholder = strings.search,
value,
onChangeText = text => {
console.log(
`Search says: "Add onChangeText (╯°□°)╯︵ ┻━┻". Current value=${text}`,
);
},
containerStyle,
leftIcon,
textInputContainerStyle,
...otherProps
} = props;
const [styles, theme] = useStyles(stylesCreate);

const onCancel = useCallback(() => {
Expand All @@ -35,6 +37,7 @@ const Search: FC<ISearchProps> = ({
<View style={[styles.container, containerStyle]}>
{leftIcon ? leftIcon : <SimpleIcon name={'icon-search'} />}
<TextInput
ref={ref}
accessibilityLabel={LABELS.search}
style={[styles.textInput, textInputContainerStyle]}
placeholder={placeholder}
Expand All @@ -54,6 +57,6 @@ const Search: FC<ISearchProps> = ({
) : null}
</View>
);
};
});

export default Search;

0 comments on commit 8da674e

Please sign in to comment.