I'm trying to do something like below i.e I've an input with suggestions dropdown , there are only 2 values in this Male and Female If i type M the remaining letters ale shows highlighted in input and by clicking on it or pressing tab it gets autopopulate vice versa for female Is there any library for it ?
I've tried below code but it doesn't show any highlighted text for obvious reason and autopopulate whenever used type M or F , the problem is it doesn't let me erase the values due to such conditions below
ps. I'm attaching an image for reference of what I want , its a feature in gmail search gmail search feature
if (name === 'patient_gender') {
if (input.toLowerCase().startsWith('m')) {
input = 'Male';
} else if (input.toLowerCase().startsWith('f')) {
input = 'Female';
}
}
It's a touch tricky and it looks like google uses 2 input boxes, does some z-index'ing switches, and then a few other things like capturing right arrow/tab to autocomplete and such.
I have a very rough demo and the code is posted here for posterity. You'll have to fill in the missing parts, but hopefully this gives you a start.
Sandbox link
Basic CSS