Skip to content

contentEditable with Controller and onChange #10385

Closed Answered by Southclaws
Southclaws asked this question in Q&A
Discussion options

You must be logged in to vote

Alright, time for the solution!

Non-form contentEditable elements do not fire onChange so you can't just pass {...field} from the Controller render props:

<Controller
            render={({ field }) => {
              return (
                <Input
                  as="span"
                  contentEditable
                  {...field}
                />
              );
            }}
            control={control}
            name="title"
          />

Because there is no onChange event for a span element - that makes no sense in normal circumstances since it's just a static span element.

However, there is an onInput event which fires for input from keyboard, mouse, emojis, clipboard, …

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@polooner
Comment options

@Southclaws
Comment options

@Southclaws
Comment options

Answer selected by Southclaws
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants