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

Fix checkbox accessibility #8874

Merged
merged 30 commits into from
Aug 31, 2022
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
dce0b2c
fix: checkbox accessibility (toggle with space)
mdneyazahmad May 4, 2022
13bf388
feat: add style prop to CheckboxButton
mdneyazahmad May 4, 2022
d589249
fix: secure textinput eye icon accesibility
mdneyazahmad May 4, 2022
acf7c34
fix: add missing propTypes and defaultProps
mdneyazahmad May 4, 2022
9e908cd
fix: linting errors
mdneyazahmad May 4, 2022
a02facd
fix: lint errors
mdneyazahmad May 4, 2022
e64cbc9
fix: error on native checkbox
mdneyazahmad May 6, 2022
4e668a6
Merge branch 'main' of github.com:Expensify/App into fix/checkbox
mdneyazahmad May 6, 2022
4215fb8
Merge branch 'main' of github.com:Expensify/App into fix/checkbox
mdneyazahmad May 9, 2022
763eed8
refactor: move checkboxes files
mdneyazahmad May 9, 2022
d708f43
refactor: add space keycode in CONST file
mdneyazahmad May 11, 2022
833cc6d
refactor: remove displayName from class component
mdneyazahmad May 11, 2022
33ab163
Merge branch 'main' of github.com:Expensify/App into fix/checkbox
mdneyazahmad May 15, 2022
b382d2c
Merge branch 'main' of github.com:Expensify/App into fix/checkbox
mdneyazahmad May 20, 2022
c041a03
Refactor CheckboxButton component
mdneyazahmad Jun 9, 2022
2afa23b
Merge branch 'main' of github.com:Expensify/App into fix/checkbox
mdneyazahmad Jun 9, 2022
5c135a2
Delete CheckboxButton component
mdneyazahmad Jun 12, 2022
9aa62a3
Implement platform specific behavior for checkbox
mdneyazahmad Jun 13, 2022
fba92ce
Add checkbox accessibility role
mdneyazahmad Jun 16, 2022
091bb02
Refactor checkbox toggle function
mdneyazahmad Jun 16, 2022
af7dcee
Update comment for Checkbox component
mdneyazahmad Jun 16, 2022
17d1524
Merge branch 'main' of github.com:Expensify/App into fix/checkbox
mdneyazahmad Jun 16, 2022
6664d15
fix: merge conflict
mdneyazahmad Aug 20, 2022
7a6200c
Add focus ring to checkbox
mdneyazahmad Aug 20, 2022
4847fb3
Remove focus from checkbox label
mdneyazahmad Aug 20, 2022
0799705
Merge branch 'main' into fix/checkbox
mdneyazahmad Aug 28, 2022
0afa9b5
Refactor checkbox
mdneyazahmad Aug 28, 2022
80b5961
Fix prop to correct name
mdneyazahmad Aug 28, 2022
a0c17db
Refactor checkbox
mdneyazahmad Aug 29, 2022
03f1115
Remove focus ring from checkbox label
mdneyazahmad Aug 30, 2022
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
3 changes: 3 additions & 0 deletions src/CONST.js
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,9 @@ const CONST = {

// There's a limit of 60k characters in Auth - https://github.com/Expensify/Auth/blob/198d59547f71fdee8121325e8bc9241fc9c3236a/auth/lib/Request.h#L28
MAX_COMMENT_LENGTH: 60000,
KEYCODE: {
SPACE: 32,
},
};

export default CONST;
7 changes: 4 additions & 3 deletions src/components/Checkbox.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import React from 'react';
import {View, Pressable} from 'react-native';
import {View} from 'react-native';
import PropTypes from 'prop-types';
import styles from '../styles/styles';
import Icon from './Icon';
import * as Expensicons from './Icon/Expensicons';
import CheckboxButton from './CheckboxButton';

