From e54fef747667b6cf9482ae10b5c66ec6043af60c Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Sat, 8 Jun 2024 11:00:17 -0400 Subject: [PATCH] Fix keyboard navigation on search pages Some of our search pages (such as the room and user search) has a list header item. Due to how this works, it's not actually a part of the list view keyboard navigation and a whole separate item. So in the tab order, it comes *after* the list view which makes no sense. And it's part of the list view, so users must expect it to be selectable with the up and down arrows like other items. This simple change makes it so it behaves as expected. The first actual list item is selected by default, but it's possible to navigate to the list header item via the up arrow key and then return to the list view using the down arrow. The list header item is also removed from the tab order and the whole page is much nicer to use now. (cherry picked from commit 364eda64005d0dc4706ac182aa004b1b97d77a3e) --- src/qml/ExploreRoomsPage.qml | 1 + src/qml/SearchPage.qml | 9 +++++++++ src/qml/UserSearchPage.qml | 1 + 3 files changed, 11 insertions(+) diff --git a/src/qml/ExploreRoomsPage.qml b/src/qml/ExploreRoomsPage.qml index f31f0f1bd..e049208b5 100644 --- a/src/qml/ExploreRoomsPage.qml +++ b/src/qml/ExploreRoomsPage.qml @@ -89,6 +89,7 @@ SearchPage { listHeaderDelegate: Delegates.RoundedItemDelegate { onClicked: _private.openManualRoomDialog() + activeFocusOnTab: false // We handle moving to this item via up/down arrows, otherwise the tab order is wacky text: i18n("Enter a room address") icon.name: "compass" icon.width: Kirigami.Units.gridUnit * 2 diff --git a/src/qml/SearchPage.qml b/src/qml/SearchPage.qml index e80f04587..5232f07f2 100644 --- a/src/qml/SearchPage.qml +++ b/src/qml/SearchPage.qml @@ -174,5 +174,14 @@ Kirigami.ScrollablePage { anchors.centerIn: parent visible: searchField.text.length > 0 && listView.count === 0 && root.model.searching } + + Keys.onUpPressed: { + if (listView.currentIndex > 0) { + listView.decrementCurrentIndex(); + } else { + listView.currentIndex = -1; // This is so the list view doesn't appear to have two selected items + listView.headerItem.forceActiveFocus(Qt.TabFocusReason); + } + } } } diff --git a/src/qml/UserSearchPage.qml b/src/qml/UserSearchPage.qml index 83d8038b6..0714c9c98 100644 --- a/src/qml/UserSearchPage.qml +++ b/src/qml/UserSearchPage.qml @@ -41,6 +41,7 @@ SearchPage { listHeaderDelegate: Delegates.RoundedItemDelegate { onClicked: _private.openManualUserDialog() + activeFocusOnTab: false // We handle moving to this item via up/down arrows, otherwise the tab order is wacky text: i18n("Enter a user ID") icon.name: "list-add-user" icon.width: Kirigami.Units.gridUnit * 2