fix: properly type send message input reference

this means we are properly typed for the composition mentions input and the paste handler
pull/3083/head
William Grant 11 months ago
parent db7fba0dc1
commit 1a13839d9d

@ -243,10 +243,10 @@ const StyledSendMessageInput = styled.div<{ dir?: HTMLDirection }>`
class CompositionBoxInner extends Component<Props, State> { class CompositionBoxInner extends Component<Props, State> {
private readonly textarea: RefObject<any>; private readonly textarea: RefObject<any>;
private readonly fileInput: RefObject<HTMLInputElement>; private readonly fileInput: RefObject<HTMLInputElement>;
private container: RefObject<HTMLDivElement>;
private readonly emojiPanel: RefObject<HTMLDivElement>; private readonly emojiPanel: RefObject<HTMLDivElement>;
private readonly emojiPanelButton: any; private readonly emojiPanelButton: any;
private linkPreviewAbortController?: AbortController; private linkPreviewAbortController?: AbortController;
private container: HTMLDivElement | null;
constructor(props: Props) { constructor(props: Props) {
super(props); super(props);
@ -254,8 +254,8 @@ class CompositionBoxInner extends Component<Props, State> {
this.textarea = createRef(); this.textarea = createRef();
this.fileInput = createRef(); this.fileInput = createRef();
this.container = createRef();
this.container = null;
// Emojis // Emojis
this.emojiPanel = createRef(); this.emojiPanel = createRef();
this.emojiPanelButton = createRef(); this.emojiPanelButton = createRef();
@ -265,17 +265,17 @@ class CompositionBoxInner extends Component<Props, State> {
public componentDidMount() { public componentDidMount() {
setTimeout(this.focusCompositionBox, 500); setTimeout(this.focusCompositionBox, 500);
if (this.container.current) {
const div = this.container; this.container.current.addEventListener('paste', this.handlePaste);
div?.addEventListener('paste', this.handlePaste); }
} }
public componentWillUnmount() { public componentWillUnmount() {
this.linkPreviewAbortController?.abort(); this.linkPreviewAbortController?.abort();
this.linkPreviewAbortController = undefined; this.linkPreviewAbortController = undefined;
if (this.container.current) {
const div = this.container; this.container.current.removeEventListener('paste', this.handlePaste);
div?.removeEventListener('paste', this.handlePaste); }
} }
public componentDidUpdate(prevProps: Props, _prevState: State) { public componentDidUpdate(prevProps: Props, _prevState: State) {
@ -414,9 +414,7 @@ class CompositionBoxInner extends Component<Props, State> {
role="main" role="main"
dir={this.props.htmlDirection} dir={this.props.htmlDirection}
onClick={this.focusCompositionBox} // used to focus on the textarea when clicking in its container onClick={this.focusCompositionBox} // used to focus on the textarea when clicking in its container
ref={el => { ref={this.container}
this.container = el;
}}
data-testid="message-input" data-testid="message-input"
> >
<CompositionTextArea <CompositionTextArea

@ -39,7 +39,7 @@ const sendMessageStyle = (dir?: HTMLDirection) => {
type Props = { type Props = {
draft: string; draft: string;
setDraft: (draft: string) => void; setDraft: (draft: string) => void;
container: HTMLDivElement | null; container: RefObject<HTMLDivElement>;
textAreaRef: RefObject<HTMLTextAreaElement>; textAreaRef: RefObject<HTMLTextAreaElement>;
fetchUsersForGroup: (query: string, callback: (data: any) => void) => void; fetchUsersForGroup: (query: string, callback: (data: any) => void) => void;
typingEnabled: boolean; typingEnabled: boolean;
@ -123,7 +123,7 @@ export const CompositionTextArea = (props: Props) => {
rows={1} rows={1}
data-testid="message-input-text-area" data-testid="message-input-text-area"
style={style} style={style}
suggestionsPortalHost={container as any} suggestionsPortalHost={container.current || undefined}
forceSuggestionsAboveCursor={true} // force mentions to be rendered on top of the cursor, this is working with a fork of react-mentions for now forceSuggestionsAboveCursor={true} // force mentions to be rendered on top of the cursor, this is working with a fork of react-mentions for now
> >
<Mention <Mention

Loading…
Cancel
Save