Skip to content

fix: don't make disabled axis areas keyboard-focusable - #269

Merged
lucasmerlin merged 2 commits into
emilk:mainfrom
TssHack:fix/disabled-axis-keyboard-focus
Oct 19, 2026
Merged

lucasmerlin merged 2 commits into
emilk:mainfrom
TssHack:fix/disabled-axis-keyboard-focus

Conversation

@TssHack

@TssHack TssHack commented Oct 12, 2026

Copy link
Copy Markdown
Contributor

Problem

allocate_axis_responses allocated every axis rect with Sense::drag() regardless of
allow_axis_zoom_drag. Sense::drag() is DRAG | FOCUSABLE, and egui gives focus interest
and an AccessKit node to any focusable widget. A static, display-only plot therefore added
two unnamed, inert Tab stops, one per axis. The only way to remove them was
show_axes(false), which also removes the axes.

Reported in #268. I confirmed the mechanism in the pinned egui revision, where
Sense::hover() is Self::empty() and therefore not focusable.

Change

Pick the sense per axis instead of globally:

let axis_sense = |axis| {
    if self.allow_axis_zoom_drag[axis] {
        Sense::drag()
    } else {
        Sense::hover()
    }
};

used as axis_sense(0) / axis_sense(1). Disabling zoom-drag on one axis leaves the other
axis draggable and focusable.

Sense::hover() still participates in hit-testing, so the hover cursor and rect allocation
are unchanged. The drag-to-zoom handler was already guarded by allow_axis_zoom_drag, so
drag behaviour is unchanged. This also documents the new contract on
Plot::allow_axis_zoom_drag.

Scope: one function, no API change, no breaking change.

Tests

Four egui_kittest tests in the existing plot_tests module. The axis areas carry no
accessible name, so they are distinguished by AccessKit bounding-box shape: an x axis is the
wide, short strip along the bottom, a y axis the narrow, tall strip along the left.
Assertions are sorted, so they do not depend on AccessKit traversal order, and no
coordinates are hard-coded.

  • disabled_axes_are_not_focusable -- all interactions off: only the following button is focusable.
  • enabled_axes_are_focusable -- both axes on: button plus both axis areas are focusable.
  • mixed_axes_are_focusable_per_axis -- [true, false] keeps only the x axis; [false, true] keeps only the y axis.
  • mixed_axes_are_focusable_at_other_sizes -- the per-axis expectations hold at three other UI sizes.

I checked that the tests actually catch regressions: with both axes wrongly gated on a single
flag (in either direction), mixed_axes_are_focusable_per_axis and
mixed_axes_are_focusable_at_other_sizes fail; with the fix they pass.

The axis shape discrimination was measured rather than assumed: across 153 width/height
combinations the smallest x-axis aspect ratio observed was 2.54 and the largest y-axis aspect
ratio was 0.31, so the "wider than tall" test has a wide margin and does not depend on fonts
or exact pixel sizes.

Validation performed

  • cargo test -p egui_plot -- 9 passed, 0 failed; doctests 4 passed, 2 ignored
  • cargo clippy -p egui_plot --all-targets --all-features -- -D warnings -- clean
  • cargo fmt --all -- --check -- clean
  • cargo check --workspace --all-targets -- clean
  • git diff --check -- clean

Not run: ./scripts/check.sh (it installs typos-cli and runs cargo deny, which need
network access). Opening as a draft per CONTRIBUTING.md until that has been run.

Disclosure

An AI coding assistant was used to investigate the issue, implement the change, and write the
tests. I reviewed the diff and ran the validation listed above.

Notes for reviewers

  • Commit: 24c7dd760b75253953642d0d357e30a6458a5739
  • Branch: fix/disabled-axis-keyboard-focus, based on main at a9d6c96
  • One file changed: egui_plot/src/plot.rs (+150/-3)

@github-actions

Copy link
Copy Markdown

View snapshot changes at kitdiff

@TssHack
TssHack marked this pull request as ready for review October 13, 2026 05:38

@lucasmerlin lucasmerlin left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I've changed it so the axis can never have focus, since focus useless there anyways

@lucasmerlin lucasmerlin added bug Something isn't working include in changelog This change will be included in the changelog labels Oct 19, 2026
@lucasmerlin
lucasmerlin merged commit 8fb933d into emilk:main Oct 19, 2026
10 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working include in changelog This change will be included in the changelog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Axis areas are always keyboard-focusable (Sense::drag), even with allow_axis_zoom_drag(false)

2 participants