grafana/public/app/core/directives/give_focus.ts

30 lines
639 B
TypeScript
Raw Normal View History

2017-12-20 05:33:33 -06:00
import coreModule from '../core_module';
2017-12-20 05:33:33 -06:00
coreModule.directive('giveFocus', function() {
return function(scope, element, attrs) {
element.click(function(e) {
e.stopPropagation();
});
scope.$watch(
attrs.giveFocus,
function(newValue) {
if (!newValue) {
return;
}
setTimeout(function() {
element.focus();
2018-08-29 07:26:50 -05:00
const domEl = element[0];
if (domEl.setSelectionRange) {
2018-08-29 07:26:50 -05:00
const pos = element.val().length * 2;
domEl.setSelectionRange(pos, pos);
}
}, 200);
},
true
);
};
});
export default {};