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

Copying message copy span html instead of text #22

Closed
GhazanfarKhan opened this issue Mar 30, 2021 · 8 comments
Closed

Copying message copy span html instead of text #22

GhazanfarKhan opened this issue Mar 30, 2021 · 8 comments
Assignees
Labels
question Further information is requested

Comments

@GhazanfarKhan
Copy link

Hi, when you copy a message from message component it will copy html not the actual text. Attaching screenshot.

image

@GhazanfarKhan
Copy link
Author

image
It is accepting any html.

@GhazanfarKhan
Copy link
Author

Is there any way I can disable html pasting

@supersnager
Copy link
Contributor

supersnager commented Apr 1, 2021

@GhazanfarKhan Thank you for your question.

If you need to sanitize data pasted to <MessageInput />, you can use onPaste event handler.

Here is simple example:

  const [ value, setValue ] = useState(""); 

  return <MessageInput  onChange={(val) => setValue(val)} value={value} onPaste={(evt) => {
                evt.preventDefault();
                setValue(evt.clipboardData.getData("text"));
         }} />

Useful links:

@supersnager supersnager added the question Further information is requested label Apr 1, 2021
@supersnager supersnager self-assigned this Apr 1, 2021
@GhazanfarKhan
Copy link
Author

@supersnager thanks.

@GhazanfarKhan
Copy link
Author

Hi @supersnager

Send button is disabled when do the above steps you describe.

@GhazanfarKhan
Copy link
Author

GhazanfarKhan commented Apr 8, 2021

Hi @supersnager, send button is disabled while do pasting but when I type something it was undisabled.

@GhazanfarKhan GhazanfarKhan reopened this Apr 8, 2021
@supersnager
Copy link
Contributor

@GhazanfarKhan Internal state of a send button is tracked by onChange internal handler. Paste event, not invokes this handler.
I will think, how to deal with it when the paste event occurs.

However, as a workaround, you can use the sendDisabled property of the <MessageInput /> component to handle the state of this button yourself:

  const [ value, setValue ] = useState(""); 
  const [sendDisabled, setSendDisabled] = useState(true);
            useEffect(() => {
                setSendDisabled(value.length===0);
            },[value]);

  return <MessageInput  sendDisabled={sendDisabled} onChange={(val) => setValue(val)} value={value} onPaste={(evt) => {
                evt.preventDefault();
                setValue(evt.clipboardData.getData("text"));
         }} />

@GhazanfarKhan
Copy link
Author

Thanks for this workaround.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants