8000 Keep `BoxLayout` widgets in DOM order by r0c0y · Pull Request #878 · jupyterlab/lumino · GitHub
[go: up one dir, main page]

Skip to content

Keep BoxLa 8000 yout widgets in DOM order - #878

Open
r0c0y wants to merge 2 commits into
jupyterlab:mainfrom
r0c0y:fix-boxlayout-dom-order
Open

r0c0y wants to merge 2 commits into
jupyterlab:mainfrom
r0c0y:fix-boxlayout-dom-order

Conversation

@r0c0y
@r0c0y r0c0y commented Nov 24, 2026 •
Copy link
Copy Markdown
Contributor

References

Code changes

  • BoxLayout.attachWidget inserts the widget's node before the next widget's node instead of appending it.
  • BoxLayout.moveWidget now moves the node to the same place. Around the move it sends the widget before-detach, after-detach, before-attach and after-attach, as PanelLayout.moveWidget does, because the node leaves the DOM and comes back.

Anchoring on the next widget's node, rather than on children[index] as PanelLayout does, leaves any other nodes in the panel's node where they are.

User-facing changes

After insertWidget or a move, Tab and screen readers reach the widgets of a BoxPanel in the order of its widgets. For top-to-bottom and left-to-right panels, that is the order on screen. Panels drawn in reverse get the same DOM order, so a TabPanel with its tabs at the bottom keeps its tab bar first, as today.

In a JupyterLab dev build (Lumino 2.10.0) in the simple interface, the shell's children in DOM order, with each one's top on screen, are:

main:    .jp-skiplink-wrapper@4  #jp-header-panel@0  #jp-top-panel@4  #jp-main-content-panel@60  #jp-bottom-panel@696  #jp-menu-panel@32
this PR: .jp-skiplink-wrapper@4  #jp-header-panel@0  #jp-top-panel@4  #jp-menu-panel@32  #jp-main-content-panel@60  #jp-bottom-panel@696

On main, Tab from the document title skips the menu bar and reaches it only after the main area and the status bar. With this PR it goes to the menu bar next. The second line and the second picture come from the same page with this PR's attachWidget change applied.

Tab from the title focuses the file browser button on main, and the File menu with this PR

Tests

boxlayout.spec.ts: an insert at an index, an insert into a panel whose node holds another node, moves to the start, the end and the middle (full DOM order each time), and the messages sent on a move. The four new tests fail on main (988 passed, 4 failed; an insert at 1 then 0 gives [1, 3, 2, 0]) and pass here (992 passed) in Chromium and WebKit. Firefox does not start on my machine, so it is left to CI. eslint, prettier --check and yarn api are clean.

I also ran a randomized check against both builds, in Chromium and WebKit: 16,000 inserts, moves, removals, hides and moves between panels. On main, the DOM order differed from the layout order in 15,464 of the 32,000 checks; with this PR, in none, and each move of an attached widget sent exactly the four messages above.

Backwards-incompatible changes

None in the API. Moving a widget of a BoxPanel now takes its node out of the DOM and puts it back, with the matching messages, as Panel does. Focus inside the moved widget is lost, and an iframe inside it reloads.

AI usage

@krassowski krassowski added the bug Something isn't working label Nov 25, 2026
BoxLayout appended a new widget's node at the end of the panel and left
a moved widget's node where it was, so Tab and screen readers reached
the widgets in a different order than the panel shows them. JupyterLab's
shell inserts its menu panel at index 3 of a top-to-bottom BoxLayout in
the simple interface, and the panel ends up after the main area and the
status bar in the DOM.

attachWidget now inserts the node before the next widget's, and
moveWidget moves it there too, sending the widget detach and attach
messages around the move as PanelLayout does.
@r0c0y
r0c0y force-pushed the fix-boxlayout-dom-order branch from 60a494a to 89702ec Compare November 25, 2026 14:21
@r0c0y r0c0y changed the title Keep BoxLayout widgets in DOM order Keep BoxLayout widgets in DOM order Nov 25, 2026
@r0c0y
r0c0y marked this pull request as ready for review November 25, 2026 14:28

This branch has not been deployed

No deployments
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 this pull request may close these issues.

2 participants

0