twitter / TwitterTextEditor

A standalone, flexible API that provides a full-featured rich text editor for iOS applications.
Apache License 2.0
2.98k stars 164 forks source link

Stop typing from keyboard #27

Open vishaldroisys opened 1 year ago

vishaldroisys commented 1 year ago

Hello,

How to stop typing from keyboard?

We have limit to stop typing from particular limit like 1500 character.

Thanks in advance.

niw commented 1 year ago

This is techinically possible, yet not recommend in terms of UI/UX standing point.

Preventing typing causes many issues for those who're using Input Method (a program that is used for typing non-English characters,) such as typing Japanese, Chinese, or other consideration is those who're using accessibility features.

The recommended implementation for such use case e.g. limiting the length of user's input is not limiting keyboard typing instead, limiting "commit" the typed text. For example, if the text is in a kind of form view, change the "Done" or "Submit" button isEnabled of the borm to not let users to commit the text if it's exceeding the limit of length. It would be also better to communicate users why they can't commit the text e.g. changing text color where the exceeded characters. You can implement such behavior by using TextEditorViewTextAttributesDelegate.