Add maxLength attribute to Input (#7744)

This commit is contained in:
delesseps 2017-09-27 11:56:30 +10:00 committed by 偏右
parent 7bfe6878dd
commit 2730344ff7
3 changed files with 50 additions and 0 deletions

View File

@ -27,6 +27,7 @@ export interface InputProps extends AbstractInputProps {
id?: number | string;
name?: string;
size?: 'large' | 'default' | 'small';
maxLength?: string;
disabled?: boolean;
readOnly?: boolean;
addonBefore?: React.ReactNode;
@ -62,6 +63,7 @@ export default class Input extends Component<InputProps, any> {
PropTypes.number,
]),
size: PropTypes.oneOf(['small', 'default', 'large']),
maxLength: PropTypes.string,
disabled: PropTypes.bool,
value: PropTypes.any,
defaultValue: PropTypes.any,

View File

@ -1,5 +1,22 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Input should support maxLength 1`] = `
<Input
disabled={false}
maxLength="3"
prefixCls="ant-input"
type="text"
>
<input
className="ant-input"
disabled={false}
maxLength="3"
onKeyDown={[Function]}
type="text"
/>
</Input>
`;
exports[`TextArea should support disabled 1`] = `
<TextArea
disabled={true}
@ -14,3 +31,18 @@ exports[`TextArea should support disabled 1`] = `
/>
</TextArea>
`;
exports[`TextArea should support maxLength 1`] = `
<TextArea
maxLength="10"
prefixCls="ant-input"
>
<textarea
className="ant-input"
maxLength="10"
onChange={[Function]}
onKeyDown={[Function]}
style={Object {}}
/>
</TextArea>
`;

View File

@ -7,6 +7,15 @@ const { TextArea } = Input;
const delay = timeout => new Promise(resolve => setTimeout(resolve, timeout));
describe('Input', () => {
it('should support maxLength', async () => {
const wrapper = mount(
<Input maxLength="3" />
);
expect(wrapper).toMatchSnapshot();
});
});
describe('TextArea', () => {
it('should auto calculate height according to content length', async () => {
const wrapper = mount(
@ -27,6 +36,13 @@ describe('TextArea', () => {
);
expect(wrapper).toMatchSnapshot();
});
it('should support maxLength', async () => {
const wrapper = mount(
<TextArea maxLength="10" />
);
expect(wrapper).toMatchSnapshot();
});
});
describe('As Form Control', () => {