Skip to content

Commit

Permalink
Merge pull request #12078 from primefaces/issue-12077
Browse files Browse the repository at this point in the history
Fixed #12077 - InputNumber | Support highlight on focus property
  • Loading branch information
cetincakiroglu authored Oct 21, 2022
2 parents 78258f1 + 7406c14 commit 939faf5
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 @@ -574,4 +574,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
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,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 @@ -865,7 +866,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 939faf5

Please sign in to comment.