From 3e4e971a2039de6af17a0a08cd2eb1fd49901c15 Mon Sep 17 00:00:00 2001 From: "mingbo.zmb" Date: Mon, 7 Jan 2019 16:54:27 +0800 Subject: [PATCH 1/2] feat(Radio): support name props for Radio & customer tagName for Group --- src/radio/radio-group.jsx | 10 ++++++++-- src/radio/radio.jsx | 3 ++- test/radio/group-spec.js | 38 ++++++++++++++++++++++++++++++++++++++ test/radio/index-spec.js | 4 ++++ 4 files changed, 52 insertions(+), 3 deletions(-) diff --git a/src/radio/radio-group.jsx b/src/radio/radio-group.jsx index abaf214932..b6b578c5e1 100644 --- a/src/radio/radio-group.jsx +++ b/src/radio/radio-group.jsx @@ -39,6 +39,10 @@ class RadioGroup extends Component { * radio group的默认值 */ defaultValue: PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.bool]), + /** + * 设置标签类型 + */ + component: PropTypes.oneOfType([PropTypes.string, PropTypes.func]), /** * 选中值改变时的事件 * @param {String/Number} value 选中项的值 @@ -85,6 +89,7 @@ class RadioGroup extends Component { onChange: () => { }, prefix: 'next-', + component: 'div', itemDirection: 'hoz', } @@ -140,7 +145,7 @@ class RadioGroup extends Component { } render() { - const { rtl, className, shape, size, style, prefix, itemDirection } = this.props; + const { rtl, className, shape, size, style, prefix, itemDirection, component } = this.props; const others = pickOthers(Object.keys(RadioGroup.propTypes), this.props); const disabled = this.props.disabled; @@ -184,7 +189,8 @@ class RadioGroup extends Component { disabled }); - return
{children}
; + const TagName = component; + return {children}; } } diff --git a/src/radio/radio.jsx b/src/radio/radio.jsx index b17bee3638..6afd87caba 100644 --- a/src/radio/radio.jsx +++ b/src/radio/radio.jsx @@ -152,7 +152,7 @@ class Radio extends UIState { render() { /* eslint-disable no-unused-vars */ - const { id, className, children, style, label, onMouseEnter, onMouseLeave, tabIndex, rtl, + const { id, className, children, style, label, onMouseEnter, onMouseLeave, tabIndex, rtl, name, ...otherProps } = this.props; const checked = !!this.state.checked; const disabled = this.disabled; @@ -165,6 +165,7 @@ class Radio extends UIState { let input = ( { assert(Math.abs(container.querySelector('.next-radio-wrapper').getBoundingClientRect().height - 40) < 0.0001); }); }); + + describe('default tagName', () => { + let wrapper; + const container = document.createElement('div'); + container.style.visibility = 'hidden'; + document.body.appendChild(container); + before((done) => { + ReactDOM.render( + , + container, + function init() { + done(); + } + ); + }); + it('should be div', () => { + assert(container.querySelector('div.next-radio-group')); + }); + }); + + describe('customer tagName', () => { + let wrapper; + const container = document.createElement('div'); + container.style.visibility = 'hidden'; + document.body.appendChild(container); + before((done) => { + ReactDOM.render( + , + container, + function init() { + done(); + } + ); + }); + it('should be footer', () => { + assert(container.querySelector('footer.next-radio-group')); + }); + }); }); describe('[events] simulate change', () => { diff --git a/test/radio/index-spec.js b/test/radio/index-spec.js index 80d6015760..0d51992a40 100644 --- a/test/radio/index-spec.js +++ b/test/radio/index-spec.js @@ -32,6 +32,10 @@ describe('Radio', () => { const wrapper = mount(); assert(wrapper.find('.next-radio-wrapper.custom-name').length === 1); }); + it('should support name', () => { + const wrapper = mount(); + assert(wrapper.find('input[name="customer"]').length === 1); + }); }); describe('behavior', () => { From 3a80fe71f2700346c877f75a8736cc4acc15553b Mon Sep 17 00:00:00 2001 From: "mingbo.zmb" Date: Tue, 8 Jan 2019 20:39:19 +0800 Subject: [PATCH 2/2] chore(Radio): add tagName case --- test/radio/group-spec.js | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/test/radio/group-spec.js b/test/radio/group-spec.js index 0c430b5e5d..aed1c631c0 100644 --- a/test/radio/group-spec.js +++ b/test/radio/group-spec.js @@ -170,7 +170,7 @@ describe('Radio.Group', () => { }); }); - describe('customer tagName', () => { + describe('customer tagName(String)', () => { let wrapper; const container = document.createElement('div'); container.style.visibility = 'hidden'; @@ -188,6 +188,26 @@ describe('Radio.Group', () => { assert(container.querySelector('footer.next-radio-group')); }); }); + + describe('customer tagName(Func)', () => { + let wrapper; + const container = document.createElement('div'); + container.style.visibility = 'hidden'; + document.body.appendChild(container); + const Footer = props =>
+ before((done) => { + ReactDOM.render( + , + container, + function init() { + done(); + } + ); + }); + it('should be special-name', () => { + assert(container.querySelector('.special-name')); + }); + }); }); describe('[events] simulate change', () => {