@@ -2132,9 +2132,9 @@ exports[`Storyshots Tabs basic usage 1`] = `
@@ -2143,9 +2143,9 @@ exports[`Storyshots Tabs basic usage 1`] = `
@@ -2161,17 +2161,17 @@ exports[`Storyshots Textarea minimal usage 1`] = `
className="form-group"
>
@@ -2199,17 +2199,17 @@ exports[`Storyshots Textarea scrollable 1`] = `
className="form-group"
>
@@ -2237,17 +2237,17 @@ exports[`Storyshots Textarea validation 1`] = `
className="form-group"
>
The unique name that identifies you throughout the site.
diff --git a/src/InputText/InputText.test.jsx b/src/InputText/InputText.test.jsx
new file mode 100644
index 0000000000..747c2fbaa0
--- /dev/null
+++ b/src/InputText/InputText.test.jsx
@@ -0,0 +1,48 @@
+import React from 'react';
+import { mount } from 'enzyme';
+
+import InputText from './index';
+
+describe('
', () => {
+ const label = 'label';
+ const name = 'name';
+ const props = {
+ label,
+ name,
+ };
+
+ describe('rendering', () => {
+ it('should render with default type when type is not defined', () => {
+ const wrapper = mount(
);
+ expect(wrapper.find('input')).toHaveLength(1);
+
+ const input = wrapper.find('input').at(0);
+ expect(input.prop('type')).toEqual('text');
+ });
+
+ it('should render with default type when type is defined as undefined', () => {
+ const wrapper = mount(
);
+ expect(wrapper.find('input')).toHaveLength(1);
+
+ const input = wrapper.find('input').at(0);
+ expect(input.prop('type')).toEqual('text');
+ });
+
+ it('should render with default type when type is defined as null', () => {
+ const wrapper = mount(
);
+ expect(wrapper.find('input')).toHaveLength(1);
+
+ const input = wrapper.find('input').at(0);
+ expect(input.prop('type')).toEqual('text');
+ });
+
+ it('should render with specified type when type is defined', () => {
+ const type = 'foobar';
+ const wrapper = mount(
);
+ expect(wrapper.find('input')).toHaveLength(1);
+
+ const input = wrapper.find('input').at(0);
+ expect(input.prop('type')).toEqual(type);
+ });
+ });
+});
diff --git a/src/InputText/index.jsx b/src/InputText/index.jsx
index 40b0c1187a..a08ef5bb30 100644
--- a/src/InputText/index.jsx
+++ b/src/InputText/index.jsx
@@ -1,7 +1,9 @@
import React from 'react';
import classNames from 'classnames';
+import PropTypes from 'prop-types';
-import asInput, { inputProps } from '../asInput';
+
+import asInput, { inputProps, defaultProps } from '../asInput';
function Text(props) {
return (
@@ -24,7 +26,22 @@ function Text(props) {
);
}
-Text.propTypes = inputProps;
+const textPropTypes = {
+ type: PropTypes.string,
+ describedBy: PropTypes.string,
+ isValid: PropTypes.bool,
+ inputRef: PropTypes.func,
+};
+
+const textDefaultProps = {
+ type: 'text',
+ describedBy: '',
+ isValid: true,
+ inputRef: () => {},
+};
+
+Text.propTypes = { ...textPropTypes, ...inputProps };
+Text.defaultProps = { ...textDefaultProps, ...defaultProps };
const InputText = asInput(Text);
diff --git a/src/asInput/index.jsx b/src/asInput/index.jsx
index 53a507a496..05d2421569 100644
--- a/src/asInput/index.jsx
+++ b/src/asInput/index.jsx
@@ -28,6 +28,19 @@ export const inputProps = {
themes: PropTypes.arrayOf(PropTypes.string),
};
+export const defaultProps = {
+ onChange: () => {},
+ onBlur: () => {},
+ id: newId('asInput'),
+ value: '',
+ description: undefined,
+ disabled: false,
+ required: false,
+ validator: undefined,
+ className: [],
+ themes: [],
+};
+
const asInput = (WrappedComponent, labelFirst = true) => {
class NewComponent extends React.Component {
constructor(props) {
@@ -162,18 +175,7 @@ const asInput = (WrappedComponent, labelFirst = true) => {
NewComponent.propTypes = inputProps;
- NewComponent.defaultProps = {
- onChange: () => {},
- onBlur: () => {},
- id: newId('asInput'),
- value: '',
- description: undefined,
- disabled: false,
- required: false,
- validator: undefined,
- className: [],
- themes: [],
- };
+ NewComponent.defaultProps = defaultProps;
return NewComponent;
};