fix: lint errors for textarea #48
1 changed files with 22 additions and 19 deletions
|
@ -12,7 +12,7 @@
|
|||
:readonly="readonly"
|
||||
:placeholder="placeholder"
|
||||
:pattern="pattern"
|
||||
:autocomplete="autocomplete"
|
||||
:autocomplete="autocompleteValue"
|
||||
:spellcheck="spellcheck"
|
||||
@focus="focused = true"
|
||||
@blur="focused = false"
|
||||
|
@ -27,7 +27,7 @@
|
|||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { defineComponent, onMounted, onUnmounted, nextTick, ref, watch, computed, toRefs } from 'vue';
|
||||
import { onMounted, nextTick, ref, watch, computed, toRefs } from 'vue';
|
||||
import { debounce } from 'throttle-debounce';
|
||||
import MkButton from '@/components/ui/button.vue';
|
||||
import { i18n } from '@/i18n';
|
||||
|
@ -62,34 +62,38 @@ const props = withDefaults(defineProps<{
|
|||
manualSave: false,
|
||||
});
|
||||
|
||||
const { modelValue, autofocus } = toRefs(props);
|
||||
const { modelValue } = toRefs(props);
|
||||
// modelValue is read only, so a separate ref is needed.
|
||||
const v = $ref(modelValue.value);
|
||||
|
||||
const focused = $ref(false);
|
||||
const changed = $ref(false);
|
||||
const invalid = $ref(false);
|
||||
const filled = computed(() => modelValue.value !== '' && modelValue.value != null);
|
||||
const inputEl = $ref(null);
|
||||
const focused = ref(false);
|
||||
const changed = ref(false);
|
||||
const invalid = ref(false);
|
||||
|
||||
const inputEl = ref<HTMLTextAreaElement | null>(null);
|
||||
const autocompleteValue = computed(() => props.autocomplete ? 'on' : 'off');
|
||||
|
||||
const focus = () => inputEl.focus();
|
||||
const onInput = evt => {
|
||||
changed = true;
|
||||
const focus = (): void => {
|
||||
if (inputEl.value) {
|
||||
inputEl.value.focus();
|
||||
}
|
||||
};
|
||||
const onInput = (evt: any): void => {
|
||||
changed.value = true;
|
||||
emit('change', evt);
|
||||
};
|
||||
const onKeydown = (evt: KeyboardEvent) => {
|
||||
const onKeydown = (evt: KeyboardEvent): void => {
|
||||
emit('keydown', evt);
|
||||
if (evt.code === 'Enter') {
|
||||
emit('enter');
|
||||
}
|
||||
};
|
||||
const updated = () => {
|
||||
changed = false;
|
||||
const updated = (): void => {
|
||||
changed.value = false;
|
||||
emit('update:modelValue', v);
|
||||
};
|
||||
const debouncedUpdated = debounce(1000, updated);
|
||||
|
||||
watch(modelValue, newValue => {
|
||||
watch(modelValue, () => {
|
||||
if (!props.manualSave) {
|
||||
if (props.debounce) {
|
||||
debouncedUpdated();
|
||||
|
@ -98,14 +102,13 @@ watch(modelValue, newValue => {
|
|||
}
|
||||
}
|
||||
|
||||
invalid = inputEl.validity.badInput;
|
||||
invalid.value = inputEl.value?.validity.badInput || true;
|
||||
norm
commented
Not sure if this should default to true or false Not sure if this should default to true or false
Johann150
commented
Either way, using a logical or here is not the right solution. You probably meant to use Since this ref will only be Either way, using a logical or here is not the right solution. You probably meant to use `??` instead.
Since this ref will only be `null` until the element is loaded it should be better to default it to `false`.
|
||||
});
|
||||
|
||||
|
||||
onMounted(() => {
|
||||
nextTick(() => {
|
||||
if (props.autofocus) {
|
||||
inputEl.focus();
|
||||
if (props.autofocus && inputEl.value) {
|
||||
inputEl.value.focus();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue
The contribution guide says to use ref sugar (i.e.
$ref
), which means we can avoid writing.value
everywhere. However I forgot that this means the variable may not beconst
because it will be assigned to. The proper solution should be to uselet
instead ofconst
.