Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Unable to select Custom Checkbox

Unable to Check/Un-check custom checkbox.

CodeSandbox: https://codesandbox.io/s/stupefied-silence-f5emkf?file=/src/App.tsx

Explanation: On commenting out dispaly:none I can view, check, uncheck the blue checkbox. But the custom Checkbox cannot be checked or unchecked.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

enter image description here

This is the expected output where the blue checkbox is not displayed. However having problem to check or uncheck the custom checkboxes. Your help is appreciated. Thank you.

enter image description here

>Solution :

Like you already did with the input type checkbox for the onChange event, you should include the click event handler also for the labels performing the same action:

  • onClick={handleSelectAll} on the first label
  • onClick={() => onClickDOP(day)} on the other labels
    suggestionsListComponent = (
        <ul>
            <li>
            <Checkbox checked={selectAll} onChange={handleSelectAll} />
            <label
                className="custom-checkbox-label"
                onClick={handleSelectAll}>  <--------
                All
            </label>
            </li>
            {filteredSuggestions.map((day: any, index: any) => {
            return (
                <li key={day.id}>
                <input
                    type="checkbox"
                    className=""
                    name={day?.name}
                    value={day?.name}
                    checked={day.active}
                    onChange={() => onClickDOP(day)}
                />
                <label
                    className="custom-checkbox-label"
                    onClick={() => onClickDOP(day)}  <--------
                >
                    {day?.name}
                </label>
                </li>
            );
            })}
        </ul>
    );
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading