Skip to content

Commit 3e4e971

Browse files
committed
feat(Radio): support name props for Radio & customer tagName for Group
1 parent 18c48f4 commit 3e4e971

File tree

4 files changed

+52
-3
lines changed

4 files changed

+52
-3
lines changed

src/radio/radio-group.jsx

+8-2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ class RadioGroup extends Component {
3939
* radio group的默认值
4040
*/
4141
defaultValue: PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.bool]),
42+
/**
43+
* 设置标签类型
44+
*/
45+
component: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
4246
/**
4347
* 选中值改变时的事件
4448
* @param {String/Number} value 选中项的值
@@ -85,6 +89,7 @@ class RadioGroup extends Component {
8589
onChange: () => {
8690
},
8791
prefix: 'next-',
92+
component: 'div',
8893
itemDirection: 'hoz',
8994
}
9095

@@ -140,7 +145,7 @@ class RadioGroup extends Component {
140145
}
141146

142147
render() {
143-
const { rtl, className, shape, size, style, prefix, itemDirection } = this.props;
148+
const { rtl, className, shape, size, style, prefix, itemDirection, component } = this.props;
144149
const others = pickOthers(Object.keys(RadioGroup.propTypes), this.props);
145150
const disabled = this.props.disabled;
146151

@@ -184,7 +189,8 @@ class RadioGroup extends Component {
184189
disabled
185190
});
186191

187-
return <div {...others} aria-disabled={disabled} role="radiogroup" className={cls} style={style}>{children}</div>;
192+
const TagName = component;
193+
return <TagName {...others} aria-disabled={disabled} role="radiogroup" className={cls} style={style}>{children}</TagName>;
188194
}
189195
}
190196

src/radio/radio.jsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ class Radio extends UIState {
152152

153153
render() {
154154
/* eslint-disable no-unused-vars */
155-
const { id, className, children, style, label, onMouseEnter, onMouseLeave, tabIndex, rtl,
155+
const { id, className, children, style, label, onMouseEnter, onMouseLeave, tabIndex, rtl, name,
156156
...otherProps } = this.props;
157157
const checked = !!this.state.checked;
158158
const disabled = this.disabled;
@@ -165,6 +165,7 @@ class Radio extends UIState {
165165

166166
let input = (<input
167167
{...obj.pickOthers(othersData, others)}
168+
name={name}
168169
id={id}
169170
disabled={disabled}
170171
checked={checked}

test/radio/group-spec.js

+38
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,44 @@ describe('Radio.Group', () => {
150150
assert(Math.abs(container.querySelector('.next-radio-wrapper').getBoundingClientRect().height - 40) < 0.0001);
151151
});
152152
});
153+
154+
describe('default tagName', () => {
155+
let wrapper;
156+
const container = document.createElement('div');
157+
container.style.visibility = 'hidden';
158+
document.body.appendChild(container);
159+
before((done) => {
160+
ReactDOM.render(
161+
<RadioGroup shape="button" size="large" defaultValue={'apple'} dataSource={list} />,
162+
container,
163+
function init() {
164+
done();
165+
}
166+
);
167+
});
168+
it('should be div', () => {
169+
assert(container.querySelector('div.next-radio-group'));
170+
});
171+
});
172+
173+
describe('customer tagName', () => {
174+
let wrapper;
175+
const container = document.createElement('div');
176+
container.style.visibility = 'hidden';
177+
document.body.appendChild(container);
178+
before((done) => {
179+
ReactDOM.render(
180+
<RadioGroup component="footer" shape="button" size="large" defaultValue={'apple'} dataSource={list} />,
181+
container,
182+
function init() {
183+
done();
184+
}
185+
);
186+
});
187+
it('should be footer', () => {
188+
assert(container.querySelector('footer.next-radio-group'));
189+
});
190+
});
153191
});
154192

155193
describe('[events] simulate change', () => {

test/radio/index-spec.js

+4
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ describe('Radio', () => {
3232
const wrapper = mount(<Radio className="custom-name" />);
3333
assert(wrapper.find('.next-radio-wrapper.custom-name').length === 1);
3434
});
35+
it('should support name', () => {
36+
const wrapper = mount(<Radio name="customer" />);
37+
assert(wrapper.find('input[name="customer"]').length === 1);
38+
});
3539
});
3640

3741
describe('behavior', () => {

0 commit comments

Comments
 (0)