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

ShortcutRegistration#resetFocusOnActiveElement should not change text selection #7070

Open
probert94 opened this issue Jan 28, 2025 · 3 comments
Labels
enhancement New feature or request vaadin-text-field

Comments

@probert94
Copy link

Description of the bug

The ShortcutRegistration allows to reset the focus to force a ValueChangeEvent on the server so that the ShortcutListener can work with the current value.
However, if the focused field has autoselect set to true, the resetFocus selects all text. In my case a shortcut opens a dialog with predefined texts that should be inserted at the current cursor position. This is not possible at the moment.

Expected behavior

The selection should not be changed, it should only force a value change event.

Minimal reproducible example

  • Add a TextField to a webpage
  • Register a Shortcut with resetFocusOnActiveElement
  • Select part of the text and then execute the shortcut

Versions

Flow: 24.6.2
Vaadin: 24.6.2
Copilot: 24.6.2
Frontend Hotswap: Enabled, using Vite
OS: amd64 Windows 11 10.0
Java: Eclipse Adoptium 21.0.3
Browser: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36 Edg/132.0.0.0
Java Hotswap: Hotswap is not enabled
IDE Plugin: Not installed

@mshabarov
Copy link
Contributor

The desired behaviour sounds like something specific for TextField (handle component's selection on shortcut).

@mshabarov mshabarov transferred this issue from vaadin/flow Jan 28, 2025
@mshabarov mshabarov transferred this issue from vaadin/docs Jan 28, 2025
@yuriy-fix yuriy-fix added enhancement New feature or request vaadin-text-field labels Feb 6, 2025
@yuriy-fix
Copy link
Contributor

The component behaves as expected in this case, therefore considering this as an enhancement request.

@probert94
Copy link
Author

@mshabarov the problem affects all inputs and textareas and the related method resetFocus is a global method under window.Vaadin.Flow, so I don't think it can be solved in the components.

@yuriy-fix Originally the resetFocusmethod was introduced to solve this issue, so it basically only exists to force a value change event so that the server knows the current value when executing the shortcut.
If there was another method to force a value change, this method would never have been introduced. So losing the selection is, in my opinion, a negative side effect of the used solution and not the desired / expected behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request vaadin-text-field
Projects
None yet
Development

No branches or pull requests

3 participants