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

Support of Enter key and Shift-Enter key in Editors #531

Open
mhandsteiner opened this issue Dec 12, 2024 · 0 comments
Open

Support of Enter key and Shift-Enter key in Editors #531

mhandsteiner opened this issue Dec 12, 2024 · 0 comments
Assignees
Milestone

Comments

@mhandsteiner
Copy link
Contributor

In editors the enter/shift-enter key should act like the tab/shift-tab key, to store current value and focus the next/ previous element.
There is the following java/ javascript code in vaadin to detect the next/ previous element, and giving them the focus.
The javascript part is most possibly similar in react to detect all focusable elements.

if (et.hasTagName("input") && target.getWidget().getElement().getClassName().contains(" editor ") && event.getKeyCode() == 13)
{
     Element next = getNextFocusElement(Document.get(), et, event.getShiftKey());
     if (next != null)
     {
         next.focus();
     }
}
private static native Element getNextFocusElement(Document doc, Element elem, boolean previous)
/*-{
    var focusable = Array.prototype.filter.call(
        doc.querySelectorAll('a:not([disabled]), button:not([disabled]), input:not([disabled]), textarea:not([disabled]), [tabindex]:not([disabled]):not([tabindex="-1"]:not([tabindex="-2"])'),
        function (element) {
            return (element.offsetWidth > 0 || element.offsetHeight > 0) && element.tabIndex >= 0;
        }
    );
    
    var index = focusable.indexOf(elem);
    if (index < 0)
    {
        return null;
    }
    else if (previous)
    {
        if (index == 0)
        {
            return focusable[focusable.length - 1];
        }
        else
        {
            return focusable[index - 1];
        }
    }
    else
    {
        if (index < focusable.length - 1)
        {
            return focusable[index + 1];
        }
        else
        {
            return focusable[0];
        }
    }
}-*/;
@rjahn rjahn added this to the 2.6 milestone Dec 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants