Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/Checkbox.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,16 @@ export default class Checkbox extends React.Component {
onClick,
onFocus,
onBlur,
...others,
} = this.props;

const globalProps = Object.keys(others).reduce((prev, key) => {
if (key.substr(0, 5) === 'aria-' || key.substr(0, 5) === 'data-' || key === 'role') {
prev[key] = others[key];
}
return prev;
}, {});

const { checked } = this.state;
const classString = classNames(prefixCls, className, {
[`${prefixCls}-checked`]: checked,
Expand All @@ -109,6 +118,7 @@ export default class Checkbox extends React.Component {
onFocus={onFocus}
onBlur={onBlur}
onChange={this.handleChange}
{...globalProps}
/>
<span className={`${prefixCls}-inner`} />
</span>
Expand Down
24 changes: 24 additions & 0 deletions tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,28 @@ describe('rc-checkbox', () => {
TestUtils.scryRenderedDOMComponentsWithTag(inst, 'input')[0].click();
expect(!!inst.state.checked).to.be(true);
});

it('passes data-* props to input', () => {
ReactDOM.render(<Checkbox data-type="my-data-type" />, container, function init() {
inst = this;
});
const renderedInput = TestUtils.scryRenderedDOMComponentsWithTag(inst, 'input')[0];
expect(renderedInput.attributes['data-type'].value).to.equal('my-data-type');
});

it('passes aria-* props to input', () => {
ReactDOM.render(<Checkbox aria-label="my-aria-label" />, container, function init() {
inst = this;
});
const renderedInput = TestUtils.scryRenderedDOMComponentsWithTag(inst, 'input')[0];
expect(renderedInput.attributes['aria-label'].value).to.equal('my-aria-label');
});

it('passes role prop to input', () => {
ReactDOM.render(<Checkbox role="my-role" />, container, function init() {
inst = this;
});
const renderedInput = TestUtils.scryRenderedDOMComponentsWithTag(inst, 'input')[0];
expect(renderedInput.attributes.role.value).to.equal('my-role');
});
});