diff --git a/Examples/UIExplorer/js/TextInputExample.ios.js b/Examples/UIExplorer/js/TextInputExample.ios.js index aa548171f2..2a8e62f7d6 100644 --- a/Examples/UIExplorer/js/TextInputExample.ios.js +++ b/Examples/UIExplorer/js/TextInputExample.ios.js @@ -832,5 +832,41 @@ exports.examples = [ ); } - } + }, + { + title: 'TextInput maxLength', + render: function() { + return ( + + + + + + + + + + + + + + + ); + } + }, ]; diff --git a/Libraries/Text/RCTTextFieldManager.m b/Libraries/Text/RCTTextFieldManager.m index c1d965509b..3c125caa30 100644 --- a/Libraries/Text/RCTTextFieldManager.m +++ b/Libraries/Text/RCTTextFieldManager.m @@ -41,7 +41,7 @@ RCT_EXPORT_MODULE() if (textField.maxLength == nil || [string isEqualToString:@"\n"]) { // Make sure forms can be submitted via return return YES; } - NSUInteger allowedLength = textField.maxLength.integerValue - textField.text.length + range.length; + NSUInteger allowedLength = textField.maxLength.integerValue - MIN(textField.maxLength.integerValue, textField.text.length) + range.length; if (string.length > allowedLength) { if (string.length > 1) { // Truncate the input string so the result is exactly maxLength