A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.
refactor(ui): add autoFocus prop for editor
robinba706266159c
diff --git a/ui/src/components/Editor/Editor.tsx b/ui/src/components/Editor/Editor.tsxindex 5c501742..520a5ac6 100644--- a/ui/src/components/Editor/Editor.tsx+++ b/ui/src/components/Editor/Editor.tsx@@ -19,6 +19,7 @@ const Editor = ({onBlur,editorPlaceholder,getEditorInstance,+ autoFocus,}) => {const elRef = useRef<HTMLDivElement>(null);const [editor, setEditor] = useState<CodeMirror.Editor | null>(null);@@ -38,6 +39,9 @@ const Editor = ({lineWrapping: true,placeholder: editorPlaceholder,});+ if (autoFocus) {+ cm.focus();+ }cm.on('change', (e) => {const newValue = e.getValue();eventRef.current?.onChange?.(newValue);diff --git a/ui/src/components/Editor/index.tsx b/ui/src/components/Editor/index.tsxindex ac775c9a..5d08706e 100644--- a/ui/src/components/Editor/index.tsx+++ b/ui/src/components/Editor/index.tsx@@ -49,10 +49,19 @@ interface Props extends EventRef {editorPlaceholder?;className?;value;+ autoFocus?: boolean;}const MDEditor: ForwardRefRenderFunction<EditorRef, Props> = (- { editorPlaceholder = '', className = '', value, onChange, onFocus, onBlur },+ {+ editorPlaceholder = '',+ className = '',+ value,+ onChange,+ onFocus,+ onBlur,+ autoFocus = false,+ },ref,) => {const [markdown, setMarkdown] = useState<string>(value || '');@@ -146,6 +155,7 @@ const MDEditor: ForwardRefRenderFunction<EditorRef, Props> = (<div className="content-wrap"><Editorvalue={markdown}+ autoFocus={autoFocus}onChange={handleChange}onFocus={handleFocus}onBlur={handleBlur}diff --git a/ui/src/pages/Questions/Detail/components/WriteAnswer/index.tsx b/ui/src/pages/Questions/Detail/components/WriteAnswer/index.tsxindex 38e4a4ae..febdb585 100644--- a/ui/src/pages/Questions/Detail/components/WriteAnswer/index.tsx+++ b/ui/src/pages/Questions/Detail/components/WriteAnswer/index.tsx@@ -100,7 +100,7 @@ const Index: FC<Props> = ({ visible = false, data, callback }) => {<div className="d-flex"><TextAreaclassName="w-100"- rows={12}+ rows={8}autoFocus={false}onFocus={handleFocusForTextArea}/>@@ -113,6 +113,7 @@ const Index: FC<Props> = ({ visible = false, data, callback }) => {focusType === 'answer' && 'focus',)}value={formData.content.value}+ autoFocusonChange={(val) => {setFormData({content: {