From 2730344ff7992026994e45cfa842c1d145ab1dd8 Mon Sep 17 00:00:00 2001 From: delesseps Date: Wed, 27 Sep 2017 11:56:30 +1000 Subject: [PATCH] Add maxLength attribute to Input (#7744) --- components/input/Input.tsx | 2 ++ .../__snapshots__/index.test.js.snap | 32 +++++++++++++++++++ components/input/__tests__/index.test.js | 16 ++++++++++ 3 files changed, 50 insertions(+) diff --git a/components/input/Input.tsx b/components/input/Input.tsx index d38e9a4557..63b25a65a5 100644 --- a/components/input/Input.tsx +++ b/components/input/Input.tsx @@ -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 { PropTypes.number, ]), size: PropTypes.oneOf(['small', 'default', 'large']), + maxLength: PropTypes.string, disabled: PropTypes.bool, value: PropTypes.any, defaultValue: PropTypes.any, diff --git a/components/input/__tests__/__snapshots__/index.test.js.snap b/components/input/__tests__/__snapshots__/index.test.js.snap index a76cf07eca..79cd35dde6 100644 --- a/components/input/__tests__/__snapshots__/index.test.js.snap +++ b/components/input/__tests__/__snapshots__/index.test.js.snap @@ -1,5 +1,22 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`Input should support maxLength 1`] = ` + + + +`; + exports[`TextArea should support disabled 1`] = ` `; + +exports[`TextArea should support maxLength 1`] = ` + +`; diff --git a/components/input/__tests__/index.test.js b/components/input/__tests__/index.test.js index 4836405430..52e4367583 100644 --- a/components/input/__tests__/index.test.js +++ b/components/input/__tests__/index.test.js @@ -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( + + ); + 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( +