flow-components icon indicating copy to clipboard operation
flow-components copied to clipboard

MessageInput is not implementing Focusable.

Open samie opened this issue 1 year ago • 3 comments

Description

This is clearly an oversight from the Java implementation. Similar to TextField the MessageInput should be implementing Focusable.

Expected outcome

messageList.focus(); should work

Minimal reproducible example

MessageInput message = new MessageInput(); message.focus();

Steps to reproduce

Any Vaadin 24 application.

Environment

Vaadin version(s): OS: All

Browsers

No response

samie avatar Apr 24 '24 15:04 samie

Note: this would require change in the web component as calling .focus() on vaadin-message-input currently does nothing. The actual focusable element is not the vaadin-message-input itself but the vaadin-text-area inside it.

web-padawan avatar Apr 25 '24 06:04 web-padawan

How does the hierarchical focus work? Or how should it work?

There are two focusable elements in this composite component: vaadin-text-area and vaadin-button and optimally it would be good to have programmatic control to focus either of them (as well as the composite).

Of course if the client-side control is not planned/needed, this could be just implemented in the Java API.

samie avatar Apr 26 '24 19:04 samie

We also have this problem of two focusable elements in vaadin-date-time-picker and in that case, calling focus() always focuses the date-picker. I think that in this case, it should focus vaadin-text-area. I will create a PR to handle this.

web-padawan avatar Apr 29 '24 07:04 web-padawan

In the meantime, this is the workaround that I'm using. I'm not sure why simply focus() does not move the focus ring to vaadin-text-area, and calling _setFocused() is needed.

    /* Implement focus to MessageInput. */
    public static class FocusableMessageInput extends MessageInput implements Focusable<MessageInput> {

        @Override
        public void focus() {
            Element element = this.getElement();
            element.executeJs("setTimeout(function(){var e = $0.querySelector('vaadin-text-area'); e.focus(); e._setFocused();},0)", new Serializable[]{element});
        }
    }

samie avatar May 21 '24 13:05 samie