Skip to content

Commit 06083f5

Browse files
refactor(Values): Use data-attribute for ignored elements on blur
1 parent 7fc07ff commit 06083f5

File tree

4 files changed

+14
-33
lines changed

4 files changed

+14
-33
lines changed

src/components/core/value-tree/form/ValueTreeArrayForm.vue

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
marginLeft: `${(level + 1) * 16}px`,
77
}"
88
/>
9-
<form v-if="isFormVisible" class="flex shrink-0 items-center font-mono text-sm">
9+
<div v-if="isFormVisible" class="flex shrink-0 items-center font-mono text-sm">
1010
<span class="select-none">
1111
<span class="text-code-navy opacity-50">{{ index }}</span>
1212
<span class="ml-0.5 text-muted-foreground">:</span>
@@ -29,20 +29,14 @@
2929
</span>
3030
</div>
3131
<div class="ml-2 inline-flex shrink-0 items-center gap-x-1">
32-
<Button
33-
:id="`value-save-${index}-${level}`"
34-
ref="saveButton"
35-
size="icon-sm"
36-
variant="secondary"
37-
@click.stop="save"
38-
>
32+
<Button ref="saveButton" data-ignore-blur size="icon-sm" variant="secondary" @click.stop="save">
3933
<Check class="h-3.5 w-3.5" />
4034
</Button>
4135
<Button ref="cancelButton" size="icon-sm" variant="secondary" @click.stop="cancel">
4236
<XIcon class="h-3.5 w-3.5" />
4337
</Button>
4438
</div>
45-
</form>
39+
</div>
4640
<Button v-else size="icon-sm" variant="ghost" @click="showForm">
4741
<Plus class="h-3.5 w-3.5" />
4842
</Button>
@@ -54,7 +48,7 @@ import { computed, nextTick, ref } from 'vue';
5448
import { Check, Plus, XIcon } from 'lucide-vue-next';
5549
import { Button } from '@/components/ui/button';
5650
57-
const props = withDefaults(
51+
withDefaults(
5852
defineProps<{
5953
index?: number;
6054
level?: number;
@@ -116,7 +110,7 @@ const cancel = () => {
116110
};
117111
118112
const onBlur = (e: FocusEvent) => {
119-
if ((e.relatedTarget as HTMLElement)?.id === `value-save-${props.index}-${props.level}`) return;
113+
if ((e.relatedTarget as HTMLElement)?.hasAttribute('data-ignore-blur')) return;
120114
cancel();
121115
};
122116
</script>

src/components/core/value-tree/type/ValueTreeArray.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@ const modelValue = defineModel<any[]>({ required: true });
4040
4141
defineEmits(['delete']);
4242
43-
const onUpdate = (key: string | number, value: any) => {
43+
const onUpdate = (key: number, value: any) => {
4444
const clone = Array.from(modelValue.value as any[]);
4545
// @ts-ignore
4646
clone[key] = value;
4747
modelValue.value = clone;
4848
};
4949
50-
const onDelete = (key: string | number) => {
50+
const onDelete = (key: number) => {
5151
const clone = Array.from(modelValue.value as any[]);
5252
// @ts-ignore
5353
clone.splice(key, 1);

src/components/core/value-tree/type/ValueTreeNumber.vue

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,7 @@
2929
<template #actions>
3030
<!-- Edit -->
3131
<template v-if="isEditing">
32-
<Button
33-
v-if="isValid"
34-
:id="`value-save-${name}-${level}`"
35-
ref="saveButton"
36-
size="icon-sm"
37-
variant="secondary"
38-
@click="save"
39-
>
32+
<Button v-if="isValid" ref="saveButton" data-ignore-blur size="icon-sm" variant="secondary" @click="save">
4033
<Check class="h-3.5 w-3.5" />
4134
</Button>
4235
<span
@@ -68,7 +61,7 @@ import { placeCursorAtEnd } from '@/utils/dom.ts';
6861
6962
const precision = 1000;
7063
71-
const props = withDefaults(
64+
withDefaults(
7265
defineProps<{
7366
name: string;
7467
level?: number;
@@ -139,7 +132,7 @@ const cancel = () => {
139132
};
140133
141134
const onBlur = (e: FocusEvent) => {
142-
if ((e.relatedTarget as HTMLElement)?.id === `value-save-${props.name}-${props.level}`) return;
135+
if ((e.relatedTarget as HTMLElement)?.hasAttribute('data-ignore-blur')) return;
143136
cancel();
144137
};
145138

src/components/core/value-tree/type/ValueTreeString.vue

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,7 @@
3030
<template #actions>
3131
<!-- Edit -->
3232
<template v-if="isEditing">
33-
<Button
34-
:id="`value-save-${name}-${level}`"
35-
ref="saveButton"
36-
size="icon-sm"
37-
variant="secondary"
38-
@click.stop="save"
39-
>
33+
<Button ref="saveButton" data-ignore-blur size="icon-sm" variant="secondary" @click.stop="save">
4034
<Check class="h-3.5 w-3.5" />
4135
</Button>
4236
<Button ref="cancelButton" size="icon-sm" variant="secondary" @click.stop="cancel">
@@ -64,7 +58,7 @@ import { placeCursorAtEnd } from '@/utils/dom.ts';
6458
6559
const colorRegex = new RegExp(/(?:#|0x)(?:[a-f0-9]{3}|[a-f0-9]{6})\b|(?:rgb|hsl)a?\([^)]*\)/, 'i');
6660
67-
const props = withDefaults(
61+
withDefaults(
6862
defineProps<{
6963
name: string;
7064
level?: number;
@@ -110,11 +104,11 @@ const cancel = () => {
110104
};
111105
112106
const onBlur = (e: FocusEvent) => {
113-
if ((e.relatedTarget as HTMLElement)?.id === `value-save-${props.name}-${props.level}`) return;
107+
if ((e.relatedTarget as HTMLElement)?.hasAttribute('data-ignore-blur')) return;
114108
cancel();
115109
};
116110
117-
const onColorInput = (e: InputEvent) => {
111+
const onColorInput = (e: Event) => {
118112
modelValue.value = (e.target as HTMLInputElement).value;
119113
};
120114

0 commit comments

Comments
 (0)