Skip to content

Commit 0793be7

Browse files
authored
Merge pull request #3723 from AlchemyCMS/backport/8.1-stable/pr-3715
[8.1-stable] Add touch support to the admin menubar
2 parents 95c1f1d + 34b1e0a commit 0793be7

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

app/views/alchemy/_menubar.html.erb

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535
}
3636

3737
.menubar:hover,
38-
.menubar:focus-within {
38+
.menubar:focus-within,
39+
.menubar.is-open {
3940
left: 0;
4041
}
4142

@@ -121,9 +122,32 @@
121122
}
122123

123124
connectedCallback() {
124-
const bar = this.shadowRoot.querySelector(".menubar")
125-
const width = bar.offsetWidth
126-
bar.style = `--panel-width: ${width}px; --left-offset: calc(var(--icon-size) + 32px);`
125+
const width = this.bar.offsetWidth
126+
this.bar.style = `--panel-width: ${width}px; --left-offset: calc(var(--icon-size) + 32px);`
127+
this.bar.addEventListener("touchstart", this, { passive: false })
128+
document.addEventListener("touchstart", this, { passive: true })
129+
}
130+
131+
handleEvent(event) {
132+
// click on menubar
133+
if (event.currentTarget === this.bar) {
134+
if (!this.bar.classList.contains("is-open")) {
135+
event.preventDefault()
136+
this.bar.classList.add("is-open")
137+
}
138+
// click outside of menubar
139+
} else if (!event.composedPath().includes(this.bar)) {
140+
this.bar.classList.remove("is-open")
141+
}
142+
}
143+
144+
disconnectedCallback() {
145+
this.bar.removeEventListener("touchstart", this)
146+
document.removeEventListener("touchstart", this)
147+
}
148+
149+
get bar() {
150+
return this.shadowRoot.querySelector(".menubar")
127151
}
128152
}
129153

0 commit comments

Comments
 (0)