Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Element loses focus on first state change in React 18 #26

Open
pieter-berkel opened this issue Nov 10, 2022 · 5 comments
Open

Element loses focus on first state change in React 18 #26

pieter-berkel opened this issue Nov 10, 2022 · 5 comments

Comments

@pieter-berkel
Copy link

pieter-berkel commented Nov 10, 2022

When you first change the content of the element you are interrupted, as if the element loses focus. I have tested this in multiple browsers and in multiple react versions. This problem only ocurs in React 18
Codesandbox

@mechanical-turk
Copy link

i'm seeing this error on react 18.2.0. first onChange loses focus, but the following ones keep focus. Example code:

// EditableBlock.tsx

export const EditableBlock = ({
  content,
  onChange,
}: {
  content: string;
  onChange: (content: string) => void;
}) => {
  const editorRef = useRef(null);

  useEditable(editorRef, onChange);

  return <div ref={editorRef}>{content}</div>;
};
// index.tsx

export default function Home() {
  const [content, setContent] = React.useState('Hello world!');
  const onChange = useCallback((content: string) => {
    setContent(content);
    console.log({ content });
  }, []);

  return <EditableBlock content={content} onChange={onChange} />;
}

@Mihir-Karbelkar
Copy link

Is this library alive? Looking to use it in a project because it's approach looks better than react-contenteditable which doesnt really work properly with hooks

@nyacg
Copy link

nyacg commented Jul 4, 2023

I have the same issue, did anyone ever find a workaround?

@inokawa
Copy link

inokawa commented Jul 21, 2023

Hi,
https://github.com/inokawa/rich-textarea (what I made) may work in some cases.
It can style textarea with JSX.

@thijsgadiot
Copy link

Should be fixed in #29 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants