Skip to content

Commit

Permalink
Merge pull request #211 from edx/alasdair/add-autocomplete-prop-to-in…
Browse files Browse the repository at this point in the history
…put-text

fix(input-text): add autocomplete prop
  • Loading branch information
AlasdairSwan authored Apr 12, 2018
2 parents c2804a4 + a6a45dc commit 13d4563
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
24 changes: 24 additions & 0 deletions .storybook/__snapshots__/Storyshots.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -9298,6 +9298,7 @@ exports[`Storyshots InputText different textual input types 1`] = `
<input
aria-describedby="error-input-search"
aria-invalid={false}
autoComplete="on"
className="form-control"
disabled={false}
id="input-search"
Expand Down Expand Up @@ -9339,6 +9340,7 @@ exports[`Storyshots InputText different textual input types 1`] = `
<input
aria-describedby="error-input-email"
aria-invalid={false}
autoComplete="on"
className="form-control"
disabled={false}
id="input-email"
Expand Down Expand Up @@ -9380,6 +9382,7 @@ exports[`Storyshots InputText different textual input types 1`] = `
<input
aria-describedby="error-input-url"
aria-invalid={false}
autoComplete="on"
className="form-control"
disabled={false}
id="input-url"
Expand Down Expand Up @@ -9421,6 +9424,7 @@ exports[`Storyshots InputText different textual input types 1`] = `
<input
aria-describedby="error-input-tel"
aria-invalid={false}
autoComplete="on"
className="form-control"
disabled={false}
id="input-tel"
Expand Down Expand Up @@ -9462,6 +9466,7 @@ exports[`Storyshots InputText different textual input types 1`] = `
<input
aria-describedby="error-input-password"
aria-invalid={false}
autoComplete="on"
className="form-control"
disabled={false}
id="input-password"
Expand Down Expand Up @@ -9503,6 +9508,7 @@ exports[`Storyshots InputText different textual input types 1`] = `
<input
aria-describedby="error-input-number"
aria-invalid={false}
autoComplete="on"
className="form-control"
disabled={false}
id="input-number"
Expand Down Expand Up @@ -9544,6 +9550,7 @@ exports[`Storyshots InputText different textual input types 1`] = `
<input
aria-describedby="error-input-datetime-local"
aria-invalid={false}
autoComplete="on"
className="form-control"
disabled={false}
id="input-datetime-local"
Expand Down Expand Up @@ -9585,6 +9592,7 @@ exports[`Storyshots InputText different textual input types 1`] = `
<input
aria-describedby="error-input-date"
aria-invalid={false}
autoComplete="on"
className="form-control"
disabled={false}
id="input-date"
Expand Down Expand Up @@ -9626,6 +9634,7 @@ exports[`Storyshots InputText different textual input types 1`] = `
<input
aria-describedby="error-input-month"
aria-invalid={false}
autoComplete="on"
className="form-control"
disabled={false}
id="input-month"
Expand Down Expand Up @@ -9667,6 +9676,7 @@ exports[`Storyshots InputText different textual input types 1`] = `
<input
aria-describedby="error-input-week"
aria-invalid={false}
autoComplete="on"
className="form-control"
disabled={false}
id="input-week"
Expand Down Expand Up @@ -9708,6 +9718,7 @@ exports[`Storyshots InputText different textual input types 1`] = `
<input
aria-describedby="error-input-time"
aria-invalid={false}
autoComplete="on"
className="form-control"
disabled={false}
id="input-time"
Expand Down Expand Up @@ -9749,6 +9760,7 @@ exports[`Storyshots InputText different textual input types 1`] = `
<input
aria-describedby="error-input-color"
aria-invalid={false}
autoComplete="on"
className="form-control"
disabled={false}
id="input-color"
Expand Down Expand Up @@ -9818,6 +9830,7 @@ exports[`Storyshots InputText displayed inline 1`] = `
<input
aria-describedby="error-asInput1"
aria-invalid={false}
autoComplete="on"
className="form-control"
disabled={false}
id="asInput1"
Expand Down Expand Up @@ -9912,6 +9925,7 @@ exports[`Storyshots InputText focus test 1`] = `
<input
aria-describedby="error-data"
aria-invalid={false}
autoComplete="on"
className="form-control"
disabled={false}
id="data"
Expand Down Expand Up @@ -9985,6 +9999,7 @@ exports[`Storyshots InputText label as element 1`] = `
<input
aria-describedby="error-asInput1"
aria-invalid={false}
autoComplete="on"
className="form-control"
disabled={false}
id="asInput1"
Expand Down Expand Up @@ -10053,6 +10068,7 @@ exports[`Storyshots InputText minimal usage 1`] = `
<input
aria-describedby="error-asInput1"
aria-invalid={false}
autoComplete="on"
className="form-control"
disabled={false}
id="asInput1"
Expand Down Expand Up @@ -10121,6 +10137,7 @@ exports[`Storyshots InputText validation 1`] = `
<input
aria-describedby="error-username description-username"
aria-invalid={false}
autoComplete="on"
className="form-control"
disabled={false}
id="username"
Expand Down Expand Up @@ -10195,6 +10212,7 @@ exports[`Storyshots InputText validation with danger theme 1`] = `
<input
aria-describedby="error-asInput1 description-asInput1"
aria-invalid={false}
autoComplete="on"
className="form-control"
disabled={false}
id="asInput1"
Expand Down Expand Up @@ -10286,6 +10304,7 @@ exports[`Storyshots InputText with input group addons 1`] = `
<input
aria-describedby="error-asInput1"
aria-invalid={false}
autoComplete="on"
className="form-control"
disabled={false}
id="asInput1"
Expand Down Expand Up @@ -10337,6 +10356,7 @@ exports[`Storyshots InputText with input group addons 1`] = `
<input
aria-describedby="error-asInput1"
aria-invalid={false}
autoComplete="on"
className="form-control"
disabled={false}
id="asInput1"
Expand Down Expand Up @@ -10400,6 +10420,7 @@ exports[`Storyshots InputText with input group addons 1`] = `
<input
aria-describedby="error-asInput1"
aria-invalid={false}
autoComplete="on"
className="form-control"
disabled={false}
id="asInput1"
Expand Down Expand Up @@ -10457,6 +10478,7 @@ exports[`Storyshots InputText with input group addons 1`] = `
<input
aria-describedby="error-asInput1"
aria-invalid={false}
autoComplete="on"
className="form-control"
disabled={false}
id="asInput1"
Expand Down Expand Up @@ -10518,6 +10540,7 @@ exports[`Storyshots InputText with input group addons 1`] = `
<input
aria-describedby="error-asInput1"
aria-invalid={false}
autoComplete="on"
className="form-control"
disabled={false}
id="asInput1"
Expand Down Expand Up @@ -15613,6 +15636,7 @@ exports[`Storyshots Modal modal with element body 1`] = `
<input
aria-describedby="error-asInput1"
aria-invalid={false}
autoComplete="on"
className="form-control"
disabled={false}
id="asInput1"
Expand Down
8 changes: 8 additions & 0 deletions src/InputText/InputText.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,13 @@ describe('<InputText />', () => {
const input = wrapper.find('input').at(0);
expect(input.prop('type')).toEqual(type);
});

