Skip to content

Commit c178b8a

Browse files
committed
feat: add hidesuggestions property to textbox
1 parent 6b812c8 commit c178b8a

File tree

4 files changed

+50
-2
lines changed

4 files changed

+50
-2
lines changed

samples/ControlCatalog/Pages/TextBoxPage.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
UseFloatingWatermark="True"
3939
PasswordChar="*"
4040
Text="Password" />
41+
<TextBox Width="200" Watermark="Hide suggestions" TextInputOptions.HideSuggestions="True" />
4142
<TextBox Width="200" Text="Left aligned text" TextAlignment="Left" AcceptsTab="True" />
4243
<TextBox Width="200" Text="Center aligned text" TextAlignment="Center" />
4344
<TextBox Width="200" Text="Right aligned text" TextAlignment="Right" />

src/Android/Avalonia.Android/Platform/Input/AndroidInputMethod.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,9 @@ public void SetOptions(TextInputOptions options)
172172
if (options.Multiline)
173173
outAttrs.InputType |= InputTypes.TextFlagMultiLine;
174174

175+
if (outAttrs.InputType is InputTypes.ClassText && options.HideSuggestions)
176+
outAttrs.InputType |= InputTypes.TextVariationPassword | InputTypes.TextFlagNoSuggestions;
177+
175178
outAttrs.ImeOptions = options.ReturnKeyType switch
176179
{
177180
TextInputReturnKeyType.Return => ImeFlags.NoEnterAction,

src/Avalonia.Base/Input/TextInput/TextInputOptions.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,4 +253,37 @@ public static bool GetIsSensitive(StyledElement avaloniaObject)
253253
/// Text contains sensitive data like card numbers and should not be stored
254254
/// </summary>
255255
public bool IsSensitive { get; set; }
256+
257+
/// <summary>
258+
/// Defines the <see cref="HideSuggestions"/> property.
259+
/// </summary>
260+
public static readonly AttachedProperty<bool> HideSuggestionsProperty =
261+
AvaloniaProperty.RegisterAttached<TextInputOptions, StyledElement, bool>(
262+
"HideSuggestions",
263+
inherits: true);
264+
265+
/// <summary>
266+
/// Sets the value of the attached <see cref="HideSuggestionsProperty"/> on a control.
267+
/// </summary>
268+
/// <param name="avaloniaObject">The control.</param>
269+
/// <param name="value">The property value to set.</param>
270+
public static void SetHideSuggestions(StyledElement avaloniaObject, bool value)
271+
{
272+
avaloniaObject.SetValue(HideSuggestionsProperty, value);
273+
}
274+
275+
/// <summary>
276+
/// Gets the value of the attached <see cref="HideSuggestionsProperty"/>.
277+
/// </summary>
278+
/// <param name="avaloniaObject">The target.</param>
279+
/// <returns>true if HideSuggestions</returns>
280+
public static bool GetHideSuggestions(StyledElement avaloniaObject)
281+
{
282+
return avaloniaObject.GetValue(HideSuggestionsProperty);
283+
}
284+
285+
/// <summary>
286+
/// Hide virtual keyboard suggestions
287+
/// </summary>
288+
public bool HideSuggestions { get; set; }
256289
}

src/iOS/Avalonia.iOS/TextInputResponder.Properties.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ partial class TextInputResponder
1212
public UITextAutocapitalizationType AutocapitalizationType { get; private set; }
1313

1414
[Export("autocorrectionType")]
15-
public UITextAutocorrectionType AutocorrectionType => UITextAutocorrectionType.Yes;
15+
public UITextAutocorrectionType AutocorrectionType =>
16+
_view._options == null ?
17+
UITextAutocorrectionType.Yes :
18+
_view._options.HideSuggestions ?
19+
UITextAutocorrectionType.No :
20+
UITextAutocorrectionType.Yes;
1621

1722
[Export("keyboardType")]
1823
public UIKeyboardType KeyboardType =>
@@ -64,7 +69,13 @@ public UIReturnKeyType ReturnKeyType
6469
_view._options?.ContentType is TextInputContentType.Password or TextInputContentType.Pin
6570
|| (_view._options?.IsSensitive ?? false);
6671

67-
[Export("spellCheckingType")] public UITextSpellCheckingType SpellCheckingType => UITextSpellCheckingType.Yes;
72+
[Export("spellCheckingType")]
73+
public UITextSpellCheckingType SpellCheckingType =>
74+
_view._options == null ?
75+
UITextSpellCheckingType.Yes :
76+
_view._options.HideSuggestions ?
77+
UITextSpellCheckingType.No :
78+
UITextSpellCheckingType.Yes;
6879

6980
[Export("textContentType")] public NSString TextContentType { get; set; } = new NSString("text/plain");
7081

0 commit comments

Comments
 (0)