From 9fe6cc8f9db79d6de2c349376593493a2cdf14f5 Mon Sep 17 00:00:00 2001 From: wjyrich Date: Tue, 24 Mar 2026 14:30:38 +0800 Subject: [PATCH] fix: improve notification close button visibility logic MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. Added `focusedByNavigation` property to GroupNotify, NormalNotify, and OverlapNotify components 2. Modified close button visibility condition to only show when focused via keyboard navigation, not programmatic focus 3. Updated NotifyView and NotifyViewDelegate to set `focusedByNavigation=true` when navigating between items 4. Reset `focusedByNavigation` to false when item loses active focus The issue was that close buttons were incorrectly showing when notifications received programmatic focus (e.g., during initialization or other non-navigation scenarios). This fix ensures close buttons only appear during actual keyboard navigation, improving the user experience by preventing visual clutter when not needed. Log: Fixed notification close button visibility during keyboard navigation Influence: 1. Test keyboard navigation between notification items using arrow keys 2. Verify close buttons appear only during keyboard navigation, not during initial load 3. Test mouse hover behavior - close buttons should appear on hover 4. Verify focus transitions between notifications work correctly 5. Test that programmatic focus changes don't trigger close button display 6. Check accessibility navigation with screen readers fix: 改进通知关闭按钮可见性逻辑 1. 在 GroupNotify、NormalNotify 和 OverlapNotify 组件中添加 `focusedByNavigation` 属性 2. 修改关闭按钮可见性条件,仅在通过键盘导航获得焦点时显示,而不是程序化 焦点 3. 更新 NotifyView 和 NotifyViewDelegate,在导航到项目时设置 `focusedByNavigation=true` 4. 当项目失去活动焦点时,将 `focusedByNavigation` 重置为 false 问题在于当通知获得程序化焦点时(例如初始化期间或其他非导航场景),关闭按 钮会错误地显示。此修复确保关闭按钮仅在真正的键盘导航期间出现,通过在不必 要时防止视觉混乱来改善用户体验。 Log: 修复了键盘导航期间通知关闭按钮的可见性问题 Influence: 1. 使用方向键测试通知项目之间的键盘导航 2. 验证关闭按钮仅在键盘导航期间出现,而不是在初始加载时 3. 测试鼠标悬停行为 - 悬停时应显示关闭按钮 4. 验证通知之间的焦点转换正常工作 5. 测试程序化焦点更改不会触发关闭按钮显示 6. 检查屏幕阅读器的辅助功能导航 --- panels/notification/center/GroupNotify.qml | 2 ++ panels/notification/center/NormalNotify.qml | 5 ++++- panels/notification/center/NotifyView.qml | 1 + panels/notification/center/NotifyViewDelegate.qml | 2 ++ panels/notification/center/OverlapNotify.qml | 5 ++++- 5 files changed, 13 insertions(+), 2 deletions(-) diff --git a/panels/notification/center/GroupNotify.qml b/panels/notification/center/GroupNotify.qml index 29c607a54..7a17299f4 100644 --- a/panels/notification/center/GroupNotify.qml +++ b/panels/notification/center/GroupNotify.qml @@ -13,6 +13,8 @@ NotifyItem { id: root implicitWidth: impl.implicitWidth implicitHeight: impl.implicitHeight + property bool focusedByNavigation: false + onActiveFocusChanged: if (!activeFocus) focusedByNavigation = false signal collapse() signal gotoNextItem() // Signal to navigate to next notify item diff --git a/panels/notification/center/NormalNotify.qml b/panels/notification/center/NormalNotify.qml index ee9192106..35da81e7e 100644 --- a/panels/notification/center/NormalNotify.qml +++ b/panels/notification/center/NormalNotify.qml @@ -14,6 +14,9 @@ NotifyItem { implicitWidth: impl.implicitWidth implicitHeight: impl.implicitHeight + property bool focusedByNavigation: false + onActiveFocusChanged: if (!activeFocus) focusedByNavigation = false + signal gotoNextItem() signal gotoPrevItem() @@ -59,7 +62,7 @@ NotifyItem { actions: root.actions defaultAction: root.defaultAction // Show close button when: mouse hovers, or item has focus from keyboard navigation - parentHovered: impl.hovered || root.activeFocus + parentHovered: impl.hovered || (root.activeFocus && root.focusedByNavigation) strongInteractive: root.strongInteractive contentIcon: root.contentIcon contentRowCount: root.contentRowCount diff --git a/panels/notification/center/NotifyView.qml b/panels/notification/center/NotifyView.qml index 93db32f54..e235a7df4 100644 --- a/panels/notification/center/NotifyView.qml +++ b/panels/notification/center/NotifyView.qml @@ -38,6 +38,7 @@ Control { function tryFocus(retries) { let item = view.itemAtIndex(idx) if (item && item.enabled) { + item.focusedByNavigation = true item.resetFocus() if (!item.focusFirstButton()) { item.forceActiveFocus() diff --git a/panels/notification/center/NotifyViewDelegate.qml b/panels/notification/center/NotifyViewDelegate.qml index bbec8e4b9..51480a659 100644 --- a/panels/notification/center/NotifyViewDelegate.qml +++ b/panels/notification/center/NotifyViewDelegate.qml @@ -26,6 +26,7 @@ DelegateChooser { Qt.callLater(function() { let nextItem = view.itemAtIndex(currentIndex + 1) if (nextItem && nextItem.enabled) { + nextItem.focusedByNavigation = true nextItem.resetFocus() nextItem.forceActiveFocus() } @@ -43,6 +44,7 @@ DelegateChooser { Qt.callLater(function() { let prevItem = view.itemAtIndex(currentIndex - 1) if (prevItem && prevItem.enabled) { + prevItem.focusedByNavigation = true prevItem.forceActiveFocus() } }) diff --git a/panels/notification/center/OverlapNotify.qml b/panels/notification/center/OverlapNotify.qml index 36aed924b..a2722bf87 100644 --- a/panels/notification/center/OverlapNotify.qml +++ b/panels/notification/center/OverlapNotify.qml @@ -20,6 +20,9 @@ NotifyItem { property var removedCallback property alias notifyContent: notifyContent + property bool focusedByNavigation: false + onActiveFocusChanged: if (!activeFocus) focusedByNavigation = false + signal expand() signal gotoNextItem() signal gotoPrevItem() @@ -107,7 +110,7 @@ NotifyItem { actions: root.actions defaultAction: root.defaultAction // Show close button when: mouse hovers, or item has focus from keyboard navigation - parentHovered: impl.hovered || root.activeFocus + parentHovered: impl.hovered || (root.activeFocus && root.focusedByNavigation) strongInteractive: root.strongInteractive contentIcon: root.contentIcon contentRowCount: root.contentRowCount