aboutsummaryrefslogtreecommitdiffstats
path: root/apps/theming/src
diff options
context:
space:
mode:
authorFerdinand Thiessen <opensource@fthiessen.de>2023-10-21 00:34:27 +0200
committerFerdinand Thiessen <opensource@fthiessen.de>2023-10-21 03:52:18 +0200
commit9697df1ea5782fce0752bcebfa3318c05cc0ed1f (patch)
treedc76a50646fbf944696f7f9fc4d570444f2defe4 /apps/theming/src
parent5c2610af7dbce72fa1c1b02185a2c28cd5be004e (diff)
downloadnextcloud-server-9697df1ea5782fce0752bcebfa3318c05cc0ed1f.tar.gz
nextcloud-server-9697df1ea5782fce0752bcebfa3318c05cc0ed1f.zip
fix(theming): App order settings - ensure the focus is kept on button
When pressing a button for changing the app order that button should keep the focus after reordering the list. Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
Diffstat (limited to 'apps/theming/src')
-rw-r--r--apps/theming/src/components/AppOrderSelectorElement.vue59
1 files changed, 55 insertions, 4 deletions
diff --git a/apps/theming/src/components/AppOrderSelectorElement.vue b/apps/theming/src/components/AppOrderSelectorElement.vue
index ee795b6272a..73da7579d59 100644
--- a/apps/theming/src/components/AppOrderSelectorElement.vue
+++ b/apps/theming/src/components/AppOrderSelectorElement.vue
@@ -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 // request focus on buttonUp
+ }
+
+ /**
+ * Handle move down, ensure focus is kept on the button
+ */
+ const moveDown = () => {
+ emit('move:down')
+ needsFocus = -1 // request focus on buttonDown
+ }
+
+ /**
+ * 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) {
+ // focus requested
+ if ((needsFocus === 1 || props.isLast) && !props.isFirst) {
+ // either requested to btn up and it is not the first, or it was requested to btn down but it is the last
+ nextTick(() => buttonUp.value.$el.focus())
+ } else {
+ nextTick(() => buttonDown.value.$el.focus())
+ }
+ }
+ needsFocus = 0
+ })
+
return {
+ buttonUp,
+ buttonDown,
+
+ moveUp,
+ moveDown,
+
t,
}
},