Files
fizzy/app/javascript/controllers/search_form_controller.js
T
2026-03-02 14:21:32 +01:00

18 lines
395 B
JavaScript

import { Controller } from "@hotwired/stimulus"
export default class extends Controller {
static targets = ["searchInput"]
clearInput() {
this.dispatch("clear", { detail: { isAlreadyEmpty: this.isEmpty } })
if (!this.isEmpty) {
this.searchInputTarget.value = ""
this.searchInputTarget.focus()
}
}
get isEmpty() {
return !this.searchInputTarget.value
}
}