[SalesForce] Show/Hide CSS Ignored When Inside an SLDS Grid Column

I'm just trying to get a simple show/hide experiment running using the code below. It runs fine when the code is outside the SLDS grid. However when I place the div inside a grid column, the console log "test" is displayed but the div remains visible. Am I missing something?? ..Thanks

Component

<aura:component >    
    <lightning:button label="Toggle" onclick="{!c.doInit}"/> 
    <div class="slds-grid">
        <div class="slds-col">
            <div class="slds-box">
                <div aura:id="detailDiv" >
                    <c:ShowHideCmpFilter Message="Detail"/>   
                </div>
            </div>
        </div>        
    </div> 
<aura:component >

CSS

.THIS.toggle {
    display: none;
}

Controller

({
    doInit : function(component, event, helper) {
        console.log("test");        
        var toggleText = component.find("detailDiv");        
        $A.util.toggleClass(toggleText, "toggle");        
    }
})

Best Answer

Without a space in your CSS, .THIS.some-class refers only to top-level elements. To specify child elements, there needs to be a space:

.THIS .toggle {
    display: none;
}

This will correctly toggle the contents as you expect.

Related Topic