2020-08-06 20:26:45 -05:00
|
|
|
<template>
|
|
|
|
<div class="field">
|
|
|
|
<div class="control">
|
|
|
|
<input type="text" class="input" :placeholder="placeholder" :value="text === null ? '' : text" @input="userUpdateText($event.target.value)">
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
2024-10-01 09:32:09 -05:00
|
|
|
<script setup>
|
2020-08-06 20:26:45 -05:00
|
|
|
|
2024-10-01 09:32:09 -05:00
|
|
|
import { ref } from "vue";
|
2020-08-06 20:26:45 -05:00
|
|
|
import debounce from "lodash/debounce";
|
|
|
|
|
2024-10-01 09:32:09 -05:00
|
|
|
const emit = defineEmits(["update:modelValue"]);
|
2020-08-06 20:26:45 -05:00
|
|
|
|
2024-10-01 09:32:09 -05:00
|
|
|
const props = defineProps({
|
|
|
|
placeholder: {
|
|
|
|
required: false,
|
|
|
|
type: String,
|
|
|
|
default: ""
|
2020-08-06 20:26:45 -05:00
|
|
|
},
|
|
|
|
|
2024-10-01 09:32:09 -05:00
|
|
|
modelValue: {
|
|
|
|
required: false,
|
|
|
|
type: String,
|
|
|
|
default: ""
|
|
|
|
}
|
|
|
|
});
|
2020-08-06 20:26:45 -05:00
|
|
|
|
2024-10-01 09:32:09 -05:00
|
|
|
const text = ref(null);
|
2020-08-06 20:26:45 -05:00
|
|
|
|
2024-10-01 09:32:09 -05:00
|
|
|
const triggerInput = debounce(function() {
|
|
|
|
emit("update:modelValue", text.value);
|
2020-08-06 20:26:45 -05:00
|
|
|
},
|
2024-10-01 09:32:09 -05:00
|
|
|
250,
|
|
|
|
{ leading: false, trailing: true })
|
2020-08-06 20:26:45 -05:00
|
|
|
|
2024-10-01 09:32:09 -05:00
|
|
|
function userUpdateText(newText) {
|
|
|
|
if (text.value !== newText) {
|
|
|
|
text.value = newText;
|
|
|
|
triggerInput();
|
|
|
|
}
|
|
|
|
}
|
2020-08-06 20:26:45 -05:00
|
|
|
|
2024-10-01 09:32:09 -05:00
|
|
|
function propUpdateText(newText) {
|
|
|
|
if (text.value === null && text.value !== newText) {
|
|
|
|
text.value = newText;
|
2020-08-06 20:26:45 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
</script>
|