ratchet icon indicating copy to clipboard operation
ratchet copied to clipboard

Toggle class does not maintain active state when inside control-content class

Open CoinDev opened this issue 10 years ago • 3 comments

Toggle does not maintain active state when inside control-content class. Specifically if you cycle through the tabs created from multiple control-content class tabs the toggle state is not preserved or set to off when in a active (on) position.

CoinDev avatar Apr 11 '14 14:04 CoinDev

+1

keviniamburg avatar Nov 10 '14 20:11 keviniamburg

I figured out the reason for this. In segmented-controllers.js when a new tab is being displayed, it's removing the class "active" throughout. It's removing the .active class from the toggles as well. I changed the segmented-controllers related tab class to "activeTab" instead, and modified the CSS as well. This solved the problem for me.

keviniamburg avatar Nov 10 '14 22:11 keviniamburg

As @slickdev mentioned, the issue lies in lines 55-59 of segmented-controls.js:

activeBodies = targetBody.parentNode.querySelectorAll(classSelector);

for (var i = 0; i < activeBodies.length; i++) {
    activeBodies[i].classList.remove(className);
}

targetBody.parentNode in this case is the wrapper div, i.e. .content or .control-content, and if the segmented controls are in that same div, then the active class is removed from them as well (undesirably).

I simply scoped the activeBodies query to active .control-content:

activeBodies = targetBody.parentNode.querySelectorAll('.control-content' + classSelector);

brianlittmann avatar Jul 24 '15 16:07 brianlittmann