a11y: Don't navigate through items with Tab in GtkListViews

When there are other widgets to navigate to outside of the list view.
Arrow keys can be used instead to navigate between items.
This commit is contained in:
Kévin Commaille 2023-12-22 14:59:22 +01:00
parent 94f28cd980
commit da91255fd5
No known key found for this signature in database
GPG Key ID: 29A48C1F03620416
6 changed files with 6 additions and 22 deletions

View File

@ -88,6 +88,7 @@
<object class="GtkListView" id="listview">
<property name="margin-end">24</property>
<property name="margin-start">24</property>
<property name="tab-behavior">item</property>
<property name="factory">
<object class="GtkBuilderListItemFactory">
<property name="bytes"><![CDATA[

View File

@ -97,6 +97,7 @@
<property name="margin-end">12</property>
<property name="margin-start">12</property>
<property name="single-click-activate">True</property>
<property name="tab-behavior">item</property>
<property name="factory">
<object class="GtkBuilderListItemFactory">
<property name="bytes"><![CDATA[

View File

@ -53,6 +53,7 @@
<property name="child">
<object class="GtkListView" id="list_view">
<property name="single-click-activate">True</property>
<property name="tab-behavior">item</property>
<property name="factory">
<object class="GtkBuilderListItemFactory">
<property name="bytes"><![CDATA[

View File

@ -161,6 +161,7 @@
<style>
<class name="navigation-sidebar"/>
</style>
<property name="tab-behavior">item</property>
<accessibility>
<property name="label" translatable="yes">Room History</property>
</accessibility>

View File

@ -134,28 +134,7 @@ mod imp {
}
}
impl WidgetImpl for Sidebar {
fn focus(&self, direction_type: gtk::DirectionType) -> bool {
// WORKAROUND: This works around the tab behavior `gtk::ListViews have`
// See: https://gitlab.gnome.org/GNOME/gtk/-/issues/4840
let focus_child = self
.obj()
.focus_child()
.and_then(|w| w.focus_child())
.and_then(|w| w.focus_child());
if focus_child.is_some_and(|w| w.is::<gtk::ListView>())
&& matches!(
direction_type,
gtk::DirectionType::TabForward | gtk::DirectionType::TabBackward
)
{
false
} else {
self.parent_focus(direction_type)
}
}
}
impl WidgetImpl for Sidebar {}
impl NavigationPageImpl for Sidebar {}
impl Sidebar {

View File

@ -140,6 +140,7 @@
<class name="sidebar-list"/>
</style>
<property name="single-click-activate">true</property>
<property name="tab-behavior">item</property>
<accessibility>
<property name="label" translatable="yes">Sidebar</property>
<property name="description" translatable="yes">Allows to navigate between rooms</property>