Skip to content

Commit

Permalink
wraps input field inside a label tag #14
Browse files Browse the repository at this point in the history
  • Loading branch information
FarahZaqout committed Nov 10, 2018
2 parents dbed096 + a89fe70 commit 1a3d889
Showing 1 changed file with 37 additions and 9 deletions.
46 changes: 37 additions & 9 deletions client/src/components/common/InputField/index.jsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,50 @@
import React from 'react';
import React, { Fragment } from 'react';
import PropTypes from 'prop-types';

// this line disables the windows end of line check for eslint.
/* eslint linebreak-style: ["error", "windows"] */
// declares propTypes validation.
const propTypes = {
type: PropTypes.string.isRequired,
name: PropTypes.string.isRequired,
value: PropTypes.string,
placeholder: PropTypes.string,
className: PropTypes.string.isRequired,
onChange: PropTypes.func,
onClick: PropTypes.func,
id: PropTypes.string,
labelValue: PropTypes.string,
};

const Input = props => {
const { type, name, value, placeholder, className } = props;
const {
id,
labelValue,
type,
name,
value,
placeholder,
className,
onChange,
onClick,
} = props;

return (
<input
type={type}
placeholder={placeholder}
name={name}
value={value}
className={className}
/>
<Fragment>
<label htmlFor={id}>
{labelValue}
<input
id={id}
type={type}
placeholder={placeholder}
name={name}
value={value}
className={className}
onChange={onChange}
onClick={onClick}
/>
</label>
</Fragment>
);
};

Expand All @@ -31,6 +55,10 @@ Input.propTypes = propTypes;
Input.defaultProps = {
value: null,
placeholder: null,
onChange: null,
onClick: null,
id: null,
labelValue: null,
};

export default Input;

0 comments on commit 1a3d889

Please sign in to comment.