Add API to control spell checkers and other platform-provided text input assistants
#2,805 opened on Sep 1, 2024
Repository metrics
- Stars
- (3,615 stars)
- PR merge metrics
- (Avg merge 1d 10h) (47 merged PRs in 30d)
Description
What is the problem or limitation you are having?
It is common for test input fields to have spellcheck helpers, especially on mobile platforms. This is extremely useful when the input is human-readable text, but if an input is something like an input of a family name, or ID number, or anything else that is decidedly not a natural language word, red underlined words and spell check corrections can be something between an annoyance and an active hindrance.
Describe the solution you'd like
TextInput and MultilineTextInput should have a mechanism to disable auto spell check and other automatic content modification behaviors.
We should add the following boolean flags to both widgets:
spell_checking(to disable spell checkers)smart_quotes(to disable smart quote and em-dash expansions)
If a platform doesn't provide the feature at all, the feature should be ignored (and documented as such as a platform quirk).
Describe alternatives you've considered
In the process of implementing this, we should keep an eye out for other "text modification" features that might be worth exposing as similar boolean flags. However, a fix incorporating only these two flags is sufficient.
Additional context
Originally reported as #2801.
#3546 reported the issue with smart quote handling.
In that ticket, @rmartin16 provided the functional implementation for Android:
text_input = toga.TextInput()
if toga.platform.current_platform == "android":
from android.text import InputType
text_input._impl.native.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS)
The InputType enum seems to have a number of other options that can be disabled.
iOS provides spellCheckingType, autocorrectionType and a number of other properties for configuration automated tools.