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

Make login form accessible to Password Managers #5275

Merged
merged 30 commits into from
Dec 6, 2021
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
5b66bdc
make Input accessible
parasharrajat Sep 15, 2021
8fcf1fd
fix: input for password Managers
parasharrajat Sep 15, 2021
228b1b2
adjust the Form for Password Managers
parasharrajat Sep 15, 2021
69f0e1d
Merge branch 'main' of github.com:Expensify/Expensify.cash into login…
parasharrajat Sep 15, 2021
31f6ebb
Merge latest chagnes from master
parasharrajat Nov 6, 2021
0c95acf
Refactor code
parasharrajat Nov 7, 2021
08a441e
Refactor Form
parasharrajat Nov 7, 2021
f5c1709
last touch up
parasharrajat Nov 7, 2021
28b22f1
Enable multi steo form
parasharrajat Nov 7, 2021
bf7859e
Multi step form support
parasharrajat Nov 7, 2021
b180d80
refactor page to set the focus correctly
parasharrajat Nov 8, 2021
62683de
Pull latest changes
parasharrajat Nov 8, 2021
e5b81eb
fix: Dom change
parasharrajat Nov 8, 2021
36ec46b
Pull latest changes
parasharrajat Nov 9, 2021
9f035f1
refactor
parasharrajat Nov 9, 2021
e621911
Pull new changes from main
parasharrajat Nov 24, 2021
14cb551
Merge branch 'main' of github.com:Expensify/Expensify.cash into login…
parasharrajat Dec 1, 2021
5938bd8
Review- 1
parasharrajat Dec 1, 2021
c12aeab
Merge branch 'main' of github.com:Expensify/Expensify.cash into login…
parasharrajat Dec 1, 2021
46430c7
Review comments
parasharrajat Dec 2, 2021
8b3127a
fix: Collapsible view
parasharrajat Dec 2, 2021
d7365f0
fix: form
parasharrajat Dec 2, 2021
9f5aa7b
pass down the name prop
parasharrajat Dec 2, 2021
9703fe6
typos
parasharrajat Dec 2, 2021
a1c5ac0
Clear form
parasharrajat Dec 2, 2021
530627f
Review -2
parasharrajat Dec 2, 2021
b594059
review-3
parasharrajat Dec 2, 2021
db6b4b6
Extra prop definition removed
parasharrajat Dec 2, 2021
4da3cb1
Reafactor code to remove isvisible dependency in PasswordForm UI and …
parasharrajat Dec 3, 2021
d39fa49
fix prop definition
parasharrajat Dec 6, 2021
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
27 changes: 15 additions & 12 deletions src/components/ExpensiTextInput/BaseExpensiTextInput.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import _ from 'underscore';
import React, {Component} from 'react';
import {
Animated, TextInput, View, TouchableWithoutFeedback, Pressable,
Animated, View, TouchableWithoutFeedback, Pressable,
} from 'react-native';
import Str from 'expensify-common/lib/str';
import ExpensiTextInputLabel from './ExpensiTextInputLabel';
Expand All @@ -12,6 +12,7 @@ import Icon from '../Icon';
import * as Expensicons from '../Icon/Expensicons';
import InlineErrorText from '../InlineErrorText';
import * as styleConst from './styleConst';
import TextInputWithName from '../TextInputWithName';

