JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.2/angular.min.js"></script>
<div ng-app="pippo" ng-controller="pippoctrl">
<button ng-click="showme=!showme;shouldBeOpen=!shouldBeOpen">SHOW/HIDE</button>
<div class="wrapper">
<p ng-hide="showme">It will appear here!</p>
<input focus-me="shouldBeOpen" ng-show="showme" type="text" name="s" placeholder="Search..." />
</div>
</div>
CSS
h2, a, p, *:before,h1 {
font-family: "Helvetica Neue", sans-serif;
font-weight: 300;
}
p {
display: block;
width: 100%;
color: #2c3e50;
clear: both;
}
button {
border: 0;
background-color: #3498db;
color: white;
border-radius: 4px;
padding: 5px 10px;
transition: background-color 0.2s ease-out;
cursor: pointer;
}
button:hover {
background-color: #2980b9;
}
button:active, button:hover {
outline: none;
}
a {
color: #2c3e50;
transition: color 0.2s ease-out;
/*padding: 5px 10px;*/
margin-right: 16px;
}
a:hover {
color: #2ecc71;
}
.wrapper {
border: 1px dashed #95a5a6;
height: 56px;
margin-top: 16px;
border-radius: 4px;
position: relative;
font-size: 12px;
}
.wrapper p {
line-height: 31px;
}
JavaScript
var app=angular.module("pippo",[]);
app.controller('pippoctrl', ['$scope',function ($scope){
$scope.shouldBeOpen=false;
}]);
app.directive('focusMe', ['$timeout' , function ($timeout) {
return {
//scope: true, // optionally create a child scope
link: function (scope, element, attrs) {
console.log('focus-me=', attrs.focusMe);
scope.$watch(attrs.focusMe,function(value){
console.log('value=', value);
if (value === true) {
$timeout(function () {
element[0].focus();
});
}
});
}
};
}]);