grafana/public/app/angular/autofill_event_fix.ts
Torkel Ödegaard 27f66a6df9
Angular: Move coreModule to app/angular and isolate angular usage more (#41433)
* moving coreModule to app/angular and isolating it more

* fixed ts issue
2021-11-09 08:37:16 +01:00

36 lines
1.0 KiB
TypeScript

import coreModule from './core_module';
/** @ngInject */
export function autofillEventFix($compile: any) {
return {
link: ($scope: any, elem: any) => {
const input = elem[0];
const dispatchChangeEvent = () => {
const event = new Event('change');
return input.dispatchEvent(event);
};
const onAnimationStart = ({ animationName }: AnimationEvent) => {
switch (animationName) {
case 'onAutoFillStart':
return dispatchChangeEvent();
case 'onAutoFillCancel':
return dispatchChangeEvent();
}
return null;
};
// const onChange = (evt: Event) => console.log(evt);
input.addEventListener('animationstart', onAnimationStart);
// input.addEventListener('change', onChange);
$scope.$on('$destroy', () => {
input.removeEventListener('animationstart', onAnimationStart);
// input.removeEventListener('change', onChange);
});
},
};
}
coreModule.directive('autofillEventFix', autofillEventFix);