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

Updating contentEditable div fails if it is empty #48

Open
centsi opened this issue Oct 26, 2022 · 1 comment
Open

Updating contentEditable div fails if it is empty #48

centsi opened this issue Oct 26, 2022 · 1 comment

Comments

@centsi
Copy link

centsi commented Oct 26, 2022

Hi, I'm finding mobx-jsx so much easier to use than React - thank you.

I do have a problem with using a contentEditable div however - when the div becomes empty by the user deleting its contents it ceases to update from changes elsewhere and generates an error (I excluded the rest of the stack trace as I suspect it isn't needed):

[mobx] uncaught error in 'Reaction[Autorun]' TypeError: Cannot set properties of null (setting 'data') at insertExpression (mobx-jsx.js:775:42)

This is a trimmed down version of the code that causes it:

export function Editable(){
    Data.amount = 25;
    return <div
        contentEditable
        onInput={e=>Data.amount=e.target.innerText}>{Data.amount}</div>
}

Is there a way to prevent that happening? As for my purposes using a contentEditable div is so much nicer than using an input - mostly due to how difficult it is to make an input exactly fit its contents.

Thanks - Lawrence

@centsi
Copy link
Author

centsi commented Oct 27, 2022

In case it wasn't clear, the error occurs when deleting all of the text from that div (25) in the code above.

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

1 participant