Files
n8n-enterprise-unlocked/packages/editor-ui/src/components/ExpandableInput/ExpandableInputEdit.vue
Alex Grozav 9c94050deb feat: Replace Vue.extend with defineComponent in editor-ui (no-changelog) (#6033)
* refactor: replace Vue.extend with defineComponent in editor-ui

* fix: change $externalHooks extractions from mixins

* fix: refactor externalHooks mixin
2023-04-21 18:51:08 +03:00

69 lines
1.5 KiB
Vue

<template>
<ExpandableInputBase :value="value" :placeholder="placeholder">
<input
class="el-input__inner"
:value="value"
:placeholder="placeholder"
:maxlength="maxlength"
@input="onInput"
@keydown.enter="onEnter"
@keydown.esc="onEscape"
ref="input"
size="4"
v-click-outside="onClickOutside"
/>
</ExpandableInputBase>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import ExpandableInputBase from './ExpandableInputBase.vue';
import type { PropType } from 'vue';
import type { EventBus } from '@/event-bus';
export default defineComponent({
components: { ExpandableInputBase },
name: 'ExpandableInputEdit',
props: {
value: {},
placeholder: {},
maxlength: {},
autofocus: {},
eventBus: {
type: Object as PropType<EventBus>,
},
},
mounted() {
// autofocus on input element is not reliable
if (this.autofocus && this.$refs.input) {
this.focus();
}
this.eventBus?.on('focus', this.focus);
},
destroyed() {
this.eventBus?.off('focus', this.focus);
},
methods: {
focus() {
if (this.$refs.input) {
(this.$refs.input as HTMLInputElement).focus();
}
},
onInput() {
this.$emit('input', (this.$refs.input as HTMLInputElement).value);
},
onEnter() {
this.$emit('enter', (this.$refs.input as HTMLInputElement).value);
},
onClickOutside(e: Event) {
if (e.type === 'click') {
this.$emit('blur', (this.$refs.input as HTMLInputElement).value);
}
},
onEscape() {
this.$emit('esc');
},
},
});
</script>