grafana/public/app/angular/give_focus.ts
Tobias Skarhed 5e7df4cf6a
Angular cleanup: Move directives (#35330)
* angular2react: Remove json_editor_ctrl

* angular2react: Move directives

* Add to angular dir
2021-06-08 08:28:56 +02:00

30 lines
649 B
TypeScript

import coreModule from '../core/core_module';
coreModule.directive('giveFocus', () => {
return (scope: any, element: any, attrs: any) => {
element.click((e: any) => {
e.stopPropagation();
});
scope.$watch(
attrs.giveFocus,
(newValue: any) => {
if (!newValue) {
return;
}
setTimeout(() => {
element.focus();
const domEl: any = element[0];
if (domEl.setSelectionRange) {
const pos = element.val().length * 2;
domEl.setSelectionRange(pos, pos);
}
}, 200);
},
true
);
};
});
export default {};