forked from FoundKeyGang/FoundKey
fix lints from refactoring
closes FoundKeyGang/FoundKey#48 Co-authored-by: Francis Dinh <normandy@biribiri.dev>
This commit is contained in:
parent
15ac0fb303
commit
a752dcab30
1 changed files with 20 additions and 17 deletions
|
@ -12,7 +12,7 @@
|
||||||
:readonly="readonly"
|
:readonly="readonly"
|
||||||
:placeholder="placeholder"
|
:placeholder="placeholder"
|
||||||
:pattern="pattern"
|
:pattern="pattern"
|
||||||
:autocomplete="autocomplete"
|
:autocomplete="autocomplete ? 'on' : 'off'"
|
||||||
:spellcheck="spellcheck"
|
:spellcheck="spellcheck"
|
||||||
@focus="focused = true"
|
@focus="focused = true"
|
||||||
@blur="focused = false"
|
@blur="focused = false"
|
||||||
|
@ -62,34 +62,40 @@ const props = withDefaults(defineProps<{
|
||||||
manualSave: false,
|
manualSave: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
const { modelValue, autofocus } = toRefs(props);
|
const { modelValue } = toRefs(props);
|
||||||
// modelValue is read only, so a separate ref is needed.
|
// modelValue is read only, so a separate ref is needed.
|
||||||
const v = $ref(modelValue.value);
|
const v = $ref(modelValue.value);
|
||||||
|
|
||||||
const focused = $ref(false);
|
let focused = $ref(false);
|
||||||
const changed = $ref(false);
|
let changed = $ref(false);
|
||||||
const invalid = $ref(false);
|
let invalid = $ref(false);
|
||||||
const filled = computed(() => modelValue.value !== '' && modelValue.value != null);
|
let inputEl: HTMLTextAreaElement | null = $ref(null);
|
||||||
const inputEl = $ref(null);
|
|
||||||
|
|
||||||
const focus = () => inputEl.focus();
|
const filled = computed(() => modelValue.value !== '' && modelValue.value != null);
|
||||||
const onInput = evt => {
|
|
||||||
|
const focus = (): void => {
|
||||||
|
inputEl?.focus();
|
||||||
|
};
|
||||||
|
|
||||||
|
const onInput = (evt: HTMLInputEvent): void => {
|
||||||
changed = true;
|
changed = true;
|
||||||
emit('change', evt);
|
emit('change', evt);
|
||||||
};
|
};
|
||||||
const onKeydown = (evt: KeyboardEvent) => {
|
|
||||||
|
const onKeydown = (evt: KeyboardEvent): void => {
|
||||||
emit('keydown', evt);
|
emit('keydown', evt);
|
||||||
if (evt.code === 'Enter') {
|
if (evt.code === 'Enter') {
|
||||||
emit('enter');
|
emit('enter');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const updated = () => {
|
|
||||||
|
const updated = (): void => {
|
||||||
changed = false;
|
changed = false;
|
||||||
emit('update:modelValue', v);
|
emit('update:modelValue', v);
|
||||||
};
|
};
|
||||||
const debouncedUpdated = debounce(1000, updated);
|
const debouncedUpdated = debounce(1000, updated);
|
||||||
|
|
||||||
watch(modelValue, newValue => {
|
watch(modelValue, () => {
|
||||||
if (!props.manualSave) {
|
if (!props.manualSave) {
|
||||||
if (props.debounce) {
|
if (props.debounce) {
|
||||||
debouncedUpdated();
|
debouncedUpdated();
|
||||||
|
@ -98,15 +104,12 @@ watch(modelValue, newValue => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
invalid = inputEl.validity.badInput;
|
invalid = inputEl?.validity.badInput ?? false;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
nextTick(() => {
|
nextTick(() => {
|
||||||
if (props.autofocus) {
|
if (props.autofocus) focus();
|
||||||
inputEl.focus();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Reference in a new issue