-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Focus on composition area when pressing a key #4998
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -357,6 +357,37 @@ export const CompositionArea = ({ | |||||||||||||||||
}; | ||||||||||||||||||
}, [setLarge]); | ||||||||||||||||||
|
||||||||||||||||||
// Listen to any key in the conversation panel to | ||||||||||||||||||
React.useEffect(() => { | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||
const handler = (e: KeyboardEvent) => { | ||||||||||||||||||
const { key } = e; | ||||||||||||||||||
|
||||||||||||||||||
// We don't want to react to a control character | ||||||||||||||||||
if (key.length !== 1) { | ||||||||||||||||||
return; | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
// We don't want to switch focus if another panel is up | ||||||||||||||||||
const panels = document.querySelectorAll('.conversation .panel'); | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also these kind of class lookups are brittle, if we ever change There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this information already saved in a Redux store somewhere? Or are you implying that it should be added? (And if you're suggesting it be added, where would be your suggestion for where to add this?) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, seems like this already has precedent in the codebase: Signal-Desktop/ts/components/stickers/StickerButton.tsx Lines 193 to 196 in 6700d2f
Maybe refactoring this could be done in a different PR? |
||||||||||||||||||
if (panels && panels.length > 1) { | ||||||||||||||||||
return; | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
// We don't want to take focus away of input fields | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Clarity:
Suggested change
|
||||||||||||||||||
const { activeElement } = document; | ||||||||||||||||||
if (activeElement?.nodeName.toLowerCase() === 'input') { | ||||||||||||||||||
Comment on lines
+377
to
+378
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style: Avoid extra identifier in scope
Suggested change
|
||||||||||||||||||
return; | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
inputApiRef.current?.focus(); | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this use the If yes, then:
Suggested change
|
||||||||||||||||||
}; | ||||||||||||||||||
|
||||||||||||||||||
document.addEventListener('keydown', handler); | ||||||||||||||||||
return () => { | ||||||||||||||||||
document.removeEventListener('keydown', handler); | ||||||||||||||||||
}; | ||||||||||||||||||
Comment on lines
+385
to
+388
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Surfacing @josh-signal's comment here in a conversation:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @josh-signal to be clear, you're suggesting this change?
Suggested change
Not sure if this will work, but at least it's a starting place for the conversation. |
||||||||||||||||||
}); | ||||||||||||||||||
|
||||||||||||||||||
if ( | ||||||||||||||||||
isBlocked || | ||||||||||||||||||
areWePending || | ||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.