Open iajn opened 1 year ago
Yes, the focus should be cleared somehow before moving the front layer to the back. The only issue is that JavaFX does not provide an API for this.
I dug a little deeper into this issue and don't see anything that can be done without platform support. When one press TAB, the control that has the focus (e.g. TextField) consumes the KeyEvent so that it doesn't bubble up to its parent (the ModalPane) and calls a TraverseEngine. The algorithm passes the focus to the nearest element in the scene graph, based on distance. Like almost everything in JavaFX, it's a private API, so no tweaks allowed.
Workaround: on the show
event set focusTraversable
to false for every node in the current scene except the ModalPane and its children. Set it back to true on hide.
It's quite messy because we don't know the depth of the scene graph beforehand, so I wouldn't implement this in the control itself.
Noticed while playing around in the sampler app, when a ModalPane is visible its possible to shift the focus using tab somewhere under it and then activate buttons using spacebar. I'd imagine focus should shift only inside the dialog. Not sure if this can be limited with some existing property?
In the sampler app, its possible to lock the page UI by opening the persistent ModalPane, shifting the focus to some other button and opening a different dialog that doesn't have a close button. Update: noticed that reopening the page is still possible and it fixes the issue, so I guess its not entirely locked.