sp-dev-fx-controls-react icon indicating copy to clipboard operation
sp-dev-fx-controls-react copied to clipboard

Rich text control does not allow to type in space character

Open majkelmichel opened this issue 1 year ago • 4 comments

Category

[ ] Enhancement

[x] Bug

[ ] Question

Version

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

Expected / Desired Behavior / Question

I can type in space into RichText control.

Observed Behavior

onChange callback does not fire when space key is pressed. Also pasting (CTRL+V) space character does nothing. Only way to add space is pasting text that has some text surrounding spaces.

Steps to Reproduce

SPFx version: 1.17.3 Simple SPFx Webpart. I have a button on property pane, that makes a Fluent UI Panel open. On this panel I have a RichText control. It is controlled with reducer-based state.

<Stack styles={{ root: { paddingTop: 32 } }}>
  <RichText value={item.value}
    className={"ql-active"}
    isEditMode={item.type === ECustomPropertyType.Static}
    onChange={(v) => {
        console.log("CHANGE", v); // shows that no event is fired for space
        actions.changeValue({ id: item.id, value: v }); // action that changes state through reducer
        return v;
    }} />
</Stack>

majkelmichel avatar Oct 02 '23 11:10 majkelmichel

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

ghost avatar Oct 02 '23 11:10 ghost

Thank you for submitting your first issue to this project.

github-actions[bot] avatar Oct 02 '23 11:10 github-actions[bot]

Hey @majkelmichel

Below is my sample, which works fine.

          <RichText 
            label="My rich text field" 
            value={this.state.richTextValue} 
            isEditMode={this.props.displayMode === DisplayMode.Edit} 
            onChange={this._getRichTextValue} />
          <PrimaryButton text='Reset text' onClick={() => { this.setState({ richTextValue: 'test' }); }} />

and onChange i am calling a method like this,

    private _getRichTextValue(v: string) {
      console.log('value:', v);
      this.setState({ richTextValue: v });
      return v;
    }

and below are the logs from console.

image

Will you be able to try this approach and let me know if this is working for you.

Thanks, Nishkalank

NishkalankBezawada avatar Oct 02 '23 14:10 NishkalankBezawada

Hi @NishkalankBezawada I think I have found the problem. Please look at sample component below:

import * as React from 'react';
import { useState } from 'react';
import { RichText } from "@pnp/spfx-controls-react/lib/controls/richText";
import { DetailsList, IColumn, SelectionMode } from "office-ui-fabric-react";

export default function RichTextBug(): JSX.Element {
    const [value, setValue] = useState("");

    const columns: IColumn[] = [
        {
            key: "richtext",
            name: "Rich Text",
            fieldName: "rich-text",
            minWidth: 200,
            onRender: () => (
                <RichText value={value} isEditMode={true} onChange={(v) => {
                    console.log("VALUE", v); // ! space is not registered because DetailsList stop propagation of keydown event
                    setValue(v);
                    return v;
                }}
                />
            )
        }
    ];

    return (
        <DetailsList items={[1]} columns={columns} selectionMode={SelectionMode.none} />
    );
}

keydown event is also used in DetailsList component for selecting rows. I believe this might somehow interfere with RichText component. I think that, when RichText is selected it should always receive that event, but it does not. For example TextField component works completly normal and is unaffected by being placed within DetailsList

majkelmichel avatar Oct 03 '23 08:10 majkelmichel