File tree Expand file tree Collapse file tree 1 file changed +9
-1
lines changed
Expand file tree Collapse file tree 1 file changed +9
-1
lines changed Original file line number Diff line number Diff line change 1111 gap =" 3"
1212 >
1313 <CdsTextInput
14+ :ref =" (el) => { inputRefs[index] = el }"
1415 v-model =" item.label"
1516 floating-label
1617 :label =" inputLabel"
5253</template >
5354
5455<script setup>
55- import { defineProps , ref , watch } from ' vue' ;
56+ import { defineProps , ref , watch , nextTick } from ' vue' ;
5657import CdsTextInput from ' ./TextInput.vue' ;
5758import CdsIcon from ' ./Icon.vue' ;
5859import CdsFlexbox from ' ./Flexbox.vue' ;
@@ -87,6 +88,7 @@ defineProps({
8788
8889
8990const internalModel = ref ([]);
91+ const inputRefs = ref ([]);
9092
9193watch (model, (newValue ) => {
9294 if (JSON .stringify (newValue) === JSON .stringify (internalModel .value )) return ;
@@ -101,10 +103,16 @@ watch(internalModel, (newValue) => {
101103}, { deep: true });
102104
103105function addInput () {
106+ if (internalModel .value [internalModel .value .length - 1 ].label === ' ' ) return ;
107+
104108 internalModel .value .push ({
105109 value: generateKey (),
106110 label: ' ' ,
107111 });
112+
113+ nextTick (() => {
114+ inputRefs .value [internalModel .value .length - 1 ]? .focus ();
115+ });
108116}
109117
110118function removeInput (index ) {
You can’t perform that action at this time.
0 commit comments