2021-05-29 11:31:21 -07:00
|
|
|
<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"
|
2021-06-30 00:17:30 -07:00
|
|
|
v-click-outside="onClickOutside"
|
2021-05-29 11:31:21 -07:00
|
|
|
/>
|
|
|
|
</ExpandableInputBase>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2023-04-21 08:51:08 -07:00
|
|
|
import { defineComponent } from 'vue';
|
2022-12-14 01:04:10 -08:00
|
|
|
import ExpandableInputBase from './ExpandableInputBase.vue';
|
2023-04-21 08:51:08 -07:00
|
|
|
import type { PropType } from 'vue';
|
|
|
|
import type { EventBus } from '@/event-bus';
|
2021-05-29 11:31:21 -07:00
|
|
|
|
2023-04-21 08:51:08 -07:00
|
|
|
export default defineComponent({
|
2022-12-14 01:04:10 -08:00
|
|
|
name: 'ExpandableInputEdit',
|
2023-05-16 02:43:46 -07:00
|
|
|
components: { ExpandableInputBase },
|
2023-04-06 06:32:45 -07:00
|
|
|
props: {
|
|
|
|
value: {},
|
|
|
|
placeholder: {},
|
|
|
|
maxlength: {},
|
|
|
|
autofocus: {},
|
|
|
|
eventBus: {
|
|
|
|
type: Object as PropType<EventBus>,
|
|
|
|
},
|
|
|
|
},
|
2021-05-29 11:31:21 -07:00
|
|
|
mounted() {
|
|
|
|
// autofocus on input element is not reliable
|
2023-04-07 03:21:17 -07:00
|
|
|
if (this.autofocus && this.$refs.input) {
|
2021-05-29 11:31:21 -07:00
|
|
|
this.focus();
|
|
|
|
}
|
2023-04-20 03:26:14 -07:00
|
|
|
this.eventBus?.on('focus', this.focus);
|
|
|
|
},
|
|
|
|
destroyed() {
|
|
|
|
this.eventBus?.off('focus', this.focus);
|
2021-05-29 11:31:21 -07:00
|
|
|
},
|
|
|
|
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);
|
|
|
|
},
|
2021-06-30 00:17:30 -07:00
|
|
|
onClickOutside(e: Event) {
|
|
|
|
if (e.type === 'click') {
|
|
|
|
this.$emit('blur', (this.$refs.input as HTMLInputElement).value);
|
|
|
|
}
|
2021-05-29 11:31:21 -07:00
|
|
|
},
|
|
|
|
onEscape() {
|
|
|
|
this.$emit('esc');
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
</script>
|