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
3 changes: 1 addition & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
"@materialr/ripple": "^0.1.1",
"classnames": "^2.2.5",
"prop-types": "^15.6.1",
"react": "^16.2.0"
"react": "^16.2.0",
"uuid": "^3.2.1"
},
"devDependencies": {
"babel-cli": "^6.26.0",
Expand Down
5 changes: 3 additions & 2 deletions src/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import rippleFoundation from '@materialr/ripple';
import classnames from 'classnames';
import PropTypes from 'prop-types';
import React from 'react';
import uuidv1 from 'uuid/v1';

import '@material/checkbox/mdc-checkbox.scss';

Expand All @@ -16,7 +17,7 @@ class Checkbox extends React.Component {
this.elementInput = undefined;
this.elementRoot = undefined;
this.rippleFoundation = undefined;
this.state = { classNames: [], classNamesRipple: [], cssVariables: {} };
this.state = { classNames: [], classNamesRipple: [], cssVariables: {}, id: uuidv1() };
this.checkboxCreate = this.checkboxCreate.bind(this);
this.checkboxDestroy = this.checkboxDestroy.bind(this);
this.getClassNames = this.getClassNames.bind(this);
Expand Down Expand Up @@ -126,7 +127,7 @@ class Checkbox extends React.Component {
rippleActivate,
rippleDeactivate,
} = this;
const id = new Date().getTime().toString();
const { id } = this.state;
return (
<Wrapper
alignEnd={alignEnd}
Expand Down
10 changes: 10 additions & 0 deletions src/index.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ test('Renders extra classNames that are passed in', () => {
expect(actual).toBe(expected);
});

test('<Checkbox /> > Generates a unique id for each component', () => {
const wrapperFirst = mount(<Checkbox name={NAME} />);
const wrapperSecond = mount(<Checkbox name={NAME} />);

const actualIdFirst = wrapperFirst.find('.mdc-checkbox__native-control').props().id;
const actualIdsecond = wrapperSecond.find('.mdc-checkbox__native-control').props().id;

expect(actualIdFirst).not.toBe(actualIdsecond);
});

test('Does not add a ripple when it is disabled', () => {
const wrapper = mount(<Checkbox name={NAME} />, { disableLifecycleMethods: true });
const expected = undefined;
Expand Down