[Update] Config Window: DeeplAuthKey. to focus input component when edit button clicked.

This commit is contained in:
Sakamoto Shiina
2024-08-05 07:48:01 +09:00
parent 19ef8d3226
commit 891e750a97
2 changed files with 20 additions and 7 deletions

View File

@@ -1,8 +1,9 @@
import React, { useState } from "react";
import React, { useState, useRef, forwardRef, useImperativeHandle } from "react";
import styles from "./_Entry.module.scss";
export const _Entry = ({ width, onChange, initialValue = "" }) => {
const _Entry = forwardRef(({ width, onChange, initialValue = "" }, ref) => {
const [input_value, setInputValue] = useState(initialValue);
const inputRef = useRef();
const onChangeFunction = (e) => {
setInputValue(e.currentTarget.value);
@@ -11,6 +12,12 @@ export const _Entry = ({ width, onChange, initialValue = "" }) => {
}
};
useImperativeHandle(ref, () => ({
focus: () => {
inputRef.current.focus();
}
}));
return (
<div className={styles.entry_container}>
<div
@@ -18,6 +25,7 @@ export const _Entry = ({ width, onChange, initialValue = "" }) => {
style={{ width }}
>
<input
ref={inputRef}
className={styles.entry_input_area}
value={input_value}
onChange={onChangeFunction}
@@ -25,4 +33,8 @@ export const _Entry = ({ width, onChange, initialValue = "" }) => {
</div>
</div>
);
};
});
_Entry.displayName = "_Entry";
export { _Entry };

View File

@@ -1,21 +1,21 @@
import styles from "./DeeplAuthKey.module.scss";
import { useTranslation } from "react-i18next";
import clsx from "clsx";
import ExternalLink from "@images/external_link.svg?react";
import { _Entry } from "../_atoms/_Entry";
import { useState } from "react";
import { useState, useRef } from "react";
export const DeeplAuthKey = () => {
const { t } = useTranslation();
const [is_editable, seIsEditable] = useState(false);
const [input_value, seInputValue] = useState("");
const entryRef = useRef(null);
const revealEditAuthKey = () => {
seIsEditable(true);
entryRef.current.focus();
};
const onchangeEntryAuthKey = (e) => {
seInputValue(e.target.value);
};
@@ -26,7 +26,7 @@ export const DeeplAuthKey = () => {
return (
<div className={styles.container}>
<div className={styles.entry_section_wrapper}>
<_Entry width="32rem" onChange={onchangeEntryAuthKey}/>
<_Entry ref={entryRef} width="32rem" onChange={onchangeEntryAuthKey}/>
<button className={styles.save_button} onClick={saveAuthKey}>Save</button>
{is_editable
? null
@@ -40,6 +40,7 @@ export const DeeplAuthKey = () => {
);
};
export const OpenWebpage_DeeplAuthKey = () => {
return (
<div className={styles.open_webpage_button_wrapper}>