From 068bba178a7d3bed405112bdccd77375e88ea33e Mon Sep 17 00:00:00 2001 From: Yoon-Hae-Min Date: Tue, 27 Sep 2022 22:32:07 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20input=EC=B0=BD=EC=97=90=EC=84=9C=20ente?= =?UTF-8?q?r=EB=A5=BC=20=EB=88=84=EB=A5=BC=EC=8B=9C=EC=97=90=20=EB=8B=A4?= =?UTF-8?q?=EC=9D=8C=20input=EC=B0=BD=EC=9C=BC=EB=A1=9C=20=EC=9D=B4?= =?UTF-8?q?=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PostWriteCommonForm/PostWriteCommonForm.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/breaking-front/src/components/PostWriteCommonForm/PostWriteCommonForm.js b/breaking-front/src/components/PostWriteCommonForm/PostWriteCommonForm.js index e27eb663..86e627dc 100644 --- a/breaking-front/src/components/PostWriteCommonForm/PostWriteCommonForm.js +++ b/breaking-front/src/components/PostWriteCommonForm/PostWriteCommonForm.js @@ -28,6 +28,16 @@ const PostWriteCommonForm = ({ onChangeData, data, setData }) => { setIsShowPriceInput((pre) => !pre); }; + const nextInputFocus = (event) => { + if (event.key === 'Enter') { + event.preventDefault(); + event.target.blur(); + const form = event.target.form; + const index = Array.prototype.indexOf.call(form, event.target); + form.elements[index + 1].focus(); + } + }; + return ( <> @@ -51,6 +61,7 @@ const PostWriteCommonForm = ({ onChangeData, data, setData }) => { value={data.title} onChange={onChangeData} name="title" + onKeyDown={nextInputFocus} /> { onChange={handlePrice} onBlur={toggleShowPriceInput} onFocus={toggleShowPriceInput} - onKeyDown={(event) => { - if (event.key === 'Enter') { - event.preventDefault(); - event.target.blur(); - } - }} + onKeyDown={nextInputFocus} />