Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

rn-material-ui-textfield

gabrieldonadel10.6kBSD-3-Clause1.0.9TypeScript support: included

Material UI textfield

react, react-component, react-native, ios, android, material, material-ui, input, textinput, field, textfield, floating, label

readme

rn-material-ui-textfield

npm npm downloads license

Material UI texfield with consistent behaviour on Android, iOS and Web

example

Features

  • Material design guidelines compliance
  • Consistent look and feel on iOS and Android
  • Animated state transitions (normal, focused and errored)
  • Customizable font size, colors and animation duration
  • Disabled state (with dotted underline)
  • Outlined and filled fields
  • Masked input support
  • Multiline text input
  • Character counter
  • Prefix and suffix
  • Accessory views
  • Helper text
  • RTL support
  • Pure javascript implementation

Installation

yarn add rn-material-ui-textfield
npm install rn-material-ui-textfield

Usage

import React, { Component } from 'react';
import {
  TextField,
  FilledTextField,
  OutlinedTextField,
} from 'rn-material-ui-textfield';

class Example extends Component {
  fieldRef = React.createRef();

  onSubmit = () => {
    let { current: field } = this.fieldRef;

    console.log(field.value());
  };

  formatText = (text) => {
    return text.replace(/[^+\d]/g, '');
  };

  render() {
    return (
      <OutlinedTextField
        label="Phone number"
        keyboardType="phone-pad"
        formatText={this.formatText}
        onSubmitEditing={this.onSubmit}
        ref={this.fieldRef}
      />
    );
  }
}

Properties

name description type default
textColor Text input color String rgba(0, 0, 0, .87)
fontSize Text input font size Number 16
labelFontSize Text field label font size Number 12
lineWidth Text field underline width Number 0.5
activeLineWidth Text field active underline width Number 2
disabledLineWidth Text field disabled underline width Number 1
tintColor Text field accent color String rgb(0, 145, 234)
baseColor Text field base color String rgba(0, 0, 0, .38)
label Text field label text String -
title Text field helper text String -
prefix Text field prefix text String -
suffix Text field suffix text String -
error Text field error text String -
errorColor Text field color for errored state String rgb(213, 0, 0)
lineType Text field line type String solid
disabledLineType Text field line type in disabled state String dotted
animationDuration Text field animation duration in ms Number 225
characterRestriction Text field soft limit for character counter Number -
disabled Text field availability Boolean false
editable Text field text can be edited Boolean true
multiline Text filed multiline input Boolean false
contentInset Layout configuration object Object {...}
labelOffset Label position adjustment Object {...}
inputContainerStyle Style for input container view Object -
containerStyle Style for container view Object -
labelTextStyle Style for label inner Text component Object -
titleTextStyle Style for title inner Text component Object -
affixTextStyle Style for affix inner Text component Object -
formatText Input mask callback Function -
renderLeftAccessory Render left input accessory view Function -
renderRightAccessory Render right input accessory view Function -
onChangeText Change text callback Function -
onFocus Focus callback Function -
onBlur Blur callback Function -
inputRef TextInput ref RefObject -

Other TextInput properties will also work.

Content Inset

name description Normal Filled Outlined
top Inset on the top side 16 8 0
left Inset on the left side 0 12 12
right Inset on the right side 0 12 12
label Space between label and TextInput 4 4 4
input Space between line and TextInput 8 8 16

Label Offset

name description Normal Filled Outlined
x0 Horizontal offset for inactive state 0 0 0
y0 Vertical offset for inactive state 0 -10 0
x1 Horizontal offset for active state 0 0 0
y1 Vertical offset for active state 0 -2 -10

Methods

name description returns
focus() Acquire focus -
blur() Release focus -
clear() Clear text field -
value() Get current value String
isFocused() Get current focus state Boolean
isErrored() Get current error state Boolean
isRestricted() Get current restriction state Boolean
isDefaultVisible() Get default value visibility Boolean
isPlaceholderVisible() Get placeholder visibility Boolean
setValue() Set current value -

Example