class BaseExpensiTextInput extends Component {
constructor(props) {
Expand Down Expand Up @@ -167,11 +168,12 @@ class BaseExpensiTextInput extends Component {
label={this.props.label}
labelTranslateY={this.state.labelTranslateY}
labelScale={this.state.labelScale}
for={this.props.nativeID}
/>
</>
) : null}
<View style={[styles.expensiTextInputAndIconContainer]}>
<TextInput
<TextInputWithName
ref={(ref) => {
if (typeof this.props.innerRef === 'function') { this.props.innerRef(ref); }
this.input = ref;
Expand All @@ -189,18 +191,19 @@ class BaseExpensiTextInput extends Component {
onChangeText={this.setValue}
secureTextEntry={this.state.passwordHidden}
onPressOut={this.props.onPress}
name={this.props.name}
/>
{this.props.secureTextEntry && (
<Pressable
accessibilityRole="button"
style={styles.secureInputEyeButton}
onPress={this.togglePasswordVisibility}
>
<Icon
src={this.state.passwordHidden ? Expensicons.Eye : Expensicons.EyeDisabled}
fill={themeColors.icon}
/>
</Pressable>
<Pressable
accessibilityRole="button"
style={styles.secureInputEyeButton}
onPress={this.togglePasswordVisibility}
>
<Icon
src={this.state.passwordHidden ? Expensicons.Eye : Expensicons.EyeDisabled}
fill={themeColors.icon}
/>
</Pressable>
)}
</View>
</View>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,23 @@ import {Animated} from 'react-native';

const propTypes = {
/** Label */
label: PropTypes.string,
label: PropTypes.string.isRequired,

/** Label vertical translate */
labelTranslateY: PropTypes.instanceOf(Animated.Value).isRequired,

/** Label scale */
labelScale: PropTypes.instanceOf(Animated.Value).isRequired,

/** For attribute for label */
for: PropTypes.string,
};

const defaultProps = {
for: '',
};

export default propTypes;
export {
propTypes,
defaultProps,
};
53 changes: 33 additions & 20 deletions src/components/ExpensiTextInput/ExpensiTextInputLabel/index.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,39 @@
import React, {memo} from 'react';
import React, {PureComponent} from 'react';
import {Animated} from 'react-native';
import styles from '../../../styles/styles';
import propTypes from './expensiTextInputLabelPropTypes';
import {propTypes, defaultProps} from './expensiTextInputLabelPropTypes';

const ExpensiTextInputLabel = props => (
<Animated.Text
style={[
styles.expensiTextInputLabel,
styles.expensiTextInputLabelDesktop,
styles.expensiTextInputLabelTransformation(
props.labelTranslateY,
0,
props.labelScale,
),
]}
pointerEvents="none"
>
{props.label}
</Animated.Text>
);
class ExpensiTextInputLabel extends PureComponent {
componentDidMount() {
if (!this.props.for) {
return;
}
this.label.setNativeProps({for: this.props.for});
}

render() {
return (
<Animated.Text
pointerEvents="none"
accessibilityRole="label"
ref={el => this.label = el}
style={[
styles.expensiTextInputLabel,
styles.expensiTextInputLabelDesktop,
styles.expensiTextInputLabelTransformation(
this.props.labelTranslateY,
0,
this.props.labelScale,
),
]}
>
{this.props.label}
</Animated.Text>
);
}
}

ExpensiTextInputLabel.propTypes = propTypes;
ExpensiTextInputLabel.displayName = 'ExpensiTextInputLabel';
ExpensiTextInputLabel.defaultProps = defaultProps;

export default memo(ExpensiTextInputLabel);
export default ExpensiTextInputLabel;
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, {PureComponent} from 'react';
import {Animated} from 'react-native';
import styles from '../../../styles/styles';
import propTypes from './expensiTextInputLabelPropTypes';
import * as expensiTextInputLabelPropTypes from './expensiTextInputLabelPropTypes';
import * as styleConst from '../styleConst';

class ExpensiTextInputLabel extends PureComponent {
Expand Down Expand Up @@ -36,6 +36,7 @@ class ExpensiTextInputLabel extends PureComponent {
}
}

ExpensiTextInputLabel.propTypes = propTypes;
ExpensiTextInputLabel.propTypes = expensiTextInputLabelPropTypes.propTypes;
ExpensiTextInputLabel.propTypes = expensiTextInputLabelPropTypes.defaultProps;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ExpensiTextInputLabel.defaultProps =

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, Nice catch.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


export default ExpensiTextInputLabel;
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ const propTypes = {
/** Input label */
label: PropTypes.string,

/** Name attribute for the input */
name: PropTypes.string,

/** Input value */
value: PropTypes.string,

Expand Down Expand Up @@ -33,6 +36,7 @@ const propTypes = {

const defaultProps = {
label: '',
name: '',
errorText: '',
placeholder: '',
hasError: false,
Expand Down
16 changes: 16 additions & 0 deletions src/components/Form/BaseForm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React, {forwardRef} from 'react';
import {View} from 'react-native';
import * as ComponentUtils from '../../libs/ComponentUtils';

const BaseForm = forwardRef((props, ref) => (
<View
accessibilityRole={ComponentUtils.ACCESSIBILITY_ROLE_FORM}
accessibilityAutoComplete="on"
ref={ref}
// eslint-disable-next-line react/jsx-props-no-spreading
{...props}
/>
));

BaseForm.displayName = 'BaseForm';
export default BaseForm;
28 changes: 28 additions & 0 deletions src/components/Form/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import React from 'react';
import BaseForm from './BaseForm';

class Form extends React.Component {
componentDidMount() {
if (!this.form) {
return;
}

// Password Managers need these attributes to be able to identify the form elements properly.
this.form.setNativeProps({
method: 'post',
action: '/',
});
}

render() {
return (
<BaseForm
ref={el => this.form = el}
// eslint-disable-next-line react/jsx-props-no-spreading
{...this.props}
/>
);
}
}

export default Form;
8 changes: 8 additions & 0 deletions src/components/Form/index.native.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import React from 'react';
import BaseForm from './BaseForm';

// eslint-disable-next-line react/jsx-props-no-spreading
const Form = props => <BaseForm {...props} />;

Form.displayName = 'Form';
export default Form;
40 changes: 40 additions & 0 deletions src/components/TextInputWithName/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import _ from 'underscore';
import React from 'react';
import {TextInput} from 'react-native';
import textInputWithNamepropTypes from './textInputWithNamepropTypes';

/**
* On web we need to set the native attribute name for accessiblity.
*/
class TextInputWithName extends React.Component {
componentDidMount() {
if (!this.textInput) {
return;
}
if (_.isFunction(this.props.forwardedRef)) {
this.props.forwardedRef(this.textInput);
}

if (this.props.name) {
this.textInput.setNativeProps({name: this.props.name});
}
}

render() {
return (
<TextInput
ref={el => this.textInput = el}
// eslint-disable-next-line react/jsx-props-no-spreading
{...this.props}
/>
);
}
}

TextInputWithName.propTypes = textInputWithNamepropTypes.propTypes;
TextInputWithName.defaultProps = textInputWithNamepropTypes.defaultProps;

export default React.forwardRef((props, ref) => (
/* eslint-disable-next-line react/jsx-props-no-spreading */
<TextInputWithName {...props} forwardedRef={ref} />
));
20 changes: 20 additions & 0 deletions src/components/TextInputWithName/index.native.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import React from 'react';
import {TextInput} from 'react-native';
import textInputWithNamepropTypes from './textInputWithNamepropTypes';

const TextInputWithName = props => (
<TextInput
ref={props.forwardedRef}
// eslint-disable-next-line react/jsx-props-no-spreading
{...props}
/>
);

TextInputWithName.propTypes = textInputWithNamepropTypes.propTypes;
TextInputWithName.defaultProps = textInputWithNamepropTypes.defaultProps;
TextInputWithName.displayName = 'TextInputWithName';

export default React.forwardRef((props, ref) => (
/* eslint-disable-next-line react/jsx-props-no-spreading */
<TextInputWithName {...props} forwardedRef={ref} />
));
19 changes: 19 additions & 0 deletions src/components/TextInputWithName/textInputWithNamepropTypes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import PropTypes from 'prop-types';

const propTypes = {
/** Name attribute for the input */
name: PropTypes.string,

/** A ref to forward to the text input */
forwardedRef: PropTypes.func,
};

const defaultProps = {
name: '',
forwardedRef: () => {},
};

export default {
propTypes,
defaultProps,
};
46 changes: 46 additions & 0 deletions src/components/withToggleVisibilityView.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import React from 'react';
import {View} from 'react-native';
import PropTypes from 'prop-types';
import styles from '../styles/styles';
import getComponentDisplayName from '../libs/getComponentDisplayName';

const toggleVisibilityViewPropTypes = {
/** Whether the content is visible. */
isVisible: PropTypes.bool,
};

export default function (WrappedComponent) {
const WithToggleVisibilityView = props => (
<View style={!props.isVisible && styles.visuallyHidden}>
<WrappedComponent
// eslint-disable-next-line react/jsx-props-no-spreading
{...props}
ref={props.forwardedRef}
isVisible={props.isVisible}
/>
</View>
);

WithToggleVisibilityView.displayName = `WithToggleVisibilityView(${getComponentDisplayName(WrappedComponent)})`;
WithToggleVisibilityView.propTypes = {
forwardedRef: PropTypes.oneOfType([
PropTypes.func,
PropTypes.shape({current: PropTypes.instanceOf(React.Component)}),
]),

/** Whether the content is visible. */
isVisible: PropTypes.bool,
};
WithToggleVisibilityView.defaultProps = {
forwardedRef: undefined,
isVisible: false,
};
return React.forwardRef((props, ref) => (
// eslint-disable-next-line react/jsx-props-no-spreading
<WithToggleVisibilityView {...props} forwardedRef={ref} />
));
}

export {
toggleVisibilityViewPropTypes,
};
10 changes: 10 additions & 0 deletions src/libs/ComponentUtils/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* Web password field needs `current-password` as autocomplete type which is not supported on native
*/
const PASSWORD_AUTOCOMPLETE_TYPE = 'current-password';
const ACCESSIBILITY_ROLE_FORM = 'form';

export {
PASSWORD_AUTOCOMPLETE_TYPE,
ACCESSIBILITY_ROLE_FORM,
};
7 changes: 7 additions & 0 deletions src/libs/ComponentUtils/index.native.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const PASSWORD_AUTOCOMPLETE_TYPE = 'password';
const ACCESSIBILITY_ROLE_FORM = 'none';

export {
PASSWORD_AUTOCOMPLETE_TYPE,
ACCESSIBILITY_ROLE_FORM,
};
Loading