Skip to content

Commit

Permalink
Feat: Tab 입력시 에디터 밖으로 Tabindex가 나가는 현상 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
sanoopark committed Jul 16, 2023
1 parent 0f249e7 commit a201285
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/components/common/Editor/Editor.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,23 @@ const Editor = ({ id, savedData }: EditorProps) => {
editorRef.current.render(newEditorData);
}, [editorReady, savedData]);

/** Tab을 입력했을 때 에디터 밖으로 TabIndex가 변경되는 것을 방지 */
useEffect(() => {
const isEditorFocused = editorRef.current?.blocks?.getCurrentBlockIndex() !== -1;

const handleKeyDown = (event: KeyboardEvent) => {
if (isEditorFocused && event.key === 'Tab') {
event.preventDefault();
}
};

window.addEventListener('keydown', handleKeyDown);

return () => {
window.removeEventListener('keydown', handleKeyDown);
};
}, []);

return (
<>
<div id={id} />;
Expand Down

0 comments on commit a201285

Please sign in to comment.