From b10711bddd1fdf6e01e82c0d49840dce9c2e04d2 Mon Sep 17 00:00:00 2001 From: Nicolas Gallagher Date: Wed, 18 Dec 2019 22:31:45 +0000 Subject: [PATCH] [fix] TextInput autoComplete behavior Fix 'autoComplete' behavior now that Chrome has fixed broken behavior for 'off'. Add fallback support for React Native's 'autoCompleteType' prop. Close #1404 --- .../src/exports/TextInput/__tests__/index-test.js | 7 ++++++- packages/react-native-web/src/exports/TextInput/index.js | 7 +++---- packages/react-native-web/src/exports/TextInput/types.js | 1 + 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/packages/react-native-web/src/exports/TextInput/__tests__/index-test.js b/packages/react-native-web/src/exports/TextInput/__tests__/index-test.js index 44b5ebac..d98a9d0f 100644 --- a/packages/react-native-web/src/exports/TextInput/__tests__/index-test.js +++ b/packages/react-native-web/src/exports/TextInput/__tests__/index-test.js @@ -25,7 +25,12 @@ describe('components/TextInput', () => { test('value "off"', () => { const input = findNativeInput(shallow()); - expect(input.prop('autoComplete')).toEqual('noop'); + expect(input.prop('autoComplete')).toEqual('off'); + }); + + test('autoCompleteType fallback', () => { + const input = findNativeInput(shallow()); + expect(input.prop('autoComplete')).toEqual('off'); }); }); diff --git a/packages/react-native-web/src/exports/TextInput/index.js b/packages/react-native-web/src/exports/TextInput/index.js index 0f334b0f..f1e3c729 100644 --- a/packages/react-native-web/src/exports/TextInput/index.js +++ b/packages/react-native-web/src/exports/TextInput/index.js @@ -95,7 +95,8 @@ class TextInput extends React.Component { render() { const { autoCapitalize = 'sentences', - autoComplete = 'on', + autoComplete, + autoCompleteType, autoCorrect = true, autoFocus, defaultValue, @@ -144,9 +145,7 @@ class TextInput extends React.Component { Object.assign(supportedProps, { autoCapitalize, - // Browser's treat autocomplete "off" as "on" - // https://bugs.chromium.org/p/chromium/issues/detail?id=468153#c164 - autoComplete: autoComplete === 'off' ? 'noop' : autoComplete, + autoComplete: autoComplete || autoCompleteType || 'on', autoCorrect: autoCorrect ? 'on' : 'off', autoFocus, classList: [classes.textinput], diff --git a/packages/react-native-web/src/exports/TextInput/types.js b/packages/react-native-web/src/exports/TextInput/types.js index df5dbf7e..31d78ea4 100644 --- a/packages/react-native-web/src/exports/TextInput/types.js +++ b/packages/react-native-web/src/exports/TextInput/types.js @@ -21,6 +21,7 @@ export type TextInputProps = { ...ViewProps, autoCapitalize?: 'characters' | 'none' | 'sentences' | 'words', autoComplete?: string, + autoCompleteType?: string, // Compat with React Native (Bug react-native#26003) autoCorrect?: boolean, autoFocus?: boolean, blurOnSubmit?: boolean,