Skip to content

Commit

Permalink
feat: add hidesuggestions property to textbox
Browse files Browse the repository at this point in the history
  • Loading branch information
jcsawyer committed Dec 24, 2024
1 parent 07f3ad2 commit 67c90a2
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 2 deletions.
1 change: 1 addition & 0 deletions samples/ControlCatalog/Pages/TextBoxPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
UseFloatingWatermark="True"
PasswordChar="*"
Text="Password" />
<TextBox Width="200" Watermark="Hide suggestions" TextInputOptions.HideSuggestions="True" />
<TextBox Width="200" Text="Left aligned text" TextAlignment="Left" AcceptsTab="True" />
<TextBox Width="200" Text="Center aligned text" TextAlignment="Center" />
<TextBox Width="200" Text="Right aligned text" TextAlignment="Right" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ public void SetOptions(TextInputOptions options)
if (options.Multiline)
outAttrs.InputType |= InputTypes.TextFlagMultiLine;

if (outAttrs.InputType is InputTypes.ClassText && options.HideSuggestions)
outAttrs.InputType |= InputTypes.TextVariationPassword | InputTypes.TextFlagNoSuggestions;

outAttrs.ImeOptions = options.ReturnKeyType switch
{
TextInputReturnKeyType.Return => ImeFlags.NoEnterAction,
Expand Down
33 changes: 33 additions & 0 deletions src/Avalonia.Base/Input/TextInput/TextInputOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -253,4 +253,37 @@ public static bool GetIsSensitive(StyledElement avaloniaObject)
/// Text contains sensitive data like card numbers and should not be stored
/// </summary>
public bool IsSensitive { get; set; }

/// <summary>
/// Defines the <see cref="HideSuggestions"/> property.
/// </summary>
public static readonly AttachedProperty<bool> HideSuggestionsProperty =
AvaloniaProperty.RegisterAttached<TextInputOptions, StyledElement, bool>(
"HideSuggestions",
inherits: true);

/// <summary>
/// Sets the value of the attached <see cref="HideSuggestionsProperty"/> on a control.
/// </summary>
/// <param name="avaloniaObject">The control.</param>
/// <param name="value">The property value to set.</param>
public static void SetHideSuggestions(StyledElement avaloniaObject, bool value)
{
avaloniaObject.SetValue(HideSuggestionsProperty, value);
}

/// <summary>
/// Gets the value of the attached <see cref="HideSuggestionsProperty"/>.
/// </summary>
/// <param name="avaloniaObject">The target.</param>
/// <returns>true if HideSuggestions</returns>
public static bool GetHideSuggestions(StyledElement avaloniaObject)
{
return avaloniaObject.GetValue(HideSuggestionsProperty);
}

/// <summary>
/// Hide virtual keyboard suggestions
/// </summary>
public bool HideSuggestions { get; set; }
}
15 changes: 13 additions & 2 deletions src/iOS/Avalonia.iOS/TextInputResponder.Properties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ partial class TextInputResponder
public UITextAutocapitalizationType AutocapitalizationType { get; private set; }

[Export("autocorrectionType")]
public UITextAutocorrectionType AutocorrectionType => UITextAutocorrectionType.Yes;
public UITextAutocorrectionType AutocorrectionType =>
_view._options == null ?
UITextAutocorrectionType.Yes :
_view._options.HideSuggestions ?
UITextAutocorrectionType.No :
UITextAutocorrectionType.Yes;

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

[Export("spellCheckingType")] public UITextSpellCheckingType SpellCheckingType => UITextSpellCheckingType.Yes;
[Export("spellCheckingType")]
public UITextSpellCheckingType SpellCheckingType =>
_view._options == null ?
UITextSpellCheckingType.Yes :
_view._options.HideSuggestions ?
UITextSpellCheckingType.No :
UITextSpellCheckingType.Yes;

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

Expand Down

0 comments on commit 67c90a2

Please sign in to comment.