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

[Search] - Click or enter keypress events in order to trigger search requests? #6644

Open
GeorgeKanan opened this issue Oct 24, 2018 · 3 comments

Comments

@GeorgeKanan
Copy link

GeorgeKanan commented Oct 24, 2018

Hi,
When queries are applied to a database it's more efficient to submit Search requests on click or enter keypress events instead of keypress events.
Is it possible to do so?

In this case, I'm considering search suggestions as search results, so that a user would choose one out of them in order to be submitted later with form data.

@natzar
Copy link

natzar commented Nov 17, 2018

Like an attribute called autosubmit=false ?

@GeorgeKanan
Copy link
Author

GeorgeKanan commented Nov 26, 2018

@natzar Yes maybe, and a way to trigger search requests

@timhoffmannGIThub
Copy link

timhoffmannGIThub commented Oct 27, 2019

Hi, bit late to the party, but I thought I might contribute. I kind of stood at the same problem a few months ago. Here's how I've done it:

Let's create two variables via react. One which is basically our search-string and one which sets the former:
const [searchString, setSearchString] = useState("");

Then you'll need an constant, that listens to the enter-key. It'll look something like this:
const listenEnter = e => { if (e.keyCode === 13) { enter(); } };

You can give yourself a response however you seem fit, through console or other:
const enter= () => { console.log("success"); };
This will just give you feedback, you can take it out of course.

After that you will need to rewrite how it the search bar reacts to changes. This is where it'll autosubmit, which means you'll have to rewrite it so it just sets the value of the searchstring. It could look something like this:
const onSearchChange = (e, data) => { setSearchString(e.target.value); };

Now this is important, you'll have to add a onKeyDown attribute in the return, just under the search segement. Of course you'll need to conform it to the grid system and can change it how you'd like to have it displayed. For simplicitys sake let's just write it like this for now:
return ( <Search value={searchString} onSearchChange={onSearchChange} showNoResults={false} input="text" onKeyDown={listenEnter} /> );

And that should be it! I did simplify a lot of corners I guess, but I hope the core idea came out and will serve in later Versions of semanticUI as well.

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

No branches or pull requests

3 participants