From d5d83ff7b8aa0ffb2739ffab7adc469bb2249cd0 Mon Sep 17 00:00:00 2001 From: Jan Blackquill Date: Wed, 21 Apr 2021 18:31:30 -0400 Subject: [PATCH] Improve keyboard navigation Simply enabling activeFocusOnTab on a few key elements massively improves the keyboard navigation. Additionally, making the text box forward tab events when appropriate allows for focus to pass through it without getitng stuck. --- imports/NeoChat/Component/ChatBox/ChatBar.qml | 17 ++++++++++------- imports/NeoChat/Page/RoomListPage.qml | 2 ++ imports/NeoChat/Panel/RoomDrawer.qml | 2 ++ 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/imports/NeoChat/Component/ChatBox/ChatBar.qml b/imports/NeoChat/Component/ChatBox/ChatBar.qml index 80d68d801..90f9d6734 100644 --- a/imports/NeoChat/Component/ChatBox/ChatBar.qml +++ b/imports/NeoChat/Component/ChatBox/ChatBar.qml @@ -159,14 +159,16 @@ ToolBar { switchRoomUp(); return; } - if (isCompleting) { - let decrementedIndex = completionMenu.currentIndex - 1 - // Wrap around to the last item - if (decrementedIndex < 0) { - decrementedIndex = Math.max(completionMenu.count - 1, 0) // 0 if count == 0 - } - completionMenu.currentIndex = decrementedIndex + if (!isCompleting) { + nextItemInFocusChain(false).forceActiveFocus(Qt.TabFocusReason) + return } + let decrementedIndex = completionMenu.currentIndex - 1 + // Wrap around to the last item + if (decrementedIndex < 0) { + decrementedIndex = Math.max(completionMenu.count - 1, 0) // 0 if count == 0 + } + completionMenu.currentIndex = decrementedIndex } Keys.onTabPressed: { @@ -175,6 +177,7 @@ ToolBar { return; } if (!isCompleting) { + nextItemInFocusChain().forceActiveFocus(Qt.TabFocusReason); return; } diff --git a/imports/NeoChat/Page/RoomListPage.qml b/imports/NeoChat/Page/RoomListPage.qml index 208e9aa9a..743b4778b 100644 --- a/imports/NeoChat/Page/RoomListPage.qml +++ b/imports/NeoChat/Page/RoomListPage.qml @@ -48,6 +48,8 @@ Kirigami.ScrollablePage { ListView { id: listView + activeFocusOnTab: true + Kirigami.PlaceholderMessage { anchors.centerIn: parent width: parent.width - (Kirigami.Units.largeSpacing * 4) diff --git a/imports/NeoChat/Panel/RoomDrawer.qml b/imports/NeoChat/Panel/RoomDrawer.qml index c4ffc6754..4136cfb30 100644 --- a/imports/NeoChat/Panel/RoomDrawer.qml +++ b/imports/NeoChat/Panel/RoomDrawer.qml @@ -147,6 +147,7 @@ Kirigami.OverlayDrawer { Kirigami.ListSectionHeader { label: i18n("Members") + activeFocusOnTab: false Label { Layout.alignment: Qt.AlignRight text: room ? i18np("%1 Member", "%1 Members", room.totalMemberCount) : i18n("No Member Count") @@ -162,6 +163,7 @@ Kirigami.OverlayDrawer { clip: true headerPositioning: ListView.OverlayHeader boundsBehavior: Flickable.DragOverBounds + activeFocusOnTab: true header: Pane { padding: Kirigami.Units.smallSpacing