parsley/app/javascript/components/AppSearchText.vue

40 lines
840 B
Vue
Raw Normal View History

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
2026-04-20 13:46:42 -05:00
import { ref, watch } from "vue";
2020-08-06 20:26:45 -05:00
import debounce from "lodash/debounce";
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
2026-04-20 13:46:42 -05:00
const model = defineModel({ type: String, default: null });
const text = ref(model.value);
watch(model, (val) => { text.value = val; });
2020-08-06 20:26:45 -05:00
2024-10-01 09:32:09 -05:00
const triggerInput = debounce(function() {
2026-04-20 13:46:42 -05:00
model.value = text.value;
2020-08-06 20:26:45 -05:00
},
2024-10-01 09:32:09 -05:00
250,
2026-04-20 13:46:42 -05:00
{ 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
</script>