JSFiddle - React, Tailwind, and code Playground

by mqchen

HTML

<!--<ul class="expandable-checkboxlist">
    <li class="expandable-checkboxlist-item">
        <label class="expandable-checkboxlist-label" for="option1">Hello label</label>
        <input type="radio" id="option1" name="a" class="expandable-checkboxlist-input" />
        <div class="expandable-checkboxlist-full">
            <div class="expandable-checkboxlist-text">
                <p>Hello world</p>
            </div>
        </div>
    </li>
    <li class="expandable-checkboxlist-item">
        <label class="expandable-checkboxlist-label" for="option2">Hello label</label>
        <input type="radio" id="option2" name="a" class="expandable-checkboxlist-input" />
        <div class="expandable-checkboxlist-full">
            <div class="expandable-checkboxlist-text">
                <p>Hello world</p>
            </div>
        </div>
    </li>
    <li class="expandable-checkboxlist-item">
        <label class="expandable-checkboxlist-label" for="option3">Hello label</label>
        <input type="radio" id="option3" name="a" class="expandable-checkboxlist-input" />
        <div class="expandable-checkboxlist-full">
            <div class="expandable-checkboxlist-text">
                <p>Hello world</p>
            </div>
        </div>
    </li>
</ul>-->


<ul class="expandable-checkboxlist">
    <li class="expandable-checkboxlist-item">
        <label class="expandable-checkboxlist-label" for="optiona">Norsk</label>
        <input type="checkbox" id="optiona" name="b" class="expandable-checkboxlist-input" />
    </li>
    <li class="expandable-checkboxlist-item">
        <label class="expandable-checkboxlist-label" for="optionb">Samisk</label>
        <input type="checkbox" id="optionb" name="c" class="expandable-checkboxlist-input" />
    </li>
    <li class="expandable-checkboxlist-item">
        <label class="expandable-checkboxlist-label" for="optionc">
            <div class="formline expandable-checkboxlist-formlinelabel">
                <input...

CSS

body, html {
    font-family: Arial, sans-serif;
    font-size: 14px;
}








/**
 * Form elements
 */
.formline {
    display: block;
    position: relative;
    clear: both;
    margin: 0;
    padding-top: 15px;
    padding-bottom: 20px;
    font-size: 12px;
}

/**
 * Input element
 */
/*.formline input:not([type="checkbox"]):not([type="radio"])*/
.formline input {
    display: block;
    /*float: left;*/
    -moz-box-sizing: border-box;
    -webkit-box-sizing: border-box;
    -ms-box-sizing: border-box;
    box-sizing: border-box;
    padding: 7px 10px;
    margin: 0;
    width: 100%;
    min-height: 32px;
    border: 1px solid #dbdbdb;
    -webkit-border-radius: 3px;
    -moz-border-radius: 3px;
    border-radius: 3px;
    -webkit-box-shadow: inset 0px 0px 0px 1px #fff;
    -moz-box-shadow: inset 0px 0px 0px 1px #fff;
    box-shadow: inset 0px 0px 0px 1px #fff;
    background: #f9f9f9; /* Old browsers */
    /* IE9 SVG, needs conditional override of 'filter' to 'none' */
    background: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/Pgo8c3ZnIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgdmlld0JveD0iMCAwIDEgMSIgcHJlc2VydmVBc3BlY3RSYXRpbz0ibm9uZSI+CiAgPGxpbmVhckdyYWRpZW50IGlkPSJncmFkLXVjZ2ctZ2VuZXJhdGVkIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgeDE9IjAlIiB5MT0iMCUiIHgyPSIwJSIgeTI9IjEwMCUiPgogICAgPHN0b3Agb2Zmc2V0PSIwJSIgc3RvcC1jb2xvcj0iI2Y5ZjlmOSIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgICA8c3RvcCBvZmZzZXQ9IjEwMCUiIHN0b3AtY29sb3I9IiNmZmZmZmYiIHN0b3Atb3BhY2l0eT0iMSIvPgogIDwvbGluZWFyR3JhZGllbnQ+CiAgPHJlY3QgeD0iMCIgeT0iMCIgd2lkdGg9IjEiIGhlaWdodD0iMSIgZmlsbD0idXJsKCNncmFkLXVjZ2ctZ2VuZXJhdGVkKSIgLz4KPC9zdmc+);
    background: -moz-linear-gradient(top, #f9f9f9 0%, #ffffff 100%); /* FF3.6+ */
    background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#f9f9f9), color-stop(100%,#ffffff)); /* Chrome,Safari4+ */
    background: -webkit-linear-gradient(top, #f9f9f9 0%,#ffffff 100%); /* Chrome10+,Safari5.1+ */
   ...

JavaScript

var ExpandableCheckboxList = function(list) {
    
    $(".expandable-checkboxlist-label").each(function(index, label) {
        label = $(label);
        var formlinelabel = $(".expandable-checkboxlist-formlinelabel", label);
        if(formlinelabel) {
            var input = $("input, textarea", formlinelabel);
            var checkbox = $("#" + label.attr("for"));
            input.on("focus", function() {
                checkbox.prop("checked", true);
            });
            checkbox.on("change", function() {
                if(checkbox.prop("checked")) {
                    input.focus();
                }
            });
        }
    });
};

$(".expandable-checkboxlist").each(function(index, item) {
    ExpandableCheckboxList(item);
});