Move id generator into constrcutor

pull/21833/head
Jorik Schellekens 2020-06-01 12:04:47 +01:00
parent 66c0d53f3e
commit 9e9bcb4974
1 changed files with 4 additions and 3 deletions

View File

@ -26,6 +26,7 @@ interface IState {
}
export default class StyledCheckbox extends React.PureComponent<IProps, IState> {
private id: string;
public static readonly defaultProps = {
className: "",
@ -33,16 +34,16 @@ export default class StyledCheckbox extends React.PureComponent<IProps, IState>
constructor(props: IProps) {
super(props);
this.id = "checkbox_" + randomString(10);
}
public render() {
const { children, className, ...otherProps } = this.props;
// 56^10 so unlikely chance of collision.
const id = "checkbox_" + randomString(10);
return [
<span className={"mx_Checkbox " + className}>
<input id={id} {...otherProps} type="checkbox" />
<label htmlFor={id}>
<input id={this.id} {...otherProps} type="checkbox" />
<label htmlFor={this.id}>
{/* Using the div to center the image */}
<div className="mx_Checkbox_background">
<img src={CHECK_BOX_SVG}/>