Skip to content

Commit

Permalink
v7 fix: Autofill only sets selectionRange when in focus (#25972)
Browse files Browse the repository at this point in the history
  • Loading branch information
smhigley authored Dec 13, 2022
1 parent cbb8529 commit 0bb189f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "fix: Autofill only sets input selectionRange if input is in focus",
"packageName": "office-ui-fabric-react",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,10 @@ export class Autofill extends React.Component<IAutofillProps, IAutofillState> im
return;
}

const isFocused = this._inputElement.current && this._inputElement.current === document.activeElement;

if (
isFocused &&
this._autoFillEnabled &&
value &&
suggestedDisplayValue &&
Expand All @@ -106,17 +109,17 @@ export class Autofill extends React.Component<IAutofillProps, IAutofillState> im
shouldSelectFullRange = shouldSelectFullInputValueInComponentDidUpdate();
}

if (shouldSelectFullRange && this._inputElement.current) {
this._inputElement.current.setSelectionRange(0, suggestedDisplayValue.length, SELECTION_BACKWARD);
if (shouldSelectFullRange) {
this._inputElement.current!.setSelectionRange(0, suggestedDisplayValue.length, SELECTION_BACKWARD);
} else {
while (
differenceIndex < value.length &&
value[differenceIndex].toLocaleLowerCase() === suggestedDisplayValue[differenceIndex].toLocaleLowerCase()
) {
differenceIndex++;
}
if (differenceIndex > 0 && this._inputElement.current) {
this._inputElement.current.setSelectionRange(
if (differenceIndex > 0) {
this._inputElement.current!.setSelectionRange(
differenceIndex,
suggestedDisplayValue.length,
SELECTION_BACKWARD,
Expand Down

0 comments on commit 0bb189f

Please sign in to comment.