From f38c7bb239b9f830156ad2963567b159c27528b7 Mon Sep 17 00:00:00 2001 From: Amumu Date: Wed, 6 Nov 2019 23:30:41 +0800 Subject: [PATCH] form item passing anyother attrs (#19599) --- components/form/FormItem.tsx | 23 +++++++++++++-- .../__snapshots__/index.test.js.snap | 28 +++++++++++++++++++ components/form/__tests__/index.test.js | 13 ++++++++- 3 files changed, 61 insertions(+), 3 deletions(-) create mode 100644 components/form/__tests__/__snapshots__/index.test.js.snap diff --git a/components/form/FormItem.tsx b/components/form/FormItem.tsx index 9fd362fe52..8474034a76 100644 --- a/components/form/FormItem.tsx +++ b/components/form/FormItem.tsx @@ -3,6 +3,7 @@ import * as ReactDOM from 'react-dom'; import * as PropTypes from 'prop-types'; import classNames from 'classnames'; import Animate from 'rc-animate'; +import omit from 'omit.js'; import Row from '../grid/row'; import Col, { ColProps } from '../grid/col'; import Icon from '../icon'; @@ -400,7 +401,7 @@ export default class FormItem extends React.Component { } renderFormItem = ({ getPrefixCls }: ConfigConsumerProps) => { - const { prefixCls: customizePrefixCls, style, className } = this.props; + const { prefixCls: customizePrefixCls, style, className, ...restProps } = this.props; const prefixCls = getPrefixCls('form', customizePrefixCls); const children = this.renderChildren(prefixCls); const itemClassName = { @@ -410,7 +411,25 @@ export default class FormItem extends React.Component { }; return ( - + {children} ); diff --git a/components/form/__tests__/__snapshots__/index.test.js.snap b/components/form/__tests__/__snapshots__/index.test.js.snap new file mode 100644 index 0000000000..feabd99e53 --- /dev/null +++ b/components/form/__tests__/__snapshots__/index.test.js.snap @@ -0,0 +1,28 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Form Form.Item should support data-*、aria-* and custom attribute 1`] = ` +
+ +
+`; diff --git a/components/form/__tests__/index.test.js b/components/form/__tests__/index.test.js index a4b8adabfd..fe3567c99a 100644 --- a/components/form/__tests__/index.test.js +++ b/components/form/__tests__/index.test.js @@ -1,6 +1,6 @@ /* eslint-disable react/prefer-stateless-function */ import React from 'react'; -import { mount } from 'enzyme'; +import { mount, render } from 'enzyme'; import Form from '..'; import mountTest from '../../../tests/shared/mountTest'; @@ -13,6 +13,17 @@ describe('Form', () => { expect(wrapper.find('form').hasClass('ant-form-hide-required-mark')).toBe(true); }); + it('Form.Item should support data-*、aria-* and custom attribute', () => { + const wrapper = render( +
+ +
, + ); + expect(wrapper).toMatchSnapshot(); + }); + describe('wrappedComponentRef', () => { it('warns on functional component', () => { if (process.env.REACT === '15') {