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.

Highlight (goTo) the first item on each keystroke

See original GitHub issue

How can I highlight (goTo) to the first item in the results on each keystroke?

I tried with this, but this will work only on the first keystroke, when result box is opened.

document.querySelector("#autoselect").addEventListener("open", function (event) {
    autoSelect.goTo(0);
});    

Is there an event which will fire on earch refresh of the results?

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
folknorcommented, Jun 8, 2021

You should be able to use config.resultsList.element. It’s invoked by autoComplete.js every time the list is updated, right before it’s opened.

I’ve not tested it, but seems to me it should work.

const autoSelect = new autoComplete({
	data: {
		src: ...,
	},
	resultsList: {
		element: (element, data) => {
			//const { input, query, matches, results } = data
			autoSelect.goTo(0)
		}
	},
})
1reaction
mileusnacommented, Jun 8, 2021

@TarekRaafat thank you for quick response

I have tried that already but it looks like the results event is fired when the results are ready, not after they are displayed, so it doesn’t work out of the box.

However, I have managed to achieve what I want with small delay in results event using setTimeout, but I would appreciate some straight forward solution, if there is any.

document.querySelector("#autoselect").addEventListener("results", function (event) {
   setTimeout(() => {  autoSelect.goTo(0); }, 100);
});  
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Highlight or Select Text - Computer Hope
Press and hold your primary mouse button (commonly the left button). While holding the mouse button, drag the cursor to the end of...
Read more >
7 Keyboard Shortcuts for Selecting Cells and Ranges in Excel
Learn keyboard shortcuts that will help make navigating your worksheet, selecting cells, and highlighting ranges a better experience.
Read more >
user interface - Jump to listbox item by typing first few characters
The only way I can think to do this is to derive from CListBox, capture the keystrokes myself, find the item, run a...
Read more >
Keyboard shortcuts in Word - Microsoft Support
Select the first or last cell in the row, and then press Shift+Alt+End or Home. Select the whole table. Alt+5 on the numeric...
Read more >
Keyboard Shortcuts - Millersville University
Instead of an SAP icon button, you can use a keyboard shortcut. A keyboard shortcut is a ... Select the first item; click...
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