react-native-paper icon indicating copy to clipboard operation
react-native-paper copied to clipboard

How to use custom icons in TextInput.Icon component

Open sureshavv opened this issue 6 years ago • 16 comments

Is it possible to use custom icons in TextInput.Icon component and which icon library supports for this component.

<TextInput style={commonstyles.primaryInput} mode='outlined' label="Label Name" placeholder="Enter placeholder" left={<TextInput.Icon name="info" color={"#ff0000"} onPress={() => {}} />} />

sureshavv avatar Sep 13 '20 16:09 sureshavv

Couldn't find version numbers for the following packages in the issue:

  • react-native
  • react-native-paper
  • react-native-vector-icons

Can you update the issue to include version numbers for those packages? The version numbers must match the format 1.2.3.

github-actions[bot] avatar Sep 13 '20 16:09 github-actions[bot]

You can pass your own component in the name prop, like saw in #2255.

<TextInput style={commonstyles.primaryInput}
  mode='outlined'
  label="Label Name"
  placeholder="Enter placeholder"
  left={
    <TextInput.Icon
      name={<Icon name="info" color="#ff0000" />} // where <Icon /> is any component from vector-icons or anything else
      onPress={() => {}}
    />
  }
/>

It seem like that it's not too clear in the documentation, but we always can open a PR to contribute.

italomlp avatar Oct 29 '20 18:10 italomlp

This isn't an option currently since a release hasn't been cut yet

hbiede avatar Oct 29 '20 20:10 hbiede

@hbiede For me, it already works, even the TS giving me an error message for name prop. I'm using version 4.2.0

Edit: Seems like 4.3.0 just launched minutes ago \o/.

italomlp avatar Oct 30 '20 14:10 italomlp

@hbiede pass the name as a function

<TextInput
   right={<TextInput.Icon name={() => <Icon name={'camera'} size={20} />} />}
   style={styles.input}
   label={'Label'}
/>

ikaccc avatar Nov 09 '20 03:11 ikaccc

@ikaccc yep, it’s working now. It hadn’t been at the time as the change hadn’t been published. Thanks, though.

hbiede avatar Nov 09 '20 03:11 hbiede

this didnt work for me and IMO very confusing design, this doesnt follow any standards or share any similarities to other components in the library

tylerthedeveloper avatar Nov 22 '20 01:11 tylerthedeveloper

The fact that it requires a callback instead of a component is quite weird

hbiede avatar Nov 22 '20 06:11 hbiede

Also unusual that a name attribute is expecting a function 🤔 ...

amwebexpert avatar May 14 '21 10:05 amwebexpert

react-native-paper v.4.9.2 does not support FontAwesome5 with TextInpnut.Icon

ahmetgsu avatar Jul 10 '21 13:07 ahmetgsu

Here is my take on this: <TextInput placeholder="Text goes here" theme={{ colors: { text: Colors.primaryText } }} activeOutlineColor={Colors.primaryCTA} autoCorrect={false} style={styles.input} right={ <TextInput.Icon name={() => ( <TouchableOpacity style={styles.searchButton} onPress={onSearch}> <ExploreIcon focused focusedColor={Colors.inputBackground} /> </TouchableOpacity> )} /> } />

rupalpatel0008 avatar Apr 21 '22 04:04 rupalpatel0008

@hbiede passe o nome como uma função

<TextInput
   right={<TextInput.Icon name={() => <Icon name={'camera'} size={20} />} />}
   style={styles.input}
   label={'Label'}
/>

this it works for me. Documentation sometimes does't contribuites much.

Gabriel-Jesusvix avatar Jul 25 '22 19:07 Gabriel-Jesusvix

react-native-paper: v5.2.0 - Using Icon prop we can use custom SVG icon

          <TextInput
            placeholder="Reply"
            right={<TextInput.Icon icon={() => <SendIcon/>} />}   
          />

TextInputIconProps :

export type Props = $Omit<
  React.ComponentProps<typeof IconButton>,
  'icon' | 'theme' | 'color'
> 

yathu avatar May 10 '23 23:05 yathu

<TextInputCustom mode='outlined' label={<LableInput error={errors.confirmPassword} lable={I18n.t('register.confirm_password')} required={true} />} placeholder={I18n.t('register.confirm_password_placeholder')} value={confirmPassword} onChangeText={setConfirmPassword} error={errors.confirmPassword} errorMess={errors.confirmPassword} secureTextEntry={secureTextEntryConfirmPassword} autoComplete='password-new' textContentType="oneTimeCode" right={<TextInput.Icon forceTextInputFocus={false} style={styles.inputIcon} color={selectedTheme.selectedTheme.textColorNeutral} icon={!secureTextEntryConfirmPassword ? "eye-off-outline" : "eye-outline"} onPress={onShowConfirmPassword} />} onSubmitEditing={onRegister} /> Ipados 16.4.1 crash when press TextInput.Icon. not the simulator. Thanks Any help T.T

nguyenduy2392 avatar Jul 10 '23 09:07 nguyenduy2392

that work for me left={<TextInput.Icon name={() => (<Text>{currency}</Text>)} /> }

Goowwy avatar Nov 01 '23 11:11 Goowwy

Renamed from 'name' to 'icon` in v5.x

<TextInput
          mode="outlined"
          placeholder="See Recent Investigations"
          contentStyle={styles.inputContainer}
          style={styles.input}
          right={
            <TextInput.Icon
              icon={() => <AntDesign name={"down"} size={20} />}
              onPress={() => {}}
            />
          }
        />

UmerGillani36 avatar Jul 08 '24 07:07 UmerGillani36