Created
September 20, 2018 17:29
-
-
Save allusis/de3f13bb980041ec51452c2ed47532c5 to your computer and use it in GitHub Desktop.
Lightning - Toggle Search and Focus input
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<aura:component implements="forceCommunity:availableForAllPageTypes" access="global"> | |
<div id="search" class="search" aura:id="search"> | |
<form id="search-form" role="search"> | |
<label for="search-query">Search:</label> | |
<input type="text" id="search-query" aura:id="search-query" name="s" value="" /> | |
<button id="search-submit" type="submit">Search</button> | |
</form> | |
</div> | |
<button class="mobile-button" tabindex="-1" id="search-button" aura:id="search-button" onclick="{!c.searchMenuToggle}">Search</button> | |
</aura:component> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
({ | |
searchMenuToggle : function(component, event, helper) { | |
var toggleMenu = component.find("search"); | |
var toggleMenuButton = component.find("search-button"); | |
var toggleSearchFocus = component.find("search-query"); | |
$A.util.toggleClass(toggleMenu, "open"); | |
$A.util.toggleClass(toggleMenuButton, "open"); | |
component.set("v.isOpen",true); | |
helper.focus(component); | |
}, | |
searchMenuHide : function(component, event, helper) { | |
var isToogle = component.get("v.isOpen"); | |
if(!isToogle){ | |
var toggleMenu = component.find("search"); | |
$A.util.removeClass(toggleMenu, "open"); | |
$A.util.removeClass(toggleMenuButton, "open"); | |
} else{ | |
component.set("v.isOpen",false); | |
} | |
}, | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
({ | |
focus : function(component) { | |
var input = component.find("search-query").getElement().focus(); | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment