7474 role =" listitem" >
7575 <span class =" ranking-item__position" >{{ index + 1 }}.</span >
7676 <NcActions
77+ :id =" `ranking-${option.id}-drag`"
78+ :container =" `#ranking-${option.id}-drag`"
7779 :aria-label =" t('forms', 'Move option actions')"
7880 class =" ranking-item__drag-handle"
7981 variant =" tertiary-no-background" >
8082 <template #icon >
8183 <IconDragIndicator :size =" 20" />
8284 </template >
8385 <NcActionButton
86+ ref =" buttonOptionUp"
8487 :disabled =" index === 0"
8588 @click =" onMoveUp(index)" >
8689 <template #icon >
8992 {{ t('forms', 'Move option up') }}
9093 </NcActionButton >
9194 <NcActionButton
95+ ref =" buttonOptionDown"
9296 :disabled =" index === rankedOptions.length - 1"
9397 @click =" onMoveDown(index)" >
9498 <template #icon >
@@ -308,6 +312,11 @@ export default {
308312 ;[items[index - 1 ], items[index]] = [items[index], items[index - 1 ]]
309313 this .rankedOptions = items
310314 this .emitValues ()
315+ const newIndex = index - 1
316+ this .focusButton (
317+ newIndex > 0 ? ' buttonOptionUp' : ' buttonOptionDown' ,
318+ newIndex,
319+ )
311320 },
312321
313322 /**
@@ -321,6 +330,28 @@ export default {
321330 ;[items[index], items[index + 1 ]] = [items[index + 1 ], items[index]]
322331 this .rankedOptions = items
323332 this .emitValues ()
333+ const newIndex = index + 1
334+ this .focusButton (
335+ newIndex < this .rankedOptions .length - 1
336+ ? ' buttonOptionDown'
337+ : ' buttonOptionUp' ,
338+ newIndex,
339+ )
340+ },
341+
342+ /**
343+ * Re-focus a button ref inside a v-for after reorder
344+ *
345+ * @param {string} refName The ref name ('buttonOptionUp' or 'buttonOptionDown')
346+ * @param {number} index The index of the item in the v-for
347+ */
348+ focusButton (refName , index ) {
349+ this .$nextTick (() => {
350+ const refs = this .$refs [refName]
351+ if (Array .isArray (refs) && refs[index]) {
352+ refs[index].$el ? .focus ()
353+ }
354+ })
324355 },
325356
326357 /**
0 commit comments