2323 @mouseleave =" onItemMouseLeave"
2424 >
2525 <input
26+ ref =" nameRef"
2627 class =" module-param-input module-param-input--name"
2728 :value =" name"
2829 :style =" { width: Math.max(name.length, 1) + 'ch' }"
8586</template >
8687
8788<script >
88- import { ref , computed , nextTick , onMounted , onBeforeUnmount } from ' vue'
89+ import { ref , computed , watch , nextTick , onMounted , onBeforeUnmount } from ' vue'
8990import * as bootstrap from ' bootstrap'
9091import { useSceneStore } from ' ../../store/scene'
9192import { app } from ' ../../services/app'
@@ -99,10 +100,12 @@ export default {
99100 min: { type: String , default: ' 0' },
100101 step: { type: String , default: ' 1' },
101102 max: { type: String , default: ' 0' },
102- defaultVal: { type: String , default: ' 0' }
103+ defaultVal: { type: String , default: ' 0' },
104+ focusName: { type: Boolean , default: false }
103105 },
104- emits: [' update:name' , ' update:min' , ' update:step' , ' update:max' , ' update:defaultVal' , ' commit' ],
106+ emits: [' update:name' , ' update:min' , ' update:step' , ' update:max' , ' update:defaultVal' , ' commit' , ' focus-name-done ' ],
105107 setup (props , { emit }) {
108+ const nameRef = ref (null )
106109 const tooltipHostRef = ref (null )
107110 const sceneStore = useSceneStore ()
108111 const editorSelectedObjIndex = ref (- 1 )
@@ -217,6 +220,27 @@ export default {
217220 })
218221 }
219222
223+ const focusNameInput = () => {
224+ const el = nameRef .value
225+ if (! el) {
226+ return
227+ }
228+ el .focus ()
229+ el .select ()
230+ emit (' focus-name-done' )
231+ }
232+
233+ watch (
234+ () => props .focusName ,
235+ (shouldFocus ) => {
236+ if (! shouldFocus) {
237+ return
238+ }
239+ nextTick (focusNameInput)
240+ },
241+ { immediate: true , flush: ' post' }
242+ )
243+
220244 const syncEditorSelection = () => {
221245 editorSelectedObjIndex .value = app .editor ? .selectedObjIndex ?? - 1
222246 }
@@ -246,6 +270,7 @@ export default {
246270 })
247271
248272 return {
273+ nameRef,
249274 tooltipHostRef,
250275 onRowFocusOut,
251276 onEnterCommit,
0 commit comments