Skip to content

Commit

Permalink
Fixed #12077 - InputNumber | Support highlight on focus property
Browse files Browse the repository at this point in the history
  • Loading branch information
cetincakiroglu committed Oct 21, 2022
1 parent 8c9caa8 commit f03fb3d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/app/components/dom/domhandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -604,4 +604,12 @@ export class DomHandler {
this.zindex = this.zindex||999;
return ++this.zindex;
}

public static getSelection() {
if (window.getSelection) return window.getSelection().toString();
else if (document.getSelection) return document.getSelection().toString();
else if (document['selection']) return document['selection'].createRange().text;

return null;
}
}
4 changes: 3 additions & 1 deletion src/app/components/inputnumber/inputnumber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {CommonModule} from '@angular/common';
import {InputTextModule} from 'primeng/inputtext';
import { ButtonModule } from 'primeng/button';
import { NG_VALUE_ACCESSOR, ControlValueAccessor } from '@angular/forms';
import { DomHandler } from '../dom/domhandler';

export const INPUTNUMBER_VALUE_ACCESSOR: any = {
provide: NG_VALUE_ACCESSOR,
Expand Down Expand Up @@ -820,7 +821,8 @@ export class InputNumber implements OnInit,ControlValueAccessor {
}

onInputClick() {
if(!this.readonly) {
const currentValue = this.input.nativeElement.value;
if (!this.readonly && currentValue !== DomHandler.getSelection()) {
this.initCursor();
}
}
Expand Down

0 comments on commit f03fb3d

Please sign in to comment.