fix: select on focus, wait for value

This commit is contained in:
Mo Bitar
2020-04-21 14:05:11 -05:00
parent 9023f76417
commit 6be8fa93f8
8 changed files with 42 additions and 36 deletions

View File

@@ -0,0 +1,17 @@
/* @ngInject */
export function selectOnFocus($window: ng.IWindowService) {
return {
restrict: 'A',
link: function (scope: ng.IScope, element: JQLite) {
element.on('focus', () => {
if (!$window.getSelection()!.toString()) {
const input = element[0] as HTMLInputElement;
/** Allow text to populate */
setImmediate(() => {
input.setSelectionRange(0, input.value.length);
})
}
});
}
};
}