Focus co-author input after clicking on "Add co-authors"

This commit is contained in:
Sergio Padrino 2021-02-18 14:02:41 +01:00
parent 479c6a7609
commit 4021fc138d
2 changed files with 15 additions and 0 deletions

View file

@ -121,6 +121,8 @@ export class CommitMessage extends React.Component<
private descriptionTextArea: HTMLTextAreaElement | null = null
private descriptionTextAreaScrollDebounceId: number | null = null
private coAuthorInputRef = React.createRef<AuthorInput>()
public constructor(props: ICommitMessageProps) {
super(props)
const { commitMessage } = this.props
@ -180,6 +182,14 @@ export class CommitMessage extends React.Component<
if (this.props.focusCommitMessage) {
this.focusSummary()
} else if (
prevProps.showCoAuthoredBy === false &&
this.isCoAuthorInputVisible &&
// The co-author input could be also shown when switching between repos,
// but in that case we don't want to give the focus to the input.
prevProps.repository.id === this.props.repository.id
) {
this.coAuthorInputRef.current?.focus()
}
}
@ -344,6 +354,7 @@ export class CommitMessage extends React.Component<
return (
<AuthorInput
ref={this.coAuthorInputRef}
onAuthorsUpdated={this.onCoAuthorsUpdated}
authors={this.props.coAuthors}
autoCompleteProvider={autocompletionProvider}

View file

@ -467,6 +467,10 @@ export class AuthorInput extends React.Component<IAuthorInputProps, {}> {
this.state = {}
}
public focus() {
this.editor?.focus()
}
public componentWillUnmount() {
// Sometimes the completion box seems to fail to register
// the blur event and close. It's hard to reproduce so