I have a custom directive that utilizes ui-select. I am trying to apply a css class to my directive when the ui-select inside of it gets focus and remove it on blur. ui-select does not have focus or blur event listeners, so I would like to add my own. I add the event listeners in the link function of my directive, but when I open my app in Chrome and use the developer tools to see the event listeners on this element, mine are not there. I have tried to research this issue, but I haven't been able to find anything similar. Any help would be much appreciated!
My directive's html:
<div class="floating-ui-select-container">
<div class="floating-ui-select" ng-model="vm.value" ng-class="{active: vm.focus}">
<div class="floating-label no-highlight" ng-class="{active: vm.focus}">
{{vm.floatingLabel}}
</div>
<ui-select on-select="vm.onSelection({item: $item})">
<ui-select-match placeholder="">{{$select.selected.name}}</ui-select-match>
<ui-select-choices repeat="item in vm.menuItems | filter: $select.search">
<span>{{item.name}}</span>
</ui-select-choices>
</ui-select>
</div>
</div>
My directive's link function: (controller.hasFocus and controller.lostFocus just toggle a boolean)
function link(scope, element, attrs, controller) {
var selectDiv = document.querySelector("div.floating-ui-select-container > div.floating-ui-select");
var selectObject = document.querySelector("div.ui-select-container > div.ui-select-match > span.ui-select-toggle");
selectObject.addEventListener("focus", controller.hasFocus, true);
selectObject.addEventListener("blur", controller.lostFocus, true);
}
Note: I use the query selector twice because I could never get it to find the ui-select-toggle with one query. Also, the elements in the second query are found in the html that ui-select inserts.