Skip to content

Commit

Permalink
v0.3.3 allow confirm button trigger submit flow
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaoyao91 committed Sep 26, 2019
1 parent 0f123b5 commit 8da427b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-bootstrap-easy-dialog",
"version": "0.3.2",
"version": "0.3.3",
"description": "React Bootstrap Dialog made easy",
"keywords": [
"react-bootstrap",
Expand Down
24 changes: 15 additions & 9 deletions src/Dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ export function DialogUI({

const [inputValue, setInputValue] = useState("");
const inputRef = useRef();
const submitButtonRef = useRef();

// only set input value to default value when it shows up
useEffect(() => {
Expand Down Expand Up @@ -196,7 +197,11 @@ export function DialogUI({
}

function handleConfirm() {
onConfirm(inputValue);
if (submitButtonRef.current) {
submitButtonRef.current.click();
} else {
onConfirm();
}
}

function handleHide() {
Expand Down Expand Up @@ -233,14 +238,15 @@ export function DialogUI({
)}
{input && (
<Form onSubmit={handleSubmit}>
{input && (
<Form.Control
{...otherInputProps}
value={inputValue}
onChange={handleInputValueChange}
{...{ [refKey]: inputRef }}
/>
)}
<Form.Control
{...otherInputProps}
value={inputValue}
onChange={handleInputValueChange}
{...{ [refKey]: inputRef }}
/>
<Button type="submit" hidden ref={submitButtonRef}>
Submit
</Button>
</Form>
)}
</Modal.Body>
Expand Down

0 comments on commit 8da427b

Please sign in to comment.