Files
docuseal/app/javascript/elements/search_input.js
T

38 lines
858 B
JavaScript
Raw Normal View History

2024-08-14 16:34:30 +03:00
export default class extends HTMLElement {
connectedCallback () {
this.input.addEventListener('focus', () => {
if (this.title) {
this.title.classList.add('hidden', 'md:block')
this.input.classList.add('w-60')
}
})
this.input.addEventListener('blur', (e) => {
if (this.title && !e.target.value) {
this.title.classList.remove('hidden')
this.input.classList.remove('w-60')
}
})
2025-09-24 12:07:54 +03:00
this.button.addEventListener('click', (event) => {
2025-09-25 09:01:04 +03:00
if (!this.input.value && document.activeElement !== this.input) {
event.preventDefault()
2025-09-24 12:07:54 +03:00
2025-09-25 09:01:04 +03:00
this.input.focus()
2025-09-24 12:07:54 +03:00
}
})
2024-08-14 16:34:30 +03:00
}
get input () {
return this.querySelector('input')
}
get title () {
return document.querySelector(this.dataset.title)
}
2025-09-24 12:07:54 +03:00
get button () {
return this.querySelector('button')
}
2024-08-14 16:34:30 +03:00
}