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