Skip to content

Commit

Permalink
Toggle clear icon color
Browse files Browse the repository at this point in the history
  • Loading branch information
mattlindsey committed Dec 7, 2024
1 parent 8614591 commit 5b07ce9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
15 changes: 14 additions & 1 deletion app/javascript/stimulus/search_controller.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { Controller } from "@hotwired/stimulus"

export default class extends Controller {
static targets = [ "input" ]
static targets = [ "input", "clear" ]

connect() {
this.cursorToEnd()
this.setSearchClearIcon()
}

cursorToEnd() {
this.inputTarget.selectionStart =
Expand All @@ -20,4 +25,12 @@ export default class extends Controller {
this.element.requestSubmit()
}, 900)
}

setSearchClearIcon() {
if (this.inputTarget.value.length > 0) {
this.clearTarget.classList.add("text-gray-800")
} else {
this.clearTarget.classList.remove("text-gray-800")
}
}
}
2 changes: 1 addition & 1 deletion app/views/messages/_nav_column.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
variant: :mini,
size: 18,
class: "cursor-pointer absolute right-1 top-1/2 transform -translate-y-1/2",
data: { action: "click->search#clear" }
data: { search_target: "clear", action: "click->search#clear" }
%>
</div>
<% end %>
Expand Down

0 comments on commit 5b07ce9

Please sign in to comment.