diff options
author | Nate Sesti <sestinj@gmail.com> | 2023-06-16 23:42:10 -0700 |
---|---|---|
committer | Nate Sesti <sestinj@gmail.com> | 2023-06-16 23:42:10 -0700 |
commit | 1ea00ebe40807589ffe3d688b5f2e07295864744 (patch) | |
tree | c90a54cd359807700c8ebe71764df5e44ff08ae0 /extension/react-app/src/components/TextDialog.tsx | |
parent | a1c32513082b7d94414a21827f200224dc3ff846 (diff) | |
download | sncontinue-1ea00ebe40807589ffe3d688b5f2e07295864744.tar.gz sncontinue-1ea00ebe40807589ffe3d688b5f2e07295864744.tar.bz2 sncontinue-1ea00ebe40807589ffe3d688b5f2e07295864744.zip |
polishing
Diffstat (limited to 'extension/react-app/src/components/TextDialog.tsx')
-rw-r--r-- | extension/react-app/src/components/TextDialog.tsx | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/extension/react-app/src/components/TextDialog.tsx b/extension/react-app/src/components/TextDialog.tsx index 167e12cf..31a385d5 100644 --- a/extension/react-app/src/components/TextDialog.tsx +++ b/extension/react-app/src/components/TextDialog.tsx @@ -1,5 +1,5 @@ // Write a component that displays a dialog box with a text field and a button. -import React, { useState } from "react"; +import React, { useEffect, useState } from "react"; import styled from "styled-components"; import { Button, buttonColor, secondaryDark, vscBackground } from "."; @@ -28,6 +28,10 @@ const TextArea = styled.textarea` padding: 8px; outline: 1px solid black; font-family: Arial, Helvetica, sans-serif; + + &:focus { + outline: 1px solid orange; + } `; const P = styled.p` @@ -38,19 +42,39 @@ const P = styled.p` const TextDialog = (props: { showDialog: boolean; onEnter: (text: string) => void; + onClose: () => void; }) => { const [text, setText] = useState(""); const textAreaRef = React.createRef<HTMLTextAreaElement>(); + useEffect(() => { + if (textAreaRef.current) { + textAreaRef.current.focus(); + } + }, [props.showDialog]); + return ( <DialogContainer hidden={!props.showDialog}> <Dialog> <P>Thanks for your feedback. We'll get back to you soon!</P> - <TextArea cols={50} rows={10} ref={textAreaRef}></TextArea> + <TextArea + cols={50} + rows={10} + ref={textAreaRef} + onKeyDown={(e) => { + if (e.key === "Enter" && e.metaKey && textAreaRef.current) { + props.onEnter(textAreaRef.current.value); + setText(""); + } else if (e.key === "Escape") { + props.onClose(); + } + }} + /> <Button onClick={() => { if (textAreaRef.current) { props.onEnter(textAreaRef.current.value); + setText(""); } }} > |