fix(chat-input) Autofocus when sending private message (#13400)

This commit is contained in:
Robert Pintilii
2023-06-07 09:27:49 +03:00
committed by GitHub
parent c1573057df
commit 8565208d30

View File

@@ -22,6 +22,11 @@ interface IProps extends WithTranslation {
*/
_areSmileysDisabled: boolean;
/**
* The id of the message recipient, if any.
*/
_privateMessageRecipientId?: string;
/**
* Invoked to send chat messages.
*/
@@ -95,6 +100,17 @@ class ChatInput extends Component<IProps, IState> {
}
}
/**
* Implements {@code Component#componentDidUpdate}.
*
* @inheritdoc
*/
componentDidUpdate(prevProps: Readonly<IProps>) {
if (prevProps._privateMessageRecipientId !== this.props._privateMessageRecipientId) {
this._textArea?.current?.focus();
}
}
/**
* Implements React's {@link Component#render()}.
*
@@ -255,8 +271,11 @@ class ChatInput extends Component<IProps, IState> {
* }}
*/
const mapStateToProps = (state: IReduxState) => {
const { privateMessageRecipient } = state['features/chat'];
return {
_areSmileysDisabled: areSmileysDisabled(state)
_areSmileysDisabled: areSmileysDisabled(state),
_privateMessageRecipientId: privateMessageRecipient?.id
};
};