Skip to content

Commit

Permalink
Moves a focus check on the higher level
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeyZhukovsky committed Sep 12, 2024
1 parent a4398ed commit d81551d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
16 changes: 5 additions & 11 deletions components/ai_chat/resources/page/components/input_box/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,13 @@ type Props = Pick<AIChatContext,
| 'isToolsMenuOpen'
| 'setIsToolsMenuOpen'
| 'isMobile'
| 'hasInitialHistory'
| 'shouldDisableUserInput'
| 'hasAcceptedAgreement'
| 'handleShowSoftKeyboard'>
| 'hasAcceptedAgreement'>

interface InputBoxProps {
context: Props
onFocusInputMobile?: () => unknown
maybeShowSoftKeyboard?: (querySubmitted: boolean) => unknown
}

function InputBox(props: InputBoxProps) {
Expand Down Expand Up @@ -86,16 +85,11 @@ function InputBox(props: InputBoxProps) {
return
}

if (props.context.selectedActionType) {
if (props.context.selectedActionType ||
props.maybeShowSoftKeyboard &&
props.maybeShowSoftKeyboard(querySubmitted.current)) {
node.focus()
}
if (props.context.isMobile && props.context.hasAcceptedAgreement &&
!props.context.hasInitialHistory && !querySubmitted.current) {
node.focus()
if (props.context.handleShowSoftKeyboard) {
props.context.handleShowSoftKeyboard();
}
}
}

return (
Expand Down
12 changes: 12 additions & 0 deletions components/ai_chat/resources/page/components/main/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,17 @@ function Main() {
}
}

const maybeShowSoftKeyboard = (querySubmitted: boolean) => {
if (context.isMobile && context.hasAcceptedAgreement &&
!context.hasInitialHistory && !querySubmitted) {
if (context.handleShowSoftKeyboard) {
context.handleShowSoftKeyboard()
return true
}
}
return false
}

return (
<main className={styles.main}>
{context.showAgreementModal && <PrivacyMessage />}
Expand Down Expand Up @@ -273,6 +284,7 @@ function Main() {
<InputBox
context={context}
onFocusInputMobile={handleOnFocusInputMobile}
maybeShowSoftKeyboard={maybeShowSoftKeyboard}
/>
</ToolsButtonMenu>
</div>
Expand Down

0 comments on commit d81551d

Please sign in to comment.