[Update] Config Window: DeeplAuthKey. to focus input component when edit button clicked.
This commit is contained in:
@@ -1,8 +1,9 @@
|
|||||||
import React, { useState } from "react";
|
import React, { useState, useRef, forwardRef, useImperativeHandle } from "react";
|
||||||
import styles from "./_Entry.module.scss";
|
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 [input_value, setInputValue] = useState(initialValue);
|
||||||
|
const inputRef = useRef();
|
||||||
|
|
||||||
const onChangeFunction = (e) => {
|
const onChangeFunction = (e) => {
|
||||||
setInputValue(e.currentTarget.value);
|
setInputValue(e.currentTarget.value);
|
||||||
@@ -11,6 +12,12 @@ export const _Entry = ({ width, onChange, initialValue = "" }) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
useImperativeHandle(ref, () => ({
|
||||||
|
focus: () => {
|
||||||
|
inputRef.current.focus();
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={styles.entry_container}>
|
<div className={styles.entry_container}>
|
||||||
<div
|
<div
|
||||||
@@ -18,6 +25,7 @@ export const _Entry = ({ width, onChange, initialValue = "" }) => {
|
|||||||
style={{ width }}
|
style={{ width }}
|
||||||
>
|
>
|
||||||
<input
|
<input
|
||||||
|
ref={inputRef}
|
||||||
className={styles.entry_input_area}
|
className={styles.entry_input_area}
|
||||||
value={input_value}
|
value={input_value}
|
||||||
onChange={onChangeFunction}
|
onChange={onChangeFunction}
|
||||||
@@ -25,4 +33,8 @@ export const _Entry = ({ width, onChange, initialValue = "" }) => {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
});
|
||||||
|
|
||||||
|
_Entry.displayName = "_Entry";
|
||||||
|
|
||||||
|
export { _Entry };
|
||||||
@@ -1,21 +1,21 @@
|
|||||||
import styles from "./DeeplAuthKey.module.scss";
|
import styles from "./DeeplAuthKey.module.scss";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
|
|
||||||
import clsx from "clsx";
|
import clsx from "clsx";
|
||||||
import ExternalLink from "@images/external_link.svg?react";
|
import ExternalLink from "@images/external_link.svg?react";
|
||||||
import { _Entry } from "../_atoms/_Entry";
|
import { _Entry } from "../_atoms/_Entry";
|
||||||
import { useState } from "react";
|
import { useState, useRef } from "react";
|
||||||
|
|
||||||
export const DeeplAuthKey = () => {
|
export const DeeplAuthKey = () => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const [is_editable, seIsEditable] = useState(false);
|
const [is_editable, seIsEditable] = useState(false);
|
||||||
const [input_value, seInputValue] = useState("");
|
const [input_value, seInputValue] = useState("");
|
||||||
|
const entryRef = useRef(null);
|
||||||
|
|
||||||
const revealEditAuthKey = () => {
|
const revealEditAuthKey = () => {
|
||||||
seIsEditable(true);
|
seIsEditable(true);
|
||||||
|
entryRef.current.focus();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
const onchangeEntryAuthKey = (e) => {
|
const onchangeEntryAuthKey = (e) => {
|
||||||
seInputValue(e.target.value);
|
seInputValue(e.target.value);
|
||||||
};
|
};
|
||||||
@@ -26,7 +26,7 @@ export const DeeplAuthKey = () => {
|
|||||||
return (
|
return (
|
||||||
<div className={styles.container}>
|
<div className={styles.container}>
|
||||||
<div className={styles.entry_section_wrapper}>
|
<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>
|
<button className={styles.save_button} onClick={saveAuthKey}>Save</button>
|
||||||
{is_editable
|
{is_editable
|
||||||
? null
|
? null
|
||||||
@@ -40,6 +40,7 @@ export const DeeplAuthKey = () => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
export const OpenWebpage_DeeplAuthKey = () => {
|
export const OpenWebpage_DeeplAuthKey = () => {
|
||||||
return (
|
return (
|
||||||
<div className={styles.open_webpage_button_wrapper}>
|
<div className={styles.open_webpage_button_wrapper}>
|
||||||
|
|||||||
Reference in New Issue
Block a user