question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Rich Text focus disapppear

See original GitHub issue

Thank you for reporting an issue, suggesting an enhancement, or asking a question. We appreciate your feedback - to help the team understand your needs please complete the below template to ensure we have the details to help. Thanks!

Please check out the documentation to see if your question is already addressed there. This will help us ensure our documentation is up to date.

Category

[ ] Enhancement

[x] Bug

[ ] Question

Version

1.13.0-beta.892b624

Expected / Desired Behavior / Question

focus not disappear

Observed Behavior

focus disappear after enter one symbol

Steps to Reproduce

basic setState usage

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

export default class HelloWorld extends React.Component<IHelloWorldProps, { value: string }> {
    constructor(props: IHelloWorldProps) {
        super(props);
        this.state = {
            value: ''
        };
    }
    private onChange = (value: string) => {
        this.setState({ value });
        return value;
    }
    public render(): React.ReactElement<IHelloWorldProps> {
        return (
            <div><RichText value={this.state.value} onChange={(text) => this.onChange(text)} /></div>
        );
    }
}

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

6reactions
estruyfcommented, Apr 24, 2019

As you are storing the value back to the state of your web part, it will re-render the HTML. That is why you lose focus. You can also store the value as a private variable in your component. That will not trigger a re-render.

2reactions
Katli95commented, May 10, 2019

Thanks for the answers guys,

@kirillstarlight Your method worked for me. I duplicated the value in the constructor and used that as the value for the control and updated the state of the parent with onChange. This however feels fairly dirty and I’d much rather prefer some form of .focus() accessor for the control or have it support statefull components 😕

(I tried getting the quill editor via reference and focusing that but it didn’t work) i.e.

// RichTextReference being a reference to this control
RichTextReference.getEditor().focus()
//Resulted in persisting the focus border around the control but didn't facilitate input
Read more comments on GitHub >

github_iconTop Results From Across the Web

Javascript rich text editor, contenteditable area loses focus ...
Well the focus moves to the button so you need to cancel the click action so the focus is not lost in the...
Read more >
Rich Text Editor: leaving focus does not kill onsc...
Rich Text Editor: leaving focus does not kill onscreen phone keyboard ... some text; I tap on the icon, but the keyboard DOESN'T...
Read more >
DynamicForm RichText Field losing focus on typing #1024
Using the DynamicForm component with a RichText field should not lose focus when typing in the rich text field.
Read more >
Trigger Save when Rich Text Editor loses focus or before the ...
I would like to use the Rich Text Editor with no save button. ... and then navigate away or close the browser and...
Read more >
RadRichTextBox gets focus but does not display cursor and ...
Hi Andrew, We have logged an issue that the caret inside the document disappears but the focus remains in the control and users...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found