Vue.component('tt-modal', { props: { show: {type: [Boolean, Object], default: false}, title: {type: String, default: 'Überschrift'}, delete: {type: Boolean, default: true}, deleteText: {type: String, default: 'Löschen'}, save: {type: Boolean, default: true}, saveLoading: {type: Boolean, default: false}, saveText: {type: String, default: 'Speichern'}, disableMinHeight: {type: Boolean, default: false} }, watch: { show(newVal) { if (!newVal) { this.$emit('close') document.documentElement.style.overflow = '' document.documentElement.style.paddingRight = '' } if (newVal) { const scrollbarWidth = window.innerWidth - document.documentElement.clientWidth document.documentElement.style.overflow = 'hidden' document.documentElement.style.paddingRight = scrollbarWidth + 'px' this.$nextTick(() => { const input = this.$refs.modal.querySelector('input') if (input && !input.classList.contains('tt-autocomplete')) input.focus() }) } } }, created() { document.addEventListener('keydown', this.keydownHandler) }, destroyed() { document.removeEventListener('keydown', this.keydownHandler) document.documentElement.style.overflow = '' document.documentElement.style.paddingRight = '' }, methods: { keydownHandler(event) { if (!this.show) return if (event.key === 'Escape') this.$emit('update:show', false) if (event.key === 'Enter' && this.save) { if (event.target.tagName === 'TEXTAREA' || event.target.tagName === 'INPUT') return this.$emit('submit') } } }, data: () => ({ window: window, isMobile: navigator.userAgent.match(/(iPad)|(iPhone)|(iPod)|(android)|(webOS)/i) !== null }), template: ` ` })