feat(ui): [WIP] #2390 confirm pill edit with comma
This commit is contained in:
parent
7df1cdfeee
commit
465b8682f5
|
@ -3,22 +3,30 @@ import { ref, onMounted } from 'vue'
|
||||||
import { type ColorProps, type PastelProps, type VariantProps, type RaisedProps, color } from '~/composables/color'
|
import { type ColorProps, type PastelProps, type VariantProps, type RaisedProps, color } from '~/composables/color'
|
||||||
|
|
||||||
|
|
||||||
const input = ref();
|
const input = ref<HTMLInputElement>();
|
||||||
const emit = defineEmits<{
|
const emit = defineEmits<{
|
||||||
click: [event: MouseEvent]
|
click: [event: MouseEvent]
|
||||||
}>()
|
}>()
|
||||||
const handleClick = (event: MouseEvent) => {
|
const handleClick = (event: MouseEvent) => {
|
||||||
emit('click', event);
|
emit('click', event);
|
||||||
if (model.value !== undefined) {
|
if (model.value !== undefined) {
|
||||||
(input.value as HTMLInputElement).focus();
|
input.value?.focus();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const props = defineProps<{ noUnderline?:true, autofocus? : boolean } & (PastelProps | ColorProps) & VariantProps & RaisedProps>()
|
const props = defineProps<{ noUnderline?:true, autofocus? : boolean } & (PastelProps | ColorProps) & VariantProps & RaisedProps>()
|
||||||
const model = defineModel<string>()
|
const model = defineModel<string>()
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
if (props.autofocus) input.value.focus();
|
if (props.autofocus) input.value?.focus();
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const sanitize = () =>
|
||||||
|
model.value = model.value?.replace(',', '')?.trim()
|
||||||
|
|
||||||
|
const sanitizeAndBlur = () =>
|
||||||
|
sanitize() && input.value?.blur()
|
||||||
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
@ -37,8 +45,10 @@ onMounted(() => {
|
||||||
v-if="model !== undefined"
|
v-if="model !== undefined"
|
||||||
ref="input"
|
ref="input"
|
||||||
class="pill-content"
|
class="pill-content"
|
||||||
@keydown.enter="(e) => (e.target as HTMLInputElement).blur()"
|
@keydown.enter.prevent="sanitizeAndBlur"
|
||||||
@blur="(e) => model = (e.target as HTMLInputElement).innerText.trim()"
|
@keyup.space.prevent="sanitizeAndBlur"
|
||||||
|
@keyup.,.prevent="sanitizeAndBlur"
|
||||||
|
@blur="sanitize"
|
||||||
>
|
>
|
||||||
{{ model }}
|
{{ model }}
|
||||||
</span>
|
</span>
|
||||||
|
|
Loading…
Reference in New Issue