const propTypes = {
/** Whether checkbox is checked */
Expand Down Expand Up @@ -32,7 +33,7 @@ const defaultProps = {
};

const Checkbox = props => (
<Pressable
<CheckboxButton
disabled={props.disabled}
onPress={() => props.onPress(!props.isChecked)}
ref={props.forwardedRef}
Expand All @@ -47,7 +48,7 @@ const Checkbox = props => (
>
<Icon src={Expensicons.Checkmark} fill="white" height={14} width={14} />
</View>
</Pressable>
</CheckboxButton>
);

Checkbox.propTypes = propTypes;
Expand Down
87 changes: 87 additions & 0 deletions src/components/CheckboxButton/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import React, {Component} from 'react';
import {View} from 'react-native';
import PropTypes from 'prop-types';
import CONST from '../../CONST';

const propTypes = {
/** Should the input be disabled */
disabled: PropTypes.bool,

/** A function that is called when the box/label is pressed */
onPress: PropTypes.func.isRequired,

/** Additional styles to add to checkbox button */
style: PropTypes.oneOfType([
PropTypes.arrayOf(PropTypes.object),
PropTypes.object,
]),

/** A ref to forward to the Pressable */
forwardedRef: PropTypes.oneOfType([
PropTypes.func,
PropTypes.shape({current: PropTypes.instanceOf(React.Component)}),
]),

/** Children to wrap in CheckboxButton. */
children: PropTypes.node.isRequired,
};

const defaultProps = {
disabled: false,
style: [],
forwardedRef: undefined,
};

class CheckboxButton extends Component {
constructor(props) {
super(props);

this.onClick = this.onClick.bind(this);
this.onKeyDown = this.onKeyDown.bind(this);
this.onToggle = this.onToggle.bind(this);
}

onClick() {
this.onToggle();
}

onKeyDown(event) {
if (event.keyCode !== CONST.KEYCODE.SPACE) {
return;
}

this.onToggle();
event.stopPropagation();
event.preventDefault();
}

onToggle() {
if (this.props.disabled) {
return;
}

this.props.onPress();
}

render() {
return (
<View
focusable
onClick={this.onClick}
onKeyDown={this.onKeyDown}
ref={this.props.forwardedRef}
style={this.props.style}
>
{this.props.children}
</View>
mdneyazahmad marked this conversation as resolved.
Show resolved Hide resolved
);
}
}

CheckboxButton.propTypes = propTypes;
CheckboxButton.defaultProps = defaultProps;

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

const propTypes = {
/** Should the input be disabled */
disabled: PropTypes.bool,

/** A function that is called when the box/label is pressed */
onPress: PropTypes.func.isRequired,

/** Additional styles to add to checkbox button */
style: PropTypes.oneOfType([
PropTypes.arrayOf(PropTypes.object),
PropTypes.object,
]),

/** A ref to forward to the Pressable */
forwardedRef: PropTypes.oneOfType([
PropTypes.func,
PropTypes.shape({current: PropTypes.instanceOf(React.Component)}),
]),

/** Children to wrap in CheckboxButton. */
children: PropTypes.node.isRequired,
};

const defaultProps = {
disabled: false,
style: [],
forwardedRef: undefined,
};

const CheckboxButton = props => (
<Pressable
disabled={props.disabled}
onPress={props.onPress}
ref={props.forwardedRef}
style={props.style}
>
{props.children}
</Pressable>
);

CheckboxButton.propTypes = propTypes;
CheckboxButton.defaultProps = defaultProps;
CheckboxButton.displayName = 'CheckboxButton';

export default React.forwardRef((props, ref) => (
/* eslint-disable-next-line react/jsx-props-no-spreading */
<CheckboxButton {...props} forwardedRef={ref} />
));
8 changes: 4 additions & 4 deletions src/components/TextInput/BaseTextInput.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, View, TouchableWithoutFeedback, Pressable, AppState, Keyboard,
Animated, View, TouchableWithoutFeedback, AppState, Keyboard,
} from 'react-native';
import Str from 'expensify-common/lib/str';
import RNTextInput from '../RNTextInput';
Expand All @@ -14,6 +14,7 @@ import * as Expensicons from '../Icon/Expensicons';
import Text from '../Text';
import * as styleConst from './styleConst';
import * as StyleUtils from '../../styles/StyleUtils';
import CheckboxButton from '../CheckboxButton';

class BaseTextInput extends Component {
constructor(props) {
Expand Down Expand Up @@ -274,16 +275,15 @@ class BaseTextInput extends Component {
showSoftInputOnFocus={!this.props.disableKeyboard}
/>
{this.props.secureTextEntry && (
<Pressable
accessibilityRole="button"
mdneyazahmad marked this conversation as resolved.
Show resolved Hide resolved
<CheckboxButton
style={styles.secureInputShowPasswordButton}
onPress={this.togglePasswordVisibility}
>
<Icon
src={this.state.passwordHidden ? Expensicons.Eye : Expensicons.EyeDisabled}
fill={themeColors.icon}
/>
</Pressable>
</CheckboxButton>
)}
</View>
</View>
Expand Down