git clone https://github.com/gabrieldonadel/rn-material-ui-textfield
cd rn-material-ui-textfield/example
yarn install
yarn run ios # or yarn run android

Contributing

  1. Fork it (https://github.com/yourname/yourproject/fork)
  2. Create your feature branch (git checkout -b feature/fooBar)
  3. Commit your changes (git commit -am 'Add some fooBar')
  4. Push to the branch (git push origin feature/fooBar)
  5. Create a new Pull Request

changelog

1.0.9 (2022-11-03)

Features

  • Add expo example app with web support (2bb2cf2)

Bug Fixes

  • Fix labels styles for web (97a03cb)

1.0.8 (2022-10-30)

Bug Fixes

  • Fix Module parse failed error on Expo web (6f0a1b0)

1.0.7 (2022-08-14)

Bug Fixes

  • Proptypes error on react-native 0.69 (8b88da6)

Features

  • Add typescript support to the project (6b08613)

1.0.6 (2022-03-04)

Bug Fixes

  • Fix line-height glitch on TextField's label(681265f)

1.0.5 (2021-07-18)

Features

  • Allow pressing on accessories if input not disabled (0cc7053)

1.0.4 (2021-04-22)

Features

  • Add inputRef prop to TextField component

1.0.3 (2021-04-03)

Bug Fixes

  • TextField not updating if value prop undefined (906e002)
  • TextField value prop not updating internal text state (b28dead)

1.0.3 (2021-04-03)

Bug Fixes

  • TextField not updating if value prop undefined (906e002)
  • TextField value prop not updating internal text state (b28dead)

1.0.3 (2021-04-03)

Bug Fixes

  • TextField not updating if value prop undefined (906e002)
  • TextField value prop not updating internal text state (b28dead)

1.0.2 (2020-12-09)

Bug Fixes

  • TextField value prop not updating internal text state (b28dead)

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.

Unreleased

Added

  • bottom key for contentInset prop

0.16.0 - 2019-10-24

Added

  • left and right keys for contentInset prop
  • labelOffset prop
  • FilledTextField component
  • OutlinedTextField component

Changed

  • Accessory view positioning

0.15.0 - 2019-10-17

Added

  • contentInset prop

Changed

  • Refactored helper layout for consistent line height
  • Improved RTL support for helper
  • Improved label animation
  • label prop was made optional

Removed

  • titleFontSize prop
  • labelHeight prop
  • labelPadding prop
  • inputContainerPadding prop

0.14.1 - 2019-10-15

Fixed

  • Collapsing layout outside of ScrollView
  • Visible sideline on some Android versions

0.14.0 - 2019-10-14

Added

  • lineType prop
  • formatText prop for masked input support
  • isPlaceholderVisible() method

Changed

  • Refactored componentDidUpdate and improved animation

Fixed

  • Label and Helper text color in disabled state
  • Multiline title and error messages
  • Multiline layout on iOS

0.13.0 - 2019-10-11

Added

  • renderLeftAccessory prop
  • renderRightAccessory prop
  • .isDefaultVisible() method
  • .isErrored() method
  • .setValue() method

Changed

  • defaultValue prop becomes current value on focus
  • value prop provides only initial value
  • TextField refactored to improve internal layout
  • TextField refactored to be fully uncontrolled component
  • Line refactored to render all types of underlines
  • Focus and label animations refactored for better performance

Removed

  • renderAccessory prop

Fixed

  • Crash on null value for value prop
  • Deprecation warnings for React component lifecycle methods
  • Text position for Label and Affix on Android

0.12.0 - 2018-01-18

Added

  • RTL support

Fixed

  • Multiline input on Web platform

0.11.0 - 2017-12-05

Added

  • lineWidth prop
  • activeLineWidth prop
  • disabledLineWidth prop

Fixed

  • Normalized clearTextOnFocus behaviour
  • Disabled underline on Android

0.10.0 - 2017-09-15

Added

  • inputContainerPadding prop
  • inputContainerStyle prop
  • disabledLineType prop