-
Notifications
You must be signed in to change notification settings - Fork 61
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
Feature improve: When mouse move on an option item, it should become the current selected option item. #125
Comments
Isn't that just changing the background with CSS on hover? |
@cmer @afcapel The stimulus-autocomplete example keeps the wrong SolutionAdd
Add
|
I think I was able to solve this with the following custom stimulus controller, which inherits stimulus-autocomplete: import { Autocomplete } from 'stimulus-autocomplete'
const optionSelector = "[role='option']:not([aria-disabled])"
export default class extends Autocomplete {
connect() {
super.connect()
this.resultsTarget.addEventListener('mouseover', this.onResultsMouseOver)
}
disconnect() {
super.disconnect()
if (this.hasResultsTarget) {
this.resultsTarget.removeEventListener('mouseover', this.onResultsMouseOver)
}
}
onResultsMouseOver = (event) => {
if (!(event.target instanceof Element)) return
const selected = event.target.closest(optionSelector)
if (selected) this.select(selected)
}
} |
This does not work for me. What exactly should change? Nothing changes. Could you share your HTML? |
See github top left search box for example.
The text was updated successfully, but these errors were encountered: