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

ModalPane allows focus to escape under it #63

Open
iajn opened this issue Jul 1, 2023 · 2 comments
Open

ModalPane allows focus to escape under it #63

iajn opened this issue Jul 1, 2023 · 2 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@iajn
Copy link

iajn commented Jul 1, 2023

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.

@mkpaz
Copy link
Owner

mkpaz commented Jul 20, 2023

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.

@mkpaz mkpaz added the bug Something isn't working label Jul 20, 2023
@mkpaz
Copy link
Owner

mkpaz commented Aug 12, 2024

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.

@mkpaz mkpaz added the help wanted Extra attention is needed label Aug 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants