- π΅πΉPortugal dxvargas
When a user opens the messages page (/private-messages), the Reply textarea gets the autofocus.
My first suggestion is that the behavior should be the same, no matter we click in an item in the Inbox or we open /private-messages.Usually the Reply textarea is next to the last received message. Receiving the focus seems acceptable.
But we can imagine, if there are several new messages, the user should see, in first place, the oldest of the new ones.
For this, we could add a class "private-message-unread" to unread messages. Then it is easy to focus the one we want. - π·π΄Romania claudiu.cristea Arad π·π΄
Everything goes first to 4.x and, tentatively, to 3.0.x
- π·π΄Romania claudiu.cristea Arad π·π΄
Let's clarify the scope
But we can imagine, if there are several new messages, the user should see, in first place, the oldest of the new ones.
If you have lots of unread messages and scroll to the oldest unread, the reply box will pe pushed down, out of the screen and it makes no sense to focus on that. We can either (a) focus on reply and scroll to latest or (b) scroll to oldest unread and not focus the reply area. I was looking o how popular messengers are working. Every time they are scrolling to latest and are focusing the reply. Let's go with (a)
- π¬π·Greece idimopoulos
idimopoulos β made their first commit to this issueβs fork.
- π¬π·Greece idimopoulos
There is a bit more to this than meets the eye.
I "fixed" the initial request and then updated the InboxBlockTest to try and ensure that the thing works fine and is tested.Unfortunately, the test would pass even without the "fix".
Looking into it through the selenium at port :7900, it seems that the test does not install the filter module, thus, a plain text appears in the default add message form in the tests.
The thing though, is that, the setting for autofocusing the message field, actually works fine. Because by default, it sets the focus to the field every time the DOM element is loaded (so it works with AJAX requests too out of the box).On the other hand, if filter module is enabled, the field is hidden from display as the ckeditor5.js replaces it.
The problem is that focusing the `[autofocus]` element, does not really help because the cursor is not placed within the box ready to type a message.
Furthermore, by the time the new thread is inserted, the ckeditor JS is not triggered yet, thus we cannot simply try to focus the ck editor field.
From my browser console I was able to do it, so it is possible to focus, but not at the moment the thread is inserted.Now, CKEditor does offer events to handle when that happens and you can do something like
CKEditor5.on('instanceReady', (event, editor) => { // Set the editor to be focused when the CKEditor is ready. editor.editing.view.focus(); });
Or even
CKEditor5.on('instanceReady', (event, editor) => { // Set the editor to be focused when the CKEditor is ready. editor.editing.view.focus(); });
but there are 2 problems:
1. The CKEditor as I noted, is launched after the private message JS. So we would need to do something about it afterwards.
2. CKEditor offers 2 events. On load and on instanceReady. The first is thrown when the library is ready and the second when ANY instance is ready. So I would assume that the second is the one we want. However, it is launched whenever ANY instance is ready. That means, that if for some reason, the site owner had a different editor somewhere in the page (let's say for example a contact form on the bottom of the page), we would not know which one to focus and IF we should re-focus on launch event.The way I see it, we would need to have the private message manually initialize CKEditor5 IF it is enabled AND THEN focus it.
- π¬π·Greece idimopoulos
I ended up creating https://www.drupal.org/project/drupal/issues/3494327 π CKEditor5 should respect the autofocus attribute of a textarea Active for this issue as it seems a CKEditor issue rather than the private_message's module.
It might be that this can be closed (?). - π΅π±Poland alorenc Wolsztyn, π΅π±
The patch from #3494327 functions correctly for me.
When I click on a thread within the inbox block, the message editor receives focus, and the interface automatically scrolls down to this element. - π΅π±Poland alorenc Wolsztyn, π΅π±
I think we can close this ticket. @drupalfan2 Are you ok with it?
- π·π΄Romania claudiu.cristea Arad π·π΄
Closing as the CKEditor is solved in π CKEditor5 should respect the autofocus attribute of a textarea Active and with plain text it just works.