Skip to content
Advertisement

Search input loses focus when it doesn’t find any title

Whenever I try to search, I can type only the letters which are similar to the one of the titles. If any letter is different I lose focus from input. It used to work normally before, but Idk what happened now. Any suggestions?

How it first looks like:

After starting to type on search input:

When I type a letter which is not in the title:

Code:

JavaScript

Advertisement

Answer

What I think happens is, your “default” return form the beginning gets reset by the return in the “if else”. So the Input is a new DOM Element and loses focus.

You might want to add something like this to your default return and remove your “if else” statement.

JavaScript

What does this do? It adds the “No files found” message to your default return and shows it only, if items is empty.

But i am pretty sure, there is a better way to do this.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement