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

How to set a maxlength property for this editor ? #73

Closed
miguelangeltorresfp opened this issue Feb 5, 2020 · 2 comments
Closed

How to set a maxlength property for this editor ? #73

miguelangeltorresfp opened this issue Feb 5, 2020 · 2 comments
Labels
enhancement New feature or request

Comments

@miguelangeltorresfp
Copy link

I found this answer related to draft.js but I don't know if it would be possible to do something similar with mui-rte.

How to limit Max Length of Draft js

@niuware
Copy link
Owner

niuware commented Feb 11, 2020

Hi @miguelangeltorresfp, with the link you sent, what about disabling the input when you reach a limit?

In this example when the user writes 10 characters, the input will be disabled. The only downside is that you will need show another button to re-enable the input once the limit is reached as you won’t be able to modify the content of the editor anymore.

Anyways the max-length could be a useful feature so I will probably add it in a next release.

const [readOnly, setReadOnly] = useState(false)

...

return (
    <MUIRichTextEditor 
        onChange={(editorState) => {
            const length = editorState.getCurrentContent().getPlainText('').length
            if (length >= 10) {
                setReadOnly(true)
            }
        }}
        readOnly={readOnly}
    />
)

@niuware niuware closed this as completed Feb 11, 2020
@niuware niuware added the enhancement New feature or request label Feb 28, 2020
@niuware niuware reopened this Feb 28, 2020
@niuware
Copy link
Owner

niuware commented Mar 4, 2020

This feature was added in version 1.14.0

@niuware niuware closed this as completed Mar 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants