Fix commentCreate focus and blur issues
This commit is contained in:
parent
63cc5da092
commit
5c028fea7f
3 changed files with 9 additions and 6 deletions
|
@ -156,9 +156,6 @@ export function CommentCreate(props: Props) {
|
||||||
setCommentValue(
|
setCommentValue(
|
||||||
commentValue + (commentValue && commentValue.charAt(commentValue.length - 1) !== ' ' ? ` ${emote} ` : `${emote} `)
|
commentValue + (commentValue && commentValue.charAt(commentValue.length - 1) !== ' ' ? ` ${emote} ` : `${emote} `)
|
||||||
);
|
);
|
||||||
|
|
||||||
const inputRef = formFieldRef && formFieldRef.current && formFieldRef.current.input && formFieldRef.current.input;
|
|
||||||
if (inputRef && inputRef.current) inputRef.current.focus();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleSelectTipComment(tab: string) {
|
function handleSelectTipComment(tab: string) {
|
||||||
|
|
|
@ -313,7 +313,11 @@ export class FormField extends React.PureComponent<Props, State> {
|
||||||
isLivestream={isLivestream}
|
isLivestream={isLivestream}
|
||||||
toggleSelectors={
|
toggleSelectors={
|
||||||
setShowSelectors && showSelectors
|
setShowSelectors && showSelectors
|
||||||
? () => setShowSelectors({ tab: showSelectors.tab || undefined, open: !showSelectors.open })
|
? () => {
|
||||||
|
const input = this.input.current;
|
||||||
|
if (!showSelectors.open && input) input.blur();
|
||||||
|
setShowSelectors({ tab: showSelectors.tab || undefined, open: !showSelectors.open });
|
||||||
|
}
|
||||||
: undefined
|
: undefined
|
||||||
}
|
}
|
||||||
handleTip={handleTip}
|
handleTip={handleTip}
|
||||||
|
@ -328,7 +332,7 @@ export class FormField extends React.PureComponent<Props, State> {
|
||||||
handlePreventClick={
|
handlePreventClick={
|
||||||
!this.state.drawerOpen ? () => this.setState({ drawerOpen: true }) : undefined
|
!this.state.drawerOpen ? () => this.setState({ drawerOpen: true }) : undefined
|
||||||
}
|
}
|
||||||
autoFocus={this.state.drawerOpen}
|
autoFocus={this.state.drawerOpen && (!showSelectors || !showSelectors.open)}
|
||||||
submitButtonRef={submitButtonRef}
|
submitButtonRef={submitButtonRef}
|
||||||
/>
|
/>
|
||||||
</React.Suspense>
|
</React.Suspense>
|
||||||
|
|
|
@ -308,7 +308,9 @@ export default function TextareaWithSuggestions(props: Props) {
|
||||||
inputElement.focus();
|
inputElement.focus();
|
||||||
if (messageValue) inputElement.setSelectionRange(messageValue.length, messageValue.length);
|
if (messageValue) inputElement.setSelectionRange(messageValue.length, messageValue.length);
|
||||||
}
|
}
|
||||||
}, [autoFocus, inputRef, messageValue]);
|
// do NOT listen to messageValue change, otherwise will autofocus while typing
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
}, [autoFocus, inputRef]);
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
if (!isMention) return;
|
if (!isMention) return;
|
||||||
|
|
Loading…
Reference in a new issue