Fix textarea / input trimming to harshly

Fixes #3200
This commit is contained in:
rijkvanzanten
2020-11-27 13:54:39 -05:00
parent 0a2ffaac58
commit eedca7043f
2 changed files with 16 additions and 9 deletions

View File

@@ -133,6 +133,7 @@ export default defineComponent({
...listeners,
input: emitValue,
keydown: processValue,
blur: trimIfEnabled,
}));
const hasClick = computed(() => {
@@ -179,16 +180,18 @@ export default defineComponent({
emit('keydown', event);
}
function trimIfEnabled() {
if (props.value && props.trim) {
emit('input', String(props.value).trim());
}
}
function emitValue(event: InputEvent) {
let value = (event.target as HTMLInputElement).value;
if (props.type === 'number') {
emit('input', Number(value));
} else {
if (props.trim === true) {
value = value.trim();
}
if (props.slug === true) {
const endsWithSpace = value.endsWith(' ');
value = slugify(value, { separator: props.slugSeparator });

View File

@@ -52,13 +52,14 @@ export default defineComponent({
},
trim: {
type: Boolean,
default: true,
default: false,
},
},
setup(props, { emit, listeners }) {
const _listeners = computed(() => ({
...listeners,
input: emitValue,
blur: trimIfEnabled,
}));
const hasContent = computed(() => props.value && props.value.length > 0);
@@ -66,12 +67,15 @@ export default defineComponent({
return { _listeners, hasContent };
function emitValue(event: InputEvent) {
let value = (event.target as HTMLInputElement).value;
if (props.trim === true) {
value = value.trim();
}
const value = (event.target as HTMLInputElement).value;
emit('input', value);
}
function trimIfEnabled() {
if (props.value && props.trim) {
emit('input', props.value.trim());
}
}
},
});
</script>