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

Manage switchs value on settings with enter key #1105

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion src/components/Settings/Display/Display.component.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import { FormattedMessage } from 'react-intl';
import Switch from '@material-ui/core/Switch';
import Switch from '../../UI/Switch';
import Paper from '@material-ui/core/Paper';
import List from '@material-ui/core/List';
import ListItem from '@material-ui/core/ListItem';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ exports[`Display tests default renderer 1`] = `
}
/>
<ForwardRef(WithStyles(ForwardRef(ListItemSecondaryAction)))>
<ForwardRef(WithStyles(ForwardRef(Switch)))
<SwitchWithEnter
color="secondary"
onChange={[Function]}
value="active"
Expand Down Expand Up @@ -210,7 +210,7 @@ exports[`Display tests default renderer 1`] = `
<ForwardRef(WithStyles(ForwardRef(ListItemSecondaryAction)))
className="Display__Options"
>
<ForwardRef(WithStyles(ForwardRef(Switch)))
<SwitchWithEnter
color="secondary"
onChange={[Function]}
value="active"
Expand Down
2 changes: 1 addition & 1 deletion src/components/Settings/Navigation/Navigation.component.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import { FormattedMessage } from 'react-intl';
import Switch from '@material-ui/core/Switch';
import Switch from '../../UI/Switch';
import Paper from '@material-ui/core/Paper';
import List from '@material-ui/core/List';
import ListItem from '@material-ui/core/ListItem';
Expand Down
7 changes: 3 additions & 4 deletions src/components/Settings/Navigation/Navigation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,11 @@ describe('Navigation tests', () => {
expect(tree).toMatchSnapshot();

const state = wrapper.state();

const switch0 = wrapper.find('WithStyles(ForwardRef(Switch))').at(0);
const switch0 = wrapper.find('SwitchWithEnter').at(0);
switch0.simulate('change');
const switch1 = wrapper.find('WithStyles(ForwardRef(Switch))').at(1);
const switch1 = wrapper.find('SwitchWithEnter').at(1);
switch1.simulate('change');
const switch2 = wrapper.find('WithStyles(ForwardRef(Switch))').at(2);
const switch2 = wrapper.find('SwitchWithEnter').at(2);
switch2.simulate('change');

const newState = wrapper.state();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ exports[`Navigation tests default renderer 1`] = `
}
/>
<ForwardRef(WithStyles(ForwardRef(ListItemSecondaryAction)))>
<ForwardRef(WithStyles(ForwardRef(Switch)))
<SwitchWithEnter
checked={false}
color="secondary"
onChange={[Function]}
Expand All @@ -61,7 +61,7 @@ exports[`Navigation tests default renderer 1`] = `
}
/>
<ForwardRef(WithStyles(ForwardRef(ListItemSecondaryAction)))>
<ForwardRef(WithStyles(ForwardRef(Switch)))
<SwitchWithEnter
checked={false}
color="secondary"
onChange={[Function]}
Expand All @@ -85,7 +85,7 @@ exports[`Navigation tests default renderer 1`] = `
}
/>
<ForwardRef(WithStyles(ForwardRef(ListItemSecondaryAction)))>
<ForwardRef(WithStyles(ForwardRef(Switch)))
<SwitchWithEnter
checked={false}
color="secondary"
onChange={[Function]}
Expand All @@ -111,7 +111,7 @@ exports[`Navigation tests default renderer 1`] = `
}
/>
<ForwardRef(WithStyles(ForwardRef(ListItemSecondaryAction)))>
<ForwardRef(WithStyles(ForwardRef(Switch)))
<SwitchWithEnter
checked={false}
color="secondary"
disabled={true}
Expand All @@ -136,7 +136,7 @@ exports[`Navigation tests default renderer 1`] = `
}
/>
<ForwardRef(WithStyles(ForwardRef(ListItemSecondaryAction)))>
<ForwardRef(WithStyles(ForwardRef(Switch)))
<SwitchWithEnter
checked={false}
color="secondary"
onChange={[Function]}
Expand All @@ -162,7 +162,7 @@ exports[`Navigation tests default renderer 1`] = `
}
/>
<ForwardRef(WithStyles(ForwardRef(ListItemSecondaryAction)))>
<ForwardRef(WithStyles(ForwardRef(Switch)))
<SwitchWithEnter
checked={false}
color="secondary"
onChange={[Function]}
Expand Down Expand Up @@ -213,7 +213,7 @@ exports[`Navigation tests switchs behavior 1`] = `
}
/>
<WithStyles(ForwardRef(ListItemSecondaryAction))>
<WithStyles(ForwardRef(Switch))
<SwitchWithEnter
checked={false}
color="secondary"
onChange={[Function]}
Expand All @@ -237,7 +237,7 @@ exports[`Navigation tests switchs behavior 1`] = `
}
/>
<WithStyles(ForwardRef(ListItemSecondaryAction))>
<WithStyles(ForwardRef(Switch))
<SwitchWithEnter
checked={false}
color="secondary"
onChange={[Function]}
Expand All @@ -261,7 +261,7 @@ exports[`Navigation tests switchs behavior 1`] = `
}
/>
<WithStyles(ForwardRef(ListItemSecondaryAction))>
<WithStyles(ForwardRef(Switch))
<SwitchWithEnter
checked={false}
color="secondary"
onChange={[Function]}
Expand All @@ -287,7 +287,7 @@ exports[`Navigation tests switchs behavior 1`] = `
}
/>
<WithStyles(ForwardRef(ListItemSecondaryAction))>
<WithStyles(ForwardRef(Switch))
<SwitchWithEnter
checked={false}
color="secondary"
disabled={true}
Expand All @@ -312,7 +312,7 @@ exports[`Navigation tests switchs behavior 1`] = `
}
/>
<WithStyles(ForwardRef(ListItemSecondaryAction))>
<WithStyles(ForwardRef(Switch))
<SwitchWithEnter
checked={false}
color="secondary"
onChange={[Function]}
Expand All @@ -338,7 +338,7 @@ exports[`Navigation tests switchs behavior 1`] = `
}
/>
<WithStyles(ForwardRef(ListItemSecondaryAction))>
<WithStyles(ForwardRef(Switch))
<SwitchWithEnter
checked={false}
color="secondary"
onChange={[Function]}
Expand Down Expand Up @@ -389,7 +389,7 @@ exports[`Navigation tests switchs behavior 2`] = `
}
/>
<WithStyles(ForwardRef(ListItemSecondaryAction))>
<WithStyles(ForwardRef(Switch))
<SwitchWithEnter
checked={true}
color="secondary"
onChange={[Function]}
Expand All @@ -413,7 +413,7 @@ exports[`Navigation tests switchs behavior 2`] = `
}
/>
<WithStyles(ForwardRef(ListItemSecondaryAction))>
<WithStyles(ForwardRef(Switch))
<SwitchWithEnter
checked={true}
color="secondary"
onChange={[Function]}
Expand All @@ -437,7 +437,7 @@ exports[`Navigation tests switchs behavior 2`] = `
}
/>
<WithStyles(ForwardRef(ListItemSecondaryAction))>
<WithStyles(ForwardRef(Switch))
<SwitchWithEnter
checked={true}
color="secondary"
onChange={[Function]}
Expand All @@ -463,7 +463,7 @@ exports[`Navigation tests switchs behavior 2`] = `
}
/>
<WithStyles(ForwardRef(ListItemSecondaryAction))>
<WithStyles(ForwardRef(Switch))
<SwitchWithEnter
checked={false}
color="secondary"
disabled={true}
Expand All @@ -488,7 +488,7 @@ exports[`Navigation tests switchs behavior 2`] = `
}
/>
<WithStyles(ForwardRef(ListItemSecondaryAction))>
<WithStyles(ForwardRef(Switch))
<SwitchWithEnter
checked={false}
color="secondary"
onChange={[Function]}
Expand All @@ -514,7 +514,7 @@ exports[`Navigation tests switchs behavior 2`] = `
}
/>
<WithStyles(ForwardRef(ListItemSecondaryAction))>
<WithStyles(ForwardRef(Switch))
<SwitchWithEnter
checked={false}
color="secondary"
onChange={[Function]}
Expand Down
2 changes: 1 addition & 1 deletion src/components/Settings/Scanning/Scanning.component.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import { FormattedMessage } from 'react-intl';
import Switch from '@material-ui/core/Switch';
import Switch from '../../UI/Switch';
import Select from '@material-ui/core/Select';
import MenuItem from '@material-ui/core/MenuItem';
import Paper from '@material-ui/core/Paper';
Expand Down
2 changes: 1 addition & 1 deletion src/components/Settings/Scanning/Scanning.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ describe('Scanning tests', () => {

const state = wrapper.state();

const switchElement = wrapper.find('WithStyles(ForwardRef(Switch))').at(0);
const switchElement = wrapper.find('SwitchWithEnter').at(0);
switchElement.simulate('change');
/**
const selects = wrapper.find('Select');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ exports[`Scanning tests default renderer 1`] = `
}
/>
<ForwardRef(WithStyles(ForwardRef(ListItemSecondaryAction)))>
<ForwardRef(WithStyles(ForwardRef(Switch)))
<SwitchWithEnter
checked={false}
color="secondary"
onChange={[Function]}
Expand Down Expand Up @@ -249,7 +249,7 @@ exports[`Scanning tests options behavior 1`] = `
}
/>
<WithStyles(ForwardRef(ListItemSecondaryAction))>
<WithStyles(ForwardRef(Switch))
<SwitchWithEnter
checked={false}
color="secondary"
onChange={[Function]}
Expand Down Expand Up @@ -466,7 +466,7 @@ exports[`Scanning tests options behavior 2`] = `
}
/>
<WithStyles(ForwardRef(ListItemSecondaryAction))>
<WithStyles(ForwardRef(Switch))
<SwitchWithEnter
checked={true}
color="secondary"
onChange={[Function]}
Expand Down
28 changes: 28 additions & 0 deletions src/components/UI/Switch/Switch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import React from 'react';
import Switch from '@material-ui/core/Switch';
import PropTypes from 'prop-types';

const propTypes = {
/**
* The callback function trigered when the switch change value. The value change and then the switch change position.
*/
onChange: PropTypes.func.isRequired
};

function SwitchWithEnter(props) {
const onKeyUp = event => {
if (event.key === 'Enter' || event.keyCode === 13) {
props.onChange();
}
};

return (
<div onKeyUp={onKeyUp}>
<Switch {...props} />
</div>
);
}

SwitchWithEnter.propTypes = propTypes;

export default SwitchWithEnter;
1 change: 1 addition & 0 deletions src/components/UI/Switch/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './Switch';