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

RichText not updating properly based on state #666

Closed
nwinger opened this issue Sep 14, 2020 · 10 comments
Closed

RichText not updating properly based on state #666

nwinger opened this issue Sep 14, 2020 · 10 comments
Labels
status:fixed-next-drop Issue will be fixed in upcoming release. type:bug
Milestone

Comments

@nwinger
Copy link

nwinger commented Sep 14, 2020

Category

[ ] Enhancement

[X] Bug

[ ] Question

Version

Please specify what version of the library you are using: [1.20.0]

Expected / Desired Behavior / Question

I expect the text to update properly whenever the onChange handler is called. Also, why do you need it to return a string, instead of just accepting the updated state as a prop?

Observed Behavior

The webpart is only updating the first keystroke. All subsequent strokes seems to be disregarded, and will not be recorded unless I click outside the webpart and then refocus by clicking inside.

Steps to Reproduce

Please try the following code snippet:

import * as React from "react";
import { RichText } from "@pnp/spfx-controls-react/lib/RichText";

const RichTextExample: React.FC = (props) => {
  const [text, setText] = React.useState("Default text");

  const onChange = (newText: string) => {
    setText(newText); 
    return newText;
  };

  return <RichText value={text} onChange={onChange} />;
};

export default RichTextExample;
@ghost
Copy link

ghost commented Sep 14, 2020

Thank you for reporting this issue. We will be triaging your incoming issue as soon as possible.

@ghost ghost added the Needs: Triage 🔍 label Sep 14, 2020
@michelsmit
Copy link

Experiencing the exact same issue, makes it hard to use now.

@vaderj
Copy link

vaderj commented Sep 16, 2020

I am also experiencing this same issue

@nbelyh
Copy link
Contributor

nbelyh commented Sep 17, 2020

I have some sort of example how to make it work at least (considering there is also another bug with the focus). Yes, I realize this is bad code, but at least something :) Another thing that could fix that is re-creating the component that contains RichText every time by adding a "key" to it (if we are talking about something like a modal dialog for example). Would be happy to hear some feedback from the maintainers/creators of the control.

import * as React from "react";
import { RichText } from "@pnp/spfx-controls-react/lib/RichText";
import { IHelloWorldProps } from "./IHelloWorldProps";

const HelloWorld = (props) => {

  const [text, setText] = React.useState("Default text");
  let [text2] = React.useState("Default text");

  const onChange = (newText: string) => {
    text2 = newText; // no "setText2" to avoid focus bug
    return newText;
  };

  return (<React.Fragment>
    {text}
    <RichText value={text2} onChange={onChange} />
    <button onClick={() => setText(text2)} >Save</button>
   </React.Fragment>);
};

export default HelloWorld;

@nbelyh
Copy link
Contributor

nbelyh commented Sep 17, 2020

Duplicate: #650

@Abderahman88
Copy link
Contributor

The property 'value' causes this weird issue. I changed it to defaultValue and it worked.

<ReactQuill ... defaultValue={text || ''} ... />

@nbelyh
Copy link
Contributor

nbelyh commented Nov 29, 2020

@Abderahman88 do you mean you changed this line?

defaultValue={text || ''} //property value causes issues, defaultValue does not

The core issue seems to be still there, looks like this fix not actually helping much.. That is, it seems taht the controlled mode (value/onChange) is simply not working with RichText control (it probably never did though). The defaultValue addresses the "uncontrolled" mode of the ReactQuill.

@Abderahman88
Copy link
Contributor

@nbelyh The controlled mode is not working. (Tested with your example)

This needs to be fixed 👍

@Abderahman88
Copy link
Contributor

Like you said, it probably never worked in controlled mode.

ReactQuill

AJIXuMuK added a commit that referenced this issue Dec 13, 2020
@AJIXuMuK
Copy link
Collaborator

Hi all,

I've made the fix. Please, check beta version.

@nbelyh @Abderahman88 @vaderj @michelsmit @nwinger

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:fixed-next-drop Issue will be fixed in upcoming release. type:bug
Projects
None yet
Development

No branches or pull requests

6 participants