mirror of
https://github.com/moonlight-stream/moonlight-qt.git
synced 2026-06-18 14:40:56 +00:00
Only set initial MenuItem focus if not activating via mouse
Having an initially highlighted item when using mouse navigation doesn't adhere to UX norms and also can lead to a janky feeling when the focus flip-flops from the item under the user's cursor to the first item as the Menu opens.
This commit is contained in:
@@ -2,13 +2,18 @@ import QtQuick 2.0
|
||||
import QtQuick.Controls 2.2
|
||||
|
||||
Menu {
|
||||
property var initiator
|
||||
|
||||
onOpened: {
|
||||
// Give focus to the first visible and enabled menu item
|
||||
for (var i = 0; i < count; i++) {
|
||||
var item = itemAt(i)
|
||||
if (item.visible && item.enabled) {
|
||||
item.forceActiveFocus(Qt.TabFocusReason)
|
||||
break
|
||||
// If the initiating object currently has keyboard focus,
|
||||
// give focus to the first visible and enabled menu item
|
||||
if (initiator.focus) {
|
||||
for (var i = 0; i < count; i++) {
|
||||
var item = itemAt(i)
|
||||
if (item.visible && item.enabled) {
|
||||
item.forceActiveFocus(Qt.TabFocusReason)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user