Skip to content

Commit

Permalink
ComposeBox [nfc]: Move setFocusState call to top of function
Browse files Browse the repository at this point in the history
Following the pattern of handleMessageBlur, handleTopicFocus, and
handleTopicBlur.
  • Loading branch information
chrisbobbe committed Apr 27, 2023
1 parent 6850deb commit 60fc376
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/compose/ComposeBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -484,18 +484,18 @@ const ComposeBox: React$AbstractComponent<Props, ImperativeHandle> = forwardRef(
);

const handleMessageFocus = useCallback(() => {
setFocusState(state => ({ ...state, message: true, either: true }));
if (
!isEditing
&& isStreamNarrow(narrow)
&& !focusState.either
&& !focusState.either // not affected by setFocusState above; React state is set asynchronously
&& topicInputState.value === ''
) {
// We weren't showing the topic input when the user tapped on the input
// to focus it, but we're about to show it. Focus that, if the user
// hasn't already selected a topic.
topicInputRef.current?.focus();
}
setFocusState(state => ({ ...state, message: true, either: true }));
}, [isEditing, narrow, focusState.either, topicInputState.value, topicInputRef]);

const handleMessageBlur = useCallback(() => {
Expand Down

0 comments on commit 60fc376

Please sign in to comment.