Skip to content

Commit 08d0a63

Browse files
committed
tauri: fix: a11y: focus being locked on message input
On Linux and macOS. Such that you'd be unable to focus anything else by using the Tab key. Closes #5097. Partially addresses #4590. This also affects Electron on all platforms and Tauri for Windows: now we will not re-focus the composer after you un-select some text in a message. This can be considered a downside, but I was not able to come up with a simple soltuion that I am sure is also good accessibility-wise. On WebKit, the `selectionchange` event fires pretty much every time something is clicked or when focus changes. Namely, it fires when the focus exits the composer, which is what caused the bug. Although this is gonna be a bit annoying for mouse users that they now have to click the composer manually after certain actions, I am afraid we can't keep the approach of always keeping it in focus by default. Instead we should only focus it only in some concrete cases, where we are sure it is appropriate. The majority of the "always keep composer in focus" code has been introduced in 199ea23 (#2007). The idea was to keep it in focus _by default_, except some specific cases: > Maybe we should rather listen for the blur event > on the composer text area and check there > if we want to give up the focus. Some other issues related to composer re-focusing: - 5dfc265. - 24510e9. - 5f54cb7. (#3313, #3286).
1 parent bbb0f3d commit 08d0a63

File tree

2 files changed

+2
-17
lines changed

2 files changed

+2
-17
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
- accessibility: don't re-announce message input (composer) after sending every message #5049
1515
- accessibility: correct `aria-posinset` for chat list #5044
1616
- don't close context menues on window resize #5418
17+
- tauri: accessibility: fix focus always being locked on the message input #5125
1718

1819
<a id="2_11_1"></a>
1920

packages/frontend/src/components/message/MessageListAndComposer.tsx

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -251,20 +251,6 @@ export default function MessageListAndComposer({ accountId, chat }: Props) {
251251
[hasOpenDialogs]
252252
)
253253

254-
const onSelectionChange = useCallback(() => {
255-
const selection = window.getSelection()
256-
257-
if (
258-
selection?.type === 'Caret' ||
259-
(selection?.type === 'Range' && selection.rangeCount > 0)
260-
)
261-
return
262-
263-
// Only one of these is actually rendered at any given moment.
264-
regularMessageInputRef.current?.focus()
265-
editMessageInputRef.current?.focus()
266-
}, [])
267-
268254
const onEscapeKeyUp = useCallback((ev: KeyboardEvent) => {
269255
if (ev.code === 'Escape') {
270256
// Only one of these is actually rendered at any given moment.
@@ -275,7 +261,6 @@ export default function MessageListAndComposer({ accountId, chat }: Props) {
275261

276262
useEffect(() => {
277263
window.addEventListener('mouseup', onMouseUp)
278-
document.addEventListener('selectionchange', onSelectionChange)
279264
window.addEventListener('keyup', onEscapeKeyUp)
280265

281266
// Only one of these is actually rendered at any given moment.
@@ -284,10 +269,9 @@ export default function MessageListAndComposer({ accountId, chat }: Props) {
284269

285270
return () => {
286271
window.removeEventListener('mouseup', onMouseUp)
287-
document.removeEventListener('selectionchange', onSelectionChange)
288272
window.removeEventListener('keyup', onEscapeKeyUp)
289273
}
290-
}, [onMouseUp, onEscapeKeyUp, onSelectionChange])
274+
}, [onMouseUp, onEscapeKeyUp])
291275

292276
const settingsStore = useSettingsStore()[0]
293277
// If you want to update this, don't forget to update

0 commit comments

Comments
 (0)