Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

Remove BBAutoResize and extract a sizeToFit util method to let caller use it whenever it’s needed

Tianzhou Chen3cdc623688ec
diff --git a/frontend/src/bbkit/BBAutoResize.vue b/frontend/src/bbkit/BBAutoResize.vue
deleted file mode 100644
index ad7fe046ce..0000000000
--- a/frontend/src/bbkit/BBAutoResize.vue
+++ /dev/null
@@ -1,23 +0,0 @@
-<template>
- <div>
- <slot name="main" :resize="resize" />
- </div>
- <slot name="accessory" :resize="resize" />
-</template>
-
-<script lang="ts">
-export default {
- name: "ResizeAuto",
- setup(props, ctx) {
- const resize = (el: HTMLTextAreaElement) => {
- el.style.height = "auto";
- // Extra 2px is to prevent jiggling upon entering the text
- el.style.height = `${el.scrollHeight + 2}px`;
- };
-
- return {
- resize,
- };
- },
-};
-</script>
diff --git a/frontend/src/bbkit/index.ts b/frontend/src/bbkit/index.ts
index 9a65bc62e5..17cf1f0361 100644
--- a/frontend/src/bbkit/index.ts
+++ b/frontend/src/bbkit/index.ts
@@ -1,5 +1,4 @@
import BBAlert from "./BBAlert.vue";
-import BBAutoResize from "./BBAutoResize.vue";
import BBAvatar from "./BBAvatar.vue";
import BBContextMenu from "./BBContextMenu.vue";
import BBModal from "./BBModal.vue";
@@ -11,7 +10,6 @@ import { BBTable, BBTableCell, BBTableTabFilter } from "./BBTable";
export {
BBAlert,
- BBAutoResize,
BBAvatar,
BBContextMenu,
BBModal,
diff --git a/frontend/src/main.js b/frontend/src/main.js
index 77ccd42469..6f2b801016 100644
--- a/frontend/src/main.js
+++ b/frontend/src/main.js
@@ -8,7 +8,6 @@ import "./assets/css/tailwind.css";
import { makeServer } from "./miragejs/server";
import {
BBAlert,
- BBAutoResize,
BBAvatar,
BBContextMenu,
BBModal,
@@ -20,7 +19,7 @@ import {
BBTableCell,
BBTableTabFilter,
} from "./bbkit";
-import { isDevOrDemo, humanizeTs } from "./utils";
+import { isDevOrDemo, humanizeTs, sizeToFit } from "./utils";
if (isDevOrDemo()) {
makeServer();
@@ -34,12 +33,12 @@ app.config.globalProperties.console = console;
app.config.globalProperties.moment = moment;
app.config.globalProperties.humanizeTs = humanizeTs;
app.config.globalProperties.isDevOrDemo = isDevOrDemo();
+app.config.globalProperties.sizeToFit = sizeToFit;
app
.use(store)
.use(router)
.component("BBAlert", BBAlert)
- .component("BBAutoResize", BBAutoResize)
.component("BBAvatar", BBAvatar)
.component("BBContextMenu", BBContextMenu)
.component("BBModal", BBModal)
diff --git a/frontend/src/utils/util.ts b/frontend/src/utils/util.ts
index c39e422070..d9cd11bc48 100644
--- a/frontend/src/utils/util.ts
+++ b/frontend/src/utils/util.ts
@@ -40,3 +40,9 @@ export function array_swap(arr: any[], old_index: number, new_index: number) {
}
arr.splice(new_index, 0, arr.splice(old_index, 1)[0]);
}
+
+export function sizeToFit(el: HTMLTextAreaElement) {
+ el.style.height = "auto";
+ // Extra 2px is to prevent jiggling upon entering the text
+ el.style.height = `${el.scrollHeight + 2}px`;
+}
diff --git a/frontend/src/views/TaskActivityPanel.vue b/frontend/src/views/TaskActivityPanel.vue
index c501ba430e..24e11244c8 100644
--- a/frontend/src/views/TaskActivityPanel.vue
+++ b/frontend/src/views/TaskActivityPanel.vue
@@ -177,30 +177,26 @@
state.activeComment.id == activity.id
"
>
- <BBAutoResize>
- <template v-slot:main="{ resize }">
- <label for="comment" class="sr-only"
- >Edit Comment</label
- >
- <textarea
- ref="editCommentTextArea"
- rows="3"
- class="textarea block w-full resize-none"
- placeholder="Leave a comment..."
- v-model="editComment"
- @input="
- (e) => {
- resize(e.target);
- }
- "
- @focus="
- (e) => {
- resize(e.target);
- }
- "
- ></textarea>
- </template>
- </BBAutoResize>
+ <label for="comment" class="sr-only"
+ >Edit Comment</label
+ >
+ <textarea
+ ref="editCommentTextArea"
+ rows="3"
+ class="textarea block w-full resize-none"
+ placeholder="Leave a comment..."
+ v-model="editComment"
+ @input="
+ (e) => {
+ sizeToFit(e.target);
+ }
+ "
+ @focus="
+ (e) => {
+ sizeToFit(e.target);
+ }
+ "
+ ></textarea>
</template>
<template v-else>
{{ activity.attributes.payload.content }}
@@ -239,35 +235,29 @@
</div>
</div>
<div class="ml-3 min-w-0 flex-1">
- <BBAutoResize>
- <template v-slot:main="{ resize }">
- <label for="comment" class="sr-only">Create Comment</label>
- <textarea
- ref="newCommentTextArea"
- rows="3"
- class="textarea block w-full resize-none"
- placeholder="Leave a comment..."
- v-model="newComment"
- @input="
- (e) => {
- resize(e.target);
- }
- "
- ></textarea>
- </template>
- <template v-slot:accessory="{ resize }">
- <div class="mt-4 flex items-center justify-start space-x-4">
- <button
- type="button"
- class="btn-normal"
- :disabled="newComment.length == 0"
- @click.prevent="doCreateComment(resize)"
- >
- Comment
- </button>
- </div>
- </template>
- </BBAutoResize>
+ <label for="comment" class="sr-only">Create Comment</label>
+ <textarea
+ ref="newCommentTextArea"
+ rows="3"
+ class="textarea block w-full resize-none"
+ placeholder="Leave a comment..."
+ v-model="newComment"
+ @input="
+ (e) => {
+ sizeToFit(e.target);
+ }
+ "
+ ></textarea>
+ <div class="mt-4 flex items-center justify-start space-x-4">
+ <button
+ type="button"
+ class="btn-normal"
+ :disabled="newComment.length == 0"
+ @click.prevent="doCreateComment"
+ >
+ Comment
+ </button>
+ </div>
</div>
</div>
</div>
@@ -307,6 +297,7 @@ import {
import { useStore } from "vuex";
import { UserStateSymbol } from "../components/ProvideUser.vue";
import { User, Task, TaskActionType, Activity, ActivityId } from "../types";
+import { sizeToFit } from "../utils";
interface LocalState {
showDeleteCommentModal: boolean;
@@ -380,7 +371,7 @@ export default {
state.editCommentMode = false;
};
- const doCreateComment = (resize?: (el: HTMLTextAreaElement) => void) => {
+ const doCreateComment = () => {
store
.dispatch("activity/createActivity", {
type: "activity",
@@ -398,9 +389,7 @@ export default {
})
.then(() => {
newComment.value = "";
- if (resize) {
- nextTick(() => resize(newCommentTextArea.value));
- }
+ nextTick(() => sizeToFit(newCommentTextArea.value));
})
.catch((error) => {
console.log(error);
diff --git a/frontend/src/views/TaskContent.vue b/frontend/src/views/TaskContent.vue
index f183c11b08..287d501b8c 100644
--- a/frontend/src/views/TaskContent.vue
+++ b/frontend/src/views/TaskContent.vue
@@ -39,47 +39,44 @@
</button>
</div>
<!-- Content -->
- <BBAutoResize>
- <template v-slot:main="{ resize }">
- <label for="content" class="sr-only">Edit Description</label>
- <!-- Use border-white focus:border-white to have the invisible border width
+ <label for="content" class="sr-only">Edit Description</label>
+ <!-- Use border-white focus:border-white to have the invisible border width
otherwise it will have 1px jiggling switching between focus/unfocus state -->
- <textarea
- ref="editContentTextArea"
- rows="10"
- class="mt-4 rounded-md w-full resize-none whitespace-pre-line border-white focus:border-white outline-none"
- :class="
- state.edit
- ? 'focus:ring-control focus-visible:ring-2 focus:ring-offset-4'
- : ''
- "
- :style="
- state.edit
- ? ''
- : '-webkit-box-shadow: none; -moz-box-shadow: none; box-shadow: none'
- "
- placeholder="Add some description..."
- :readonly="!state.edit"
- v-model="editContent"
- @input="
- (e) => {
- resize(e.target);
- }
- "
- @focus="
- (e) => {
- resize(e.target);
- }
- "
- ></textarea>
- </template>
- </BBAutoResize>
+ <textarea
+ ref="editContentTextArea"
+ rows="10"
+ class="mt-4 rounded-md w-full resize-none whitespace-pre-line border-white focus:border-white outline-none"
+ :class="
+ state.edit
+ ? 'focus:ring-control focus-visible:ring-2 focus:ring-offset-4'
+ : ''
+ "
+ :style="
+ state.edit
+ ? ''
+ : '-webkit-box-shadow: none; -moz-box-shadow: none; box-shadow: none'
+ "
+ placeholder="Add some description..."
+ :readonly="!state.edit"
+ v-model="editContent"
+ @input="
+ (e) => {
+ sizeToFit(e.target);
+ }
+ "
+ @focus="
+ (e) => {
+ sizeToFit(e.target);
+ }
+ "
+ ></textarea>
</template>
<script lang="ts">
import { nextTick, onMounted, onUnmounted, PropType, ref, reactive } from "vue";
import { useStore } from "vuex";
import { Task } from "../types";
+import { sizeToFit } from "../utils";
interface LocalState {
edit: boolean;
@@ -115,6 +112,9 @@ export default {
onMounted(() => {
document.addEventListener("keydown", keyboardHandler);
+ nextTick(() => {
+ sizeToFit(editContentTextArea.value);
+ });
});
onUnmounted(() => {
@@ -140,6 +140,9 @@ export default {
.then((updatedTask: Task) => {
state.edit = false;
editContent.value = updatedTask.attributes.content;
+ nextTick(() => {
+ sizeToFit(editContentTextArea.value);
+ });
})
.catch((error) => {
console.log(error);
@@ -149,6 +152,9 @@ export default {
const cancelEdit = () => {
state.edit = false;
editContent.value = props.task.attributes.content;
+ nextTick(() => {
+ sizeToFit(editContentTextArea.value);
+ });
};
return {