callstack / react-native-paper

Material Design for React Native (Android & iOS)
https://reactnativepaper.com
MIT License
12.7k stars 2.07k forks source link

Text Input label position #4448

Open halilibrahimcelik opened 1 month ago

halilibrahimcelik commented 1 month ago

Is it possible to label change position of text input label?

I am trying to set spacing between my input fields. When I use the label, the default height increases automatically, and the gap between fields is also affected by it. As you can see, the email label increases the label height, which creates spacing inconsistencies between components. Is there a way to exclude the extra height of the label and also add a label prop to the input field? WhatsApp Image 2024-07-09 at 13 13 06

BEGDAR8ZOUHAIR commented 1 month ago

Control the Label Position and Style: You can use the label prop directly on the TextInput component and style the label to ensure it doesn't add unwanted spacing. You can also control the positioning and layout by wrapping the TextInput in a View and styling that View.

Adjust Spacing Between Input Fields: Use margin and padding to control the space between your input fields. This can be done by applying styles to the TextInput components or their containers.

BEGDAR8ZOUHAIR commented 1 month ago
import { View, StyleSheet } from 'react-native';
import { TextInput } from 'react-native-paper';

const MyForm = () => {
  return (
    <View style={styles.container}>
      <View style={styles.inputContainer}>
        <TextInput
          label="Name"
          mode="outlined"
          style={styles.input}
        />
      </View>
      <View style={styles.inputContainer}>
        <TextInput
          label="Email"
          mode="outlined"
          style={styles.input}
        />
      </View>
      <View style={styles.inputContainer}>
        <TextInput
          label="Password"
          mode="outlined"
          style={styles.input}
          secureTextEntry
        />
      </View>
    </View>
  );
};

const styles = StyleSheet.create({
  container: {
    flex: 1,
    padding: 16,
  },
  inputContainer: {
    marginBottom: 16,  // Adjust this value to control spacing between fields
  },
  input: {
    backgroundColor: 'white',  // Adjust as needed
  },
});

export default MyForm;
halilibrahimcelik commented 1 month ago

Control the Label Position and Style: You can use the label prop directly on the TextInput component and style the label to ensure it doesn't add unwanted spacing. You can also control the positioning and layout by wrapping the TextInput in a View and styling that View.

Adjust Spacing Between Input Fields: Use margin and padding to control the space between your input fields. This can be done by applying styles to the TextInput components or their containers.

Actually I tried to customize label props, even if I gave padding and margin zero to label component, (When I tried to wrap label text with a parent, layout broken) nothing changed, unwanting spacing is still there this is my field code btw. ps:I tried to use style instead of nativewind,still no changes.


          <TextInput
            returnKeyLabel='done'
            label={
              <>
                <Text className='p-0  m-0 '>Email</Text>
              </>
            }
            autoComplete='email'
            inputMode='email'
            placeholderTextColor={theme.colors.primaryContainer}
            theme={{ roundness: 8 }}
            mode='outlined'
            returnKeyType={'done'}
            style={{
              borderRadius: 10,
              margin: 0,
              padding: 0,
              borderColor: 'white',
              position: 'relative',
              borderWidth: 1,
            }}
            value={userData.email}
            onChangeText={(text) =>
              setUserData((prev) => ({ ...prev, email: text }))
            }
          />
          {errorState.email.isError && (
            <CustomErrorMessage error={errorState.email.errorMessage} />
          )}
        </View>
BEGDAR8ZOUHAIR commented 1 month ago

Please, I recommend trying to use StyleSheet for styling; it works well.

BEGDAR8ZOUHAIR commented 1 month ago

if have stille the error contact me i help you https://www.linkedin.com/in/zouhair-begdar/