remix-run / example-trellix

A partial trello board clone with Remix
https://trellix.fly.dev
288 stars 46 forks source link

Error in onBlur Event Handling for EditableText Component #9

Open talentlessDeveloper opened 5 months ago

talentlessDeveloper commented 5 months ago

The EditableText component is currently experiencing an error when handling the onBlur event. The intended functionality is for the onBlur event to trigger fetcher.submit, but instead, it produces the following error message: "Uncaught Error: Cannot submit element that is not <form>, <button>, or <input type='submit|image'>" in the console. Additionally, fetcher.submit does not trigger unless the user presses the Enter key after typing.

Observations:

Code Snippet:

onBlur={(event) => {
  if (
    inputRef.current?.value !== value &&
    inputRef.current?.value.trim() !== ""
  ) {
    fetcher.submit(event.currentTarget);
  }
  setEdit(false);
}}

Proposed Solution:

onBlur={(event) => {
  if (
    inputRef.current?.value !== value &&
    inputRef.current?.value.trim() !== ""
  ) {
    fetcher.submit(event.currentTarget.parentElement as HTMLFormElement);
  }
  setEdit(false);
}}

Note: I'm uncertain if the current behavior aligns with the intended use of the component. I'm still learning and would appreciate clarification on whether this behavior is intentional. If it's not can I create a PR?

esvikesvik commented 2 months ago

fetcher.submit(event.currentTarget.form);