mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
fix: Manually trigger a change-event when autofill is used in webkit-browsers #12133
This commit is contained in:
parent
cc8b450799
commit
a558e76a68
@ -1,5 +1,6 @@
|
||||
import './directives/dash_class';
|
||||
import './directives/dropdown_typeahead';
|
||||
import './directives/autofill_event_fix';
|
||||
import './directives/metric_segment';
|
||||
import './directives/misc';
|
||||
import './directives/ng_model_on_blur';
|
||||
|
35
public/app/core/directives/autofill_event_fix.ts
Normal file
35
public/app/core/directives/autofill_event_fix.ts
Normal file
@ -0,0 +1,35 @@
|
||||
import coreModule from '../core_module';
|
||||
|
||||
/** @ngInject */
|
||||
export function autofillEventFix($compile) {
|
||||
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);
|
@ -9,7 +9,7 @@
|
||||
<form name="loginForm" class="login-form-group gf-form-group" ng-hide="disableLoginForm">
|
||||
<div class="login-form">
|
||||
<input type="text" name="username" class="gf-form-input login-form-input" required ng-model='formModel.user' placeholder={{loginHint}}
|
||||
autofocus>
|
||||
autofocus autofill-event-fix>
|
||||
</div>
|
||||
<div class="login-form">
|
||||
<input type="password" name="password" class="gf-form-input login-form-input" required ng-model="formModel.password" id="inputPassword"
|
||||
|
@ -32,6 +32,7 @@
|
||||
@import 'utils/angular';
|
||||
@import 'utils/spacings';
|
||||
@import 'utils/widths';
|
||||
@import 'utils/hacks';
|
||||
|
||||
// LAYOUTS
|
||||
@import 'layout/lists';
|
||||
|
11
public/sass/utils/_hacks.scss
Normal file
11
public/sass/utils/_hacks.scss
Normal file
@ -0,0 +1,11 @@
|
||||
// <3: https://medium.com/@brunn/detecting-autofilled-fields-in-javascript-aed598d25da7
|
||||
// sass-lint:disable no-empty-rulesets
|
||||
@keyframes onAutoFillStart { from {/**/} to {/**/}}
|
||||
@keyframes onAutoFillCancel { from {/**/} to {/**/}}
|
||||
input:-webkit-autofill {
|
||||
animation-name: onAutoFillStart;
|
||||
transition: transform 1ms;
|
||||
}
|
||||
input:not(:-webkit-autofill) {
|
||||
animation-name: onAutoFillCancel;
|
||||
}
|
Loading…
Reference in New Issue
Block a user