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

CreditCardNumber disallow setting type #331

Merged
merged 2 commits into from
Nov 6, 2017
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
8 changes: 5 additions & 3 deletions src/components/CreditCardNumber.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ function includes(array, value) {
export default class CreditCardNumber extends React.Component {

static propTypes = {
...Input.propTypes,
className: PropTypes.string,
types: PropTypes.arrayOf(PropTypes.string),
value: PropTypes.string,
onChange: PropTypes.func,
};

static defaultProps = {
...Input.defaultProps,
className: '',
types: Object.keys(ICONS),
onChange: () => {},
Expand All @@ -55,9 +57,9 @@ export default class CreditCardNumber extends React.Component {

render() {
/* eslint-disable no-unused-vars */
const { className, onChange, types, value, ...inputProps } = this.props;
const { className, onChange, type, types, value, ...inputProps } = this.props;

const type = this.getType(value);
const ccType = this.getType(value);

return (
<InputGroup className={className}>
Expand All @@ -68,7 +70,7 @@ export default class CreditCardNumber extends React.Component {
/>
<InputGroupAddon className="p-0 px-2">
<Icon
name={typeToIconName(type)}
name={typeToIconName(ccType)}
fixedWidth
size="lg"
/>
Expand Down
2 changes: 1 addition & 1 deletion src/components/FormRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ const FormRow = props => {
id={id}
size={size}
state={rowColor}
type={type}
type={typeof type === 'string' ? type : null}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Used ternary to avoid type="false"

children={React.Children.map(children, child => React.cloneElement(child, { type }))}
{...attributes}
{...childFeedback}
Expand Down
6 changes: 6 additions & 0 deletions test/components/CreditCardNumber.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,10 @@ describe('<CreditCardNumber />', () => {
sinon.assert.calledWith(onChange, cardNumber, undefined);
});
});

it('should remain type="text"', () => {
const component = mount(<CreditCardNumber type="wth" />);
const input = component.find('Input');
assert.equal(input.prop('type'), 'text');
});
});
4 changes: 3 additions & 1 deletion test/components/FormRow.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,9 @@ describe('<FormRow />', () => {
);

it('should render custom input', () => {
assert.equal(component.find(Custom).length, 1);
const custom = component.find(Custom);
assert.equal(custom.length, 1);
assert.equal(custom.first().prop('type'), null);
});
});

Expand Down