Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Optionally chain the setCaretPosition element focus #819

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Triggs125
Copy link

Describe the issue/change

We are using a custom input component which utilizes increment/decrement buttons to add/subtract a set step to the value. When either button is clicked on the element which is passed to the setCaretPosition function does not have a focus function so it errors out (see screenshot below) and therefore never calls the onValueChange function with the updated value.

Describe the changes proposed/implemented in this PR

Add optional chaining to the focus function call inside the setCaretPosition function.

Screenshot (If applicable)

Screen Shot 2023-12-29 at 2 54 00 PM

Please check which browsers were used for testing

  • Chrome
  • Chrome (Android)
  • Safari (OSX)
  • Safari (iOS)
  • Firefox
  • Firefox (Android)

@@ -235,7 +235,7 @@ export function setCaretPosition(el: HTMLInputElement, caretPos: number) {
}

// fail city, fortunately this never happens (as far as I've tested) :)
el.focus();
el.focus?.();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q: What is the element type coming here. This function expects the element type to be input. Can you share more details on how the custom input is implemented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants