Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/components/TextInput/TextInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type {
TextStyle,
ViewStyle,
} from 'react-native'
import {TextInput as RNTextInput, View} from 'react-native'
import {TextInput as RNTextInput, TouchableOpacity, View} from 'react-native'
import styled from 'styled-components/native'
import TextInputOutlined from './TextInputOutlined'
import {CustomIcon, CustomIconProps, Error} from './components'
Expand Down Expand Up @@ -56,6 +56,9 @@ export interface TextInputProps extends RNTextInputProperties {

/** Callback that is called when the text input is blurred */
onBlur?: () => void

/** If true, the text input will be focused when the user touches the input */
focusOnTouch?: boolean
}

interface CompoundedComponent
Expand Down Expand Up @@ -93,6 +96,7 @@ export const TextInput = forwardRef<TextInputRef, TextInputProps>(
onFocus,
onSubmitEditing,
onBlur,
focusOnTouch,
...rest
},
ref,
Expand All @@ -110,8 +114,12 @@ export const TextInput = forwardRef<TextInputRef, TextInputProps>(
inputRef.current?.focus()
}, [])

const componentFocusOnTouch = focusOnTouch ?? TextInputTheme.focusOnTouch ?? false

const ContainerComponent = componentFocusOnTouch ? TouchableOpacity : View

return (
<View style={containerStyle ?? TextInputTheme.containerStyle}>
<ContainerComponent style={containerStyle ?? TextInputTheme.containerStyle} onPress={componentFocusOnTouch ? handleFocus : undefined} activeOpacity={1}>
{!!label && (
<Title testID="test-title" style={labelStyle ?? TextInputTheme.labelStyle} {...labelProps}>
{label}
Expand Down Expand Up @@ -140,7 +148,7 @@ export const TextInput = forwardRef<TextInputRef, TextInputProps>(
{!!rightComponent && rightComponent}
</TouchableContainer>
{!!errorText && <Error errorProps={errorProps} errorText={errorText} />}
</View>
</ContainerComponent>
)
},
) as CompoundedComponent
Expand Down
Loading