Skip to content

Commit c37d7c1

Browse files
committed
fix: Add border styling and refactor
Signed-off-by: Enjeck C. <patrathewhiz@gmail.com>
1 parent d939da7 commit c37d7c1

2 files changed

Lines changed: 48 additions & 14 deletions

File tree

src/shared/components/ncTable/partials/TableCellMultiSelection.vue

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
-->
55
<template>
66
<div class="cell-multi-selection">
7-
<div v-if="!isEditing" class="non-edit-mode" @click="startEditing">
7+
<div v-if="!isEditing" class="non-edit-mode" @click="handleStartEditing">
88
<ul>
99
<li v-for="v in getObjects()" :key="v.id">
1010
{{ v.label }}<span v-if="v.deleted" :title="t('tables', 'This option is outdated.')">&nbsp;⚠️</span>
@@ -66,6 +66,7 @@ export default {
6666
data() {
6767
return {
6868
localEditValues: [],
69+
isInitialEditClick: false,
6970
}
7071
},
7172
@@ -99,23 +100,28 @@ export default {
99100
isEditing(isEditing) {
100101
if (isEditing) {
101102
this.initEditValues()
102-
// Use a small delay to prevent the same click event that triggered editing
103-
// from immediately triggering the click outside handler
104-
// TODO: implement better click outside detection without setTimeout
103+
// Add click outside listener after the current event loop
104+
// to avoid the same click that triggered editing from closing the editor
105105
this.$nextTick(() => {
106-
setTimeout(() => {
107-
document.addEventListener('click', this.handleClickOutside)
108-
}, 100)
106+
document.addEventListener('click', this.handleClickOutside)
109107
})
110108
} else {
111109
document.removeEventListener('click', this.handleClickOutside)
110+
this.isInitialEditClick = false
112111
}
113112
},
114113
},
115114
116115
methods: {
117116
t,
118117
118+
handleStartEditing(event) {
119+
this.isInitialEditClick = true
120+
this.startEditing()
121+
// Stop the event from propagating to avoid immediate click outside
122+
event.stopPropagation()
123+
},
124+
119125
getObjects() {
120126
return this.column.getObjects(this.value)
121127
},
@@ -167,6 +173,12 @@ export default {
167173
},
168174
169175
handleClickOutside(event) {
176+
// Ignore the initial click that started editing
177+
if (this.isInitialEditClick) {
178+
this.isInitialEditClick = false
179+
return
180+
}
181+
170182
// Check if the click is outside the editing container
171183
// But ignore clicks on dropdown options and scrollbars
172184
if (this.$refs.editingContainer && !this.$refs.editingContainer.contains(event.target)) {

src/shared/components/ncTable/partials/TableCellSelection.vue

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
-->
55
<template>
66
<div class="cell-selection">
7-
<div v-if="!isEditing" class="non-edit-mode" @click="startEditing">
7+
<div v-if="!isEditing" class="non-edit-mode" @click="handleStartEditing">
88
{{ column.getLabel(value) }}<span v-if="isDeleted()" :title="t('tables', 'This option is outdated.')">&nbsp;⚠️</span>
99
</div>
1010
<div v-else
@@ -56,6 +56,12 @@ export default {
5656
},
5757
},
5858
59+
data() {
60+
return {
61+
isInitialEditClick: false,
62+
}
63+
},
64+
5965
computed: {
6066
getOptions() {
6167
return this.column?.selectionOptions || []
@@ -71,24 +77,29 @@ export default {
7177
isEditing(isEditing) {
7278
if (isEditing) {
7379
this.initEditValue()
74-
// Use a small delay to prevent the same click event that triggered editing
75-
// from immediately triggering the click outside handler
76-
// TODO: implement better click outside detection without setTimeout
80+
// Add click outside listener after the current event loop
81+
// to avoid the same click that triggered editing from closing the editor
7782
this.$nextTick(() => {
78-
setTimeout(() => {
79-
document.addEventListener('click', this.handleClickOutside)
80-
}, 10)
83+
document.addEventListener('click', this.handleClickOutside)
8184
})
8285
} else {
8386
// Remove click outside listener
8487
document.removeEventListener('click', this.handleClickOutside)
88+
this.isInitialEditClick = false
8589
}
8690
},
8791
},
8892
8993
methods: {
9094
t,
9195
96+
handleStartEditing(event) {
97+
this.isInitialEditClick = true
98+
this.startEditing()
99+
// Stop the event from propagating to avoid immediate click outside
100+
event.stopPropagation()
101+
},
102+
92103
isDeleted() {
93104
return this.column.isDeletedLabel(this.value)
94105
},
@@ -122,6 +133,12 @@ export default {
122133
},
123134
124135
handleClickOutside(event) {
136+
// Ignore the initial click that started editing
137+
if (this.isInitialEditClick) {
138+
this.isInitialEditClick = false
139+
return
140+
}
141+
125142
// Check if the click is outside the editing container
126143
if (this.$refs.editingContainer && !this.$refs.editingContainer.contains(event.target)) {
127144
this.saveChanges()
@@ -141,6 +158,11 @@ export default {
141158
}
142159
}
143160
161+
:deep(.vs__dropdown-toggle) {
162+
border: var(--vs-border-width) var(--vs-border-style) var(--vs-border-color);
163+
border-radius: var(--vs-border-radius);
164+
}
165+
144166
.edit-mode {
145167
.icon-loading-inline {
146168
margin-left: 4px;

0 commit comments

Comments
 (0)