use :has selectors for search input

This commit is contained in:
Pete Matsyburka
2026-07-23 11:13:10 +03:00
parent 48d595ca81
commit d05e125fa9
10 changed files with 26 additions and 57 deletions
-31
View File
@@ -1,18 +1,5 @@
export default class extends HTMLElement {
connectedCallback () {
this.input.addEventListener('focus', () => {
if (this.title) {
this.titleContainer.classList.add('max-md:hidden')
}
})
this.input.addEventListener('blur', (e) => {
if (this.title && !e.target.value) {
this.title.classList.remove('hidden')
this.titleContainer.classList.remove('max-md:hidden')
}
})
this.button.addEventListener('click', (event) => {
if (!this.input.value && document.activeElement !== this.input) {
event.preventDefault()
@@ -30,30 +17,12 @@ export default class extends HTMLElement {
onBeforeCache = () => {
this.input.value = this.input.getAttribute('value') || ''
if (this.title) {
this.titleContainer.classList.remove('max-md:hidden')
}
}
get input () {
return this.querySelector('input')
}
get title () {
return document.querySelector(this.dataset.title)
}
get titleContainer () {
const parent = this.title.parentElement
if (parent && !parent.contains(this)) {
return parent
}
return this.title
}
get button () {
return this.querySelector('button')
}