it('should render with the autocomplete property if set', () => {
const wrapper = mount(<InputText {...props} autoComplete="off" />);
expect(wrapper.find('input')).toHaveLength(1);

const input = wrapper.find('input').at(0);
expect(input.prop('autoComplete')).toEqual('off');
});
});
});
3 changes: 3 additions & 0 deletions src/InputText/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ function Text(props) {
onChange={props.onChange}
onBlur={props.onBlur}
aria-invalid={!props.isValid}
autoComplete={props.autoComplete}
disabled={props.disabled}
required={props.required}
ref={props.inputRef}
Expand All @@ -30,13 +31,15 @@ const textPropTypes = {
type: PropTypes.string,
describedBy: PropTypes.string,
isValid: PropTypes.bool,
autoComplete: PropTypes.string,
inputRef: PropTypes.func,
};

const textDefaultProps = {
type: 'text',
describedBy: '',
isValid: true,
autoComplete: 'on',
inputRef: () => {},
};

Expand Down
3 changes: 3 additions & 0 deletions src/asInput/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Handles all necessary props that are related to Input typed components.

## API

### `autoComplete` (string; optional)
`autoComplete` specifies whether or not an input field should have autocomplete enabled. It allows the browser to predict the value. When a user starts to type in a field, the browser should display options to fill in the field, based on earlier typed values. The default value is 'on'.

### `className` (string array; optional)
`className` specifies Bootstrap class names to apply to the input component. The default is an empty array.

Expand Down

0 comments on commit 13d4563

Please sign in to comment.