Skip to content

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

Add focusOnMount to BBTextField

天舟c5cfb19cbf05
diff --git a/frontend/src/bbkit/BBTextField.vue b/frontend/src/bbkit/BBTextField.vue
index 1c0ef4aead..edbd0a7d3d 100644
--- a/frontend/src/bbkit/BBTextField.vue
+++ b/frontend/src/bbkit/BBTextField.vue
@@ -21,7 +21,7 @@
</template>
<script lang="ts">
-import { computed, nextTick, reactive, ref, watch } from "vue";
+import { computed, nextTick, onMounted, reactive, ref, watch } from "vue";
import isEmpty from "lodash-es/isEmpty";
interface LocalState {
@@ -53,9 +53,13 @@ export default {
default: true,
type: Boolean,
},
+ focusOnMount: {
+ default: false,
+ type: Boolean,
+ },
},
setup(props, { emit }) {
- const inputField = ref<HTMLInputElement>();
+ const inputField = ref();
const state = reactive<LocalState>({
text: props.value,
@@ -63,6 +67,13 @@ export default {
hasError: false,
});
+ onMounted(() => {
+ if (props.focusOnMount) {
+ inputField.value.focus();
+ inputField.value.select();
+ }
+ });
+
watch(
() => props.value,
(cur, _) => {
@@ -80,9 +91,9 @@ export default {
nextTick(() => {
state.text = state.originalText;
// Since we set focus in the nextTick, inputField might already disappear due to outside state change.
- inputField.value?.focus();
+ inputField.value.focus();
nextTick(() => {
- inputField.value?.select();
+ inputField.value.select();
});
});
} else {