@ -23,20 +23,22 @@
< div class = "order-selector-element__actions" >
< NcButton v -show = " ! isFirst & & ! app.default "
ref = "buttonUp"
: aria - label = "t('settings', 'Move up')"
data - cy - app - order - button = "up"
type = "tertiary-no-background"
@ click = "$emit('move:up') " >
@ click = "moveUp " >
< template # icon >
< IconArrowUp :size ="20" / >
< / template >
< / NcButton >
< div v -show = " isFirst | | ! ! app.default " aria -hidden = " true " class = "order-selector-element__placeholder" / >
< NcButton v -show = " ! isLast & & ! app.default "
ref = "buttonDown"
: aria - label = "t('settings', 'Move down')"
data - cy - app - order - button = "down"
type = "tertiary-no-background"
@ click = "$emit('move:down') " >
@ click = "moveDown " >
< template # icon >
< IconArrowDown :size ="20" / >
< / template >
@ -47,8 +49,10 @@
< / template >
< script lang = "ts" >
import type { PropType } from 'vue'
import { translate as t } from '@nextcloud/l10n'
import { PropType , defineComponent } from 'vue'
import { defineComponent , nextTick , onUpdated , ref } from 'vue'
import IconArrowDown from 'vue-material-design-icons/ArrowDown.vue'
import IconArrowUp from 'vue-material-design-icons/ArrowUp.vue'
@ -86,8 +90,55 @@ export default defineComponent({
'move:up' : ( ) => true ,
'move:down' : ( ) => true ,
} ,
setup ( ) {
setup ( props , { emit } ) {
const buttonUp = ref ( )
const buttonDown = ref ( )
/ * *
* Used to decide if we need to trigger focus ( ) an a button on update
* /
let needsFocus = 0
/ * *
* Handle move up , ensure focus is kept on the button
* /
const moveUp = ( ) => {
emit ( 'move:up' )
needsFocus = 1 / / r e q u e s t f o c u s o n b u t t o n U p
}
/ * *
* Handle move down , ensure focus is kept on the button
* /
const moveDown = ( ) => {
emit ( 'move:down' )
needsFocus = - 1 / / r e q u e s t f o c u s o n b u t t o n D o w n
}
/ * *
* onUpdated hook is used to reset the focus on the last used button ( if requested )
* If the button is now visible anymore ( because this element is the first / last ) then the opposite button is focussed
* /
onUpdated ( ( ) => {
if ( needsFocus !== 0 ) {
/ / f o c u s r e q u e s t e d
if ( ( needsFocus === 1 || props . isLast ) && ! props . isFirst ) {
/ / e i t h e r r e q u e s t e d t o b t n u p a n d i t i s n o t t h e f i r s t , o r i t w a s r e q u e s t e d t o b t n d o w n b u t i t i s t h e l a s t
nextTick ( ( ) => buttonUp . value . $el . focus ( ) )
} else {
nextTick ( ( ) => buttonDown . value . $el . focus ( ) )
}
}
needsFocus = 0
} )
return {
buttonUp ,
buttonDown ,
moveUp ,
moveDown ,
t ,
}
} ,