Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove isFormInput prop #8887

Merged
merged 8 commits into from
May 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions FORMS.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,27 +187,24 @@ function onSubmit(values) {
label="Routing number"
inputID="routingNumber"
maxLength={8}
isFormInput
shouldSaveDraft
/>
</View>
<TextInput
label="Account number"
inputID="accountNumber"
containerStyles={[styles.mt4]}
isFormInput
/>
</Form>
```

### Props provided to Form inputs

The following props are available to form inputs:
The following prop is available to form inputs:

- inputID: An unique identifier for the input.
- isFormInput: A flag that indicates that this input is being used with Form.js.

Form.js will automatically provide the following props to any input flagged with the isFormInput prop.
Form.js will automatically provide the following props to any input with the inputID prop.

- ref: A React ref that must be attached to the input.
- defaultValue: The input default value.
Expand Down
17 changes: 3 additions & 14 deletions src/components/AddressSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,15 @@ import styles from '../styles/styles';
import TextInput from './TextInput';
import Log from '../libs/Log';
import * as GooglePlacesUtils from '../libs/GooglePlacesUtils';
import * as FormUtils from '../libs/FormUtils';

// The error that's being thrown below will be ignored until we fork the
// react-native-google-places-autocomplete repo and replace the
// VirtualizedList component with a VirtualizedList-backed instead
LogBox.ignoreLogs(['VirtualizedLists should never be nested']);

const propTypes = {
/** Indicates that the input is being used with the Form component */
isFormInput: PropTypes.bool,

/**
* The ID used to uniquely identify the input
*
* @param {Object} props - props passed to the input
* @returns {Object} - returns an Error object if isFormInput is supplied but inputID is falsey or not a string
*/
inputID: props => FormUtils.validateInputIDProps(props),
/** The ID used to uniquely identify the input in a Form */
inputID: PropTypes.string,

/** Saves a draft of the input value when used in a form */
shouldSaveDraft: PropTypes.bool,
Expand Down Expand Up @@ -59,7 +50,6 @@ const propTypes = {
};

const defaultProps = {
isFormInput: false,
inputID: undefined,
shouldSaveDraft: false,
onBlur: () => {},
Expand Down Expand Up @@ -174,13 +164,12 @@ const AddressSearch = (props) => {
hint: props.hint,
value: props.value,
defaultValue: props.defaultValue,
isFormInput: props.isFormInput,
inputID: props.inputID,
shouldSaveDraft: props.shouldSaveDraft,
onBlur: props.onBlur,
autoComplete: 'off',
onInputChange: (text) => {
if (props.isFormInput) {
if (props.inputID) {
props.onInputChange(text);
} else {
props.onInputChange({street: text});
Expand Down
15 changes: 2 additions & 13 deletions src/components/CheckboxWithLabel.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import styles from '../styles/styles';
import Checkbox from './Checkbox';
import Text from './Text';
import InlineErrorText from './InlineErrorText';
import * as FormUtils from '../libs/FormUtils';

const propTypes = {
/** Whether the checkbox is checked */
Expand All @@ -27,29 +26,20 @@ const propTypes = {
/** Error text to display */
errorText: PropTypes.string,

/** Indicates that the input is being used with the Form component */
isFormInput: PropTypes.bool,

/** The default value for the checkbox */
defaultValue: PropTypes.bool,

/** React ref being forwarded to the Checkbox input */
forwardedRef: PropTypes.func,

/**
* The ID used to uniquely identify the input
*
* @param {Object} props - props passed to the input
* @returns {Object} - returns an Error object if isFormInput is supplied but inputID is falsey or not a string
*/
inputID: props => FormUtils.validateInputIDProps(props),
/** The ID used to uniquely identify the input in a Form */
inputID: PropTypes.string,

/** Saves a draft of the input value when used in a form */
shouldSaveDraft: PropTypes.bool,
};

const defaultProps = {
isFormInput: false,
inputID: undefined,
style: [],
label: undefined,
Expand Down Expand Up @@ -86,7 +76,6 @@ const CheckboxWithLabel = (props) => {
label={props.label}
hasError={Boolean(props.errorText)}
forwardedRef={props.forwardedRef}
isFormInput={props.isFormInput}
inputID={props.inputID}
shouldSaveDraft={props.shouldSaveDraft}
/>
Expand Down
4 changes: 2 additions & 2 deletions src/components/Form.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ class Form extends React.Component {
});
}

// We check if the child has the isFormInput prop.
// We check if the child has the inputID prop.
// We don't want to pass form props to non form components, e.g. View, Text, etc
if (!child.props.isFormInput) {
if (!child.props.inputID) {
return child;
}

Expand Down
14 changes: 2 additions & 12 deletions src/components/Picker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import BasePicker from './BasePicker';
import Text from '../Text';
import styles from '../../styles/styles';
import InlineErrorText from '../InlineErrorText';
import * as FormUtils from '../../libs/FormUtils';

const propTypes = {
/** Picker label */
Expand All @@ -24,16 +23,8 @@ const propTypes = {
/** Customize the Picker container */
containerStyles: PropTypes.arrayOf(PropTypes.object),

/** Indicates that the input is being used with the Form component */
isFormInput: PropTypes.bool,

/**
* The ID used to uniquely identify the input
*
* @param {Object} props - props passed to the input
* @returns {Object} - returns an Error object if isFormInput is supplied but inputID is falsey or not a string
*/
inputID: props => FormUtils.validateInputIDProps(props),
/** The ID used to uniquely identify the input in a Form */
inputID: PropTypes.string,

/** Saves a draft of the input value when used in a form */
shouldSaveDraft: PropTypes.bool,
Expand All @@ -44,7 +35,6 @@ const defaultProps = {
isDisabled: false,
errorText: '',
containerStyles: [],
isFormInput: false,
inputID: undefined,
shouldSaveDraft: false,
value: undefined,
Expand Down
15 changes: 2 additions & 13 deletions src/components/StatePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import PropTypes from 'prop-types';
import {CONST} from 'expensify-common/lib/CONST';
import Picker from './Picker';
import withLocalize, {withLocalizePropTypes} from './withLocalize';
import * as FormUtils from '../libs/FormUtils';

const STATES = _.map(CONST.STATES, ({stateISO}) => ({
value: stateISO,
Expand All @@ -21,16 +20,8 @@ const propTypes = {
/** The value that needs to be selected */
value: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),

/** Indicates that the input is being used with the Form component */
isFormInput: PropTypes.bool,

/**
* The ID used to uniquely identify the input
*
* @param {Object} props - props passed to the input
* @returns {Object} - returns an Error object if isFormInput is supplied but inputID is falsey or not a string
*/
inputID: props => FormUtils.validateInputIDProps(props),
/** The ID used to uniquely identify the input in a Form */
inputID: PropTypes.string,

/** Saves a draft of the input value when used in a form */
shouldSaveDraft: PropTypes.bool,
Expand All @@ -53,7 +44,6 @@ const defaultProps = {
defaultValue: undefined,
errorText: '',
shouldSaveDraft: false,
isFormInput: false,
inputID: undefined,
onBlur: () => {},
};
Expand All @@ -69,7 +59,6 @@ const StatePicker = forwardRef((props, ref) => (
label={props.label || props.translate('common.state')}
errorText={props.errorText}
onBlur={props.onBlur}
isFormInput={props.isFormInput}
shouldSaveDraft={props.shouldSaveDraft}
/>
));
Expand Down
14 changes: 2 additions & 12 deletions src/components/TextInput/baseTextInputPropTypes.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import PropTypes from 'prop-types';
import * as FormUtils from '../../libs/FormUtils';

const propTypes = {
/** Input label */
Expand Down Expand Up @@ -57,16 +56,8 @@ const propTypes = {
prefixCharacter: PropTypes.string,

/** Form props */
/** Indicates that the input is being used with the Form component */
isFormInput: PropTypes.bool,

/**
* The ID used to uniquely identify the input
*
* @param {Object} props - props passed to the input
* @returns {Object} - returns an Error object if isFormInput is supplied but inputID is falsey or not a string
*/
inputID: props => FormUtils.validateInputIDProps(props),
/** The ID used to uniquely identify the input in a Form */
inputID: PropTypes.string,

/** Saves a draft of the input value when used in a form */
shouldSaveDraft: PropTypes.bool,
Expand All @@ -76,7 +67,6 @@ const propTypes = {
};

const defaultProps = {
isFormInput: false,
label: '',
name: '',
errorText: '',
Expand Down
22 changes: 0 additions & 22 deletions src/libs/FormUtils.js

This file was deleted.

9 changes: 0 additions & 9 deletions src/stories/Form.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,28 +42,24 @@ const Template = (args) => {
<TextInput
label="Routing number"
inputID="routingNumber"
isFormInput
shouldSaveDraft
/>
</View>
<TextInput
label="Account number"
inputID="accountNumber"
containerStyles={[styles.mt4]}
isFormInput
/>
<AddressSearch
label="Street"
inputID="street"
containerStyles={[styles.mt4]}
hint="No PO box"
isFormInput
/>
<DatePicker
label="Date of birth"
inputID="dob"
containerStyles={[styles.mt4]}
isFormInput
/>
<View>
<Picker
Expand All @@ -85,7 +81,6 @@ const Template = (args) => {
value: 'apple',
},
]}
isFormInput
/>
</View>
<Picker
Expand All @@ -106,19 +101,16 @@ const Template = (args) => {
value: 'apple',
},
]}
isFormInput
/>
<View style={styles.mt4}>
<StatePicker
inputID="pickState"
shouldSaveDraft
isFormInput
/>
</View>
<CheckboxWithLabel
inputID="checkbox"
style={[styles.mb4, styles.mt5]}
isFormInput
shouldSaveDraft
LabelComponent={() => (
<Text>I accept the Expensify Terms of Service</Text>
Expand Down Expand Up @@ -148,7 +140,6 @@ const WithNativeEventHandler = (args) => {
label="Routing number"
inputID="routingNumber"
onChangeText={setLog}
isFormInput
shouldSaveDraft
/>
<Text>
Expand Down