Skip to content

Commit

Permalink
fix: use entire input box as touch area for focus
Browse files Browse the repository at this point in the history
  • Loading branch information
leinelissen committed Nov 27, 2022
1 parent 845b379 commit 87f992d
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/components/Input.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { Platform, TextInputProps } from 'react-native';
import React, { useCallback, useRef } from 'react';
import { Platform, TextInput, TextInputProps } from 'react-native';
import styled, { css } from 'styled-components/native';
import useDefaultStyles from './Colors';
import { Gap } from './Utility';
Expand All @@ -8,7 +8,7 @@ export interface InputProps extends TextInputProps {
icon?: React.ReactNode
}

const Container = styled.View`
const Container = styled.Pressable`
margin: 6px 0;
border-radius: 8px;
display: flex;
Expand All @@ -28,16 +28,19 @@ const InputWrapper = styled.TextInput`

function Input({ icon = null, style, ...rest }: InputProps) {
const defaultStyles = useDefaultStyles();
const inputRef = useRef<TextInput | null>(null);

const handlePress = useCallback(() => inputRef.current?.focus(), []);

return (
<Container style={[defaultStyles.input, style]}>
<Container style={[defaultStyles.input, style]} onPress={handlePress}>
{icon && (
<>
{icon}
<Gap size={8} />
</>
)}
<InputWrapper {...rest} />
<InputWrapper {...rest} ref={inputRef} />
</Container>
);
}
Expand Down

0 comments on commit 87f992d

Please sign in to comment.