question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

bug: In React, IonSearchbar can't be given focus with JS

See original GitHub issue

Bug Report

Ionic version:

[x] 5.0.2

Current behavior:

The IonSearchbar component has a documented function for setting focus setFocus, but it doesn’t seem to work. Calling it does not produce a change in the current focus.

Expected behavior:

Calling setFocus on the searchbar should focus the element and bring the cursor into it.

Steps to reproduce:

See below for the linked repo containing a reproduction of the problem. Basically, all I’m doing is adding a searchbar, getting a ref to it, and then calling setFocus on the ref once it’s resolved. I have found that even if I inspect the element in the browser, set a variable to it in the console, and then call setFocus on that variable it does not work.

Related code:

I have a sample repo to show the problem here:

https://github.com/aub/ionic-searchbar-focus-problems

The only thing I changed in here after creating the app with ionic start focus-problems --type=react --capacitor was to add the searchbar and its setup in the ExploreContainer. I have verified that the console logging is being produced and setFocus is being called on the searchbar.

insert short code snippets here

Other information:

Ionic info:

Ionic:

   Ionic CLI       : 5.4.13 (/usr/local/lib/node_modules/ionic)
   Ionic Framework : @ionic/react 5.0.2

Capacitor:

   Capacitor CLI   : 1.5.0
   @capacitor/core : 1.5.0

Utility:

   cordova-res : not installed
   native-run  : not installed

System:

   NodeJS : v13.8.0 (/usr/local/Cellar/node/13.8.0/bin/node)
   npm    : 6.13.7
   OS     : macOS Catalina

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
aubcommented, Feb 26, 2020

Grrr, it’s also working for me now. If you don’t mind, give me a few minutes to figure out what happened here and then if I still can’t reproduce it I’ll close this issue. Sorry about that, thanks for your time.

1reaction
aubcommented, Feb 26, 2020

Whoops, sorry I should have included that. This is on the desktop in Chrome.

Read more comments on GitHub >

github_iconTop Results From Across the Web

bug: In React, IonSearchbar can't be given focus with JS ...
Basically, all I'm doing is adding a searchbar, getting a ref to it, and then calling setFocus on the ref once it's resolved....
Read more >
How can I focus on my searchbar when I enter a tab?
Hello. I am trying to focus on my searchbar when I open the third tab (tab3) of my app. I would like the...
Read more >
In React ES6, why does the input field lose focus after typing a ...
I was using a key from a text field. Inside the same block; I had an input field to update the value of...
Read more >
Create a React Native search bar from scratch - LogRocket Blog
Learn how to create your own React Native search bar from scratch in this detailed, step-by-step tutorial.
Read more >
signature=4c44794979d36c3b2c6e1161877175aa,ionic-framework ...
react : redirect routes should unmount leaving component, fixes #22022 (#22029) ... overlays: prevent focus from being stolen when presenting another overlay ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found