Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
OvidijusParsiunas committed Sep 29, 2024
1 parent aae265a commit 0bf5449
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions component/src/views/chat/input/textInput/focusUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {TextInputEl} from './textInput';

export class FocusUtils {
public static focusEndOfInput(inputElement: HTMLElement) {
if (Browser.IS_SAFARI) inputElement.focus(); // can only focus the start of the input in Safari
const range = document.createRange(); // create a new Range object
range.selectNodeContents(inputElement); // set the Range object to contain the contents of the contentEditable div
range.collapse(false); // collapse the Range object to the end of the contents
Expand All @@ -13,7 +12,10 @@ export class FocusUtils {
}

public static focusFromParentElement(parentElement: HTMLElement) {
const inputElement = parentElement.querySelector(`#${TextInputEl.TEXT_INPUT_ID}`);
if (inputElement) FocusUtils.focusEndOfInput(inputElement as HTMLElement);
const inputElement = parentElement.querySelector(`#${TextInputEl.TEXT_INPUT_ID}`) as HTMLElement;
if (inputElement) {
if (Browser.IS_SAFARI) inputElement.focus(); // can only focus the start of the input in Safari
FocusUtils.focusEndOfInput(inputElement);
}
}
}

0 comments on commit 0bf5449

Please sign in to comment.