Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keyboard focus works with Shift+Tab but not with just the Tab key #207

Closed
white-axe opened this issue Dec 10, 2023 · 1 comment · Fixed by #211
Closed

Keyboard focus works with Shift+Tab but not with just the Tab key #207

white-axe opened this issue Dec 10, 2023 · 1 comment · Fixed by #211
Labels
bug Something isn't working

Comments

@white-axe
Copy link
Contributor

Describe the bug
Egui allows users to focus widgets using the keyboard, i.e. selecting focusable widgets like buttons, using the Tab key to navigate in forward order or Shift+Tab to navigate in reverse order. However, widgets in an egui_dock tab will only be navigable in this way if the user uses Shift+Tab. Pressing the Tab key does not work.

To Reproduce
Replace the ui.label(format!("Content of {tab}")); here in the "simple" example with let _ = ui.button(format!("Content of {tab}")); and then run it.

ui.label(format!("Content of {tab}"));

When holding down Shift+Tab, the focus cycles between the buttons inside the tabs.

When holding down the Tab key alone, nothing happens.

Expected behavior
When holding down the Tab key, the focus should cycle between the buttons in the reverse of the order that Shift+Tab cycles the buttons in.

Screenshots
This is what's supposed to happen when holding Tab, but in reverse order:
screenshot

@white-axe white-axe added the bug Something isn't working label Dec 10, 2023
@white-axe
Copy link
Contributor Author

white-axe commented Dec 26, 2023

It turns out this bug is being caused by this context menu. Disabling it by using .tab_context_menus(false) when creating the DockArea fixes it.

if self.tab_context_menus {
let eject_button =
Button::new(&self.dock_state.translations.tab_context_menu.eject_button);
let close_button =
Button::new(&self.dock_state.translations.tab_context_menu.close_button);
let Node::Leaf { tabs, active, .. } =
&mut self.dock_state[surface_index][node_index]
else {
unreachable!()
};
let tab = &mut tabs[tab_index.0];
response = response.context_menu(|ui| {
tab_viewer.context_menu(ui, tab, surface_index, node_index);
if (surface_index.is_main() || !is_lonely_tab)
&& tab_viewer.allowed_in_windows(tab)
&& ui.add(eject_button).clicked()
{
self.to_detach.push((surface_index, node_index, tab_index));
ui.close_menu();
}
if show_close_button && ui.add(close_button).clicked() {
if tab_viewer.on_close(tab) {
self.to_remove
.push((surface_index, node_index, tab_index).into());
} else {
*active = tab_index;
self.new_focused = Some((surface_index, node_index));
}
ui.close_menu();
}
});
}

I'll see if I can figure out how to fix the bug without disabling the context menu.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant