mirror of
https://github.com/grafana/grafana.git
synced 2025-08-01 21:12:13 +08:00
fix: Manually trigger a change-event when autofill is used in webkit-browsers #12133
This commit is contained in:
@ -1,5 +1,6 @@
|
|||||||
import './directives/dash_class';
|
import './directives/dash_class';
|
||||||
import './directives/dropdown_typeahead';
|
import './directives/dropdown_typeahead';
|
||||||
|
import './directives/autofill_event_fix';
|
||||||
import './directives/metric_segment';
|
import './directives/metric_segment';
|
||||||
import './directives/misc';
|
import './directives/misc';
|
||||||
import './directives/ng_model_on_blur';
|
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">
|
<form name="loginForm" class="login-form-group gf-form-group" ng-hide="disableLoginForm">
|
||||||
<div class="login-form">
|
<div class="login-form">
|
||||||
<input type="text" name="username" class="gf-form-input login-form-input" required ng-model='formModel.user' placeholder={{loginHint}}
|
<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>
|
||||||
<div class="login-form">
|
<div class="login-form">
|
||||||
<input type="password" name="password" class="gf-form-input login-form-input" required ng-model="formModel.password" id="inputPassword"
|
<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/angular';
|
||||||
@import 'utils/spacings';
|
@import 'utils/spacings';
|
||||||
@import 'utils/widths';
|
@import 'utils/widths';
|
||||||
|
@import 'utils/hacks';
|
||||||
|
|
||||||
// LAYOUTS
|
// LAYOUTS
|
||||||
@import 'layout/lists';
|
@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;
|
||||||
|
}
|
Reference in New Issue
Block a user