-
Notifications
You must be signed in to change notification settings - Fork 2
Avoid triggering click event on key down, and set focus on search input after submit #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
f85af6a
cefd7c7
3654c8c
fed4f78
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,11 +17,11 @@ | |
*/ | ||
|
||
import PropTypes from "prop-types"; | ||
import React, { useState } from "react"; | ||
import React, { useState, useRef } from "react"; | ||
import { useSelector, useDispatch } from "react-redux"; | ||
import _ from "lodash"; | ||
|
||
import { Search, Button } from "@carbon/react"; | ||
import { Search, Form, Button } from "@carbon/react"; | ||
|
||
import Collections from "../../components/collections"; | ||
import Retrievers from "../../components/retrievers"; | ||
|
@@ -125,6 +125,9 @@ function QuestionAnswering({ application, showSettings }) { | |
const readers = useSelector((state) => state.readers); | ||
const dispatch = useDispatch(); | ||
|
||
// Reference for search input | ||
const searchRef = useRef(null); | ||
|
||
return ( | ||
<div className="application"> | ||
<div className="application__body"> | ||
|
@@ -133,10 +136,33 @@ function QuestionAnswering({ application, showSettings }) { | |
</div> | ||
<div className="application__content"> | ||
<h4>What would you like to know?</h4> | ||
<div className="qa__input"> | ||
<Form className="qa__input" | ||
onSubmit={evt => { | ||
evt.preventDefault(); | ||
|
||
// Step 1: Set processing to true | ||
setProcessing(true); | ||
|
||
// Step 2: Trigger ask function | ||
ask( | ||
questionText, | ||
retrievers.selectedRetriever, | ||
selectedCollection, | ||
readers.selectedReader, | ||
setAnswers, | ||
setProcessing, | ||
setProcessed, | ||
dispatch | ||
); | ||
|
||
// Sets the focus on search input, accessing it through its reference | ||
searchRef.current.focus(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add a comment here (and in the similar locations in the other files) regarding functionality e.g. "Switch focus to question text field" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure. Comments added. |
||
}} | ||
> | ||
<div className="qa__input--box"> | ||
<Search | ||
id="qa__question" | ||
ref={searchRef} | ||
labelText={questionText} | ||
placeholder={strings.PLACEHOLDER_QUESTION} | ||
disabled={ | ||
|
@@ -155,20 +181,6 @@ function QuestionAnswering({ application, showSettings }) { | |
setProcessed(false); | ||
setQuestionText(event.target.value); | ||
}} | ||
onKeyDown={(event) => { | ||
if (event.key === "Enter") { | ||
ask( | ||
questionText, | ||
retrievers.selectedRetriever, | ||
selectedCollection, | ||
readers.selectedReader, | ||
setAnswers, | ||
setProcessing, | ||
setProcessed, | ||
dispatch | ||
); | ||
} | ||
}} | ||
onClick={() => { | ||
setShowSuggestedQuestions(true); | ||
}} | ||
|
@@ -205,40 +217,8 @@ function QuestionAnswering({ application, showSettings }) { | |
) : null} | ||
</div> | ||
<Button | ||
className="qa__question--submit-btn" | ||
kind="primary" | ||
onClick={() => { | ||
// Step 1: Set processing to true | ||
setProcessing(true); | ||
|
||
// Step 2: Trigger ask function | ||
ask( | ||
questionText, | ||
retrievers.selectedRetriever, | ||
selectedCollection, | ||
readers.selectedReader, | ||
setAnswers, | ||
setProcessing, | ||
setProcessed, | ||
dispatch | ||
); | ||
}} | ||
onKeyDown={() => { | ||
// Step 1: Set processing to true | ||
setProcessing(true); | ||
|
||
// Step 2: Trigger ask function | ||
ask( | ||
questionText, | ||
retrievers.selectedRetriever, | ||
selectedCollection, | ||
readers.selectedReader, | ||
setAnswers, | ||
setProcessing, | ||
setProcessed, | ||
dispatch | ||
); | ||
}} | ||
type="submit" | ||
disabled={ | ||
disabled || | ||
!retrievers.selectedRetriever || | ||
|
@@ -249,7 +229,7 @@ function QuestionAnswering({ application, showSettings }) { | |
> | ||
Ask | ||
</Button> | ||
</div> | ||
</Form> | ||
{questionText !== strings.PLACEHOLDER_QUESTION ? ( | ||
<div className="answers"> | ||
{(processing || processed) && questionText ? ( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is this code below for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a mismatch between the feature branch's base and the PR base. These changes are from acl2023_demo.