Skip to content

Commit 7022f42

Browse files
committed
Use css :placeholder-shown for input clearable
1 parent d868562 commit 7022f42

File tree

3 files changed

+10
-16
lines changed

3 files changed

+10
-16
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
## [Unreleased]
2+
- Use css :placeholder-shown for input clearable
23

34
## 1.1.13 - 2025-03-16
45
- Small refactor on transitions

lib/generators/css_zero/add/templates/app/assets/stylesheets/input_concerns.css

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88
background-size: cover;
99
}
1010

11-
.input--clearable ::-webkit-search-cancel-button {
12-
display: none;
11+
.input--clearable {
12+
input::-webkit-search-cancel-button {
13+
display: none;
14+
}
15+
16+
&:has(:placeholder-shown) > button {
17+
display: none;
18+
}
1319
}
Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,10 @@
11
import { Controller } from "@hotwired/stimulus"
22

33
export default class extends Controller {
4-
static targets = [ "input", "button" ]
5-
6-
connect() {
7-
this.update()
8-
}
4+
static targets = [ "input" ]
95

106
clear() {
117
this.inputTarget.value = ""
128
this.inputTarget.focus()
13-
this.update()
14-
}
15-
16-
update() {
17-
this.buttonTarget.hidden = this.#isEmpty
18-
}
19-
20-
get #isEmpty() {
21-
return this.inputTarget.value === ""
229
}
2310
}

0 commit comments

Comments
 (0)