Skip to content

feat: add hidesuggestions property to textbox #17815

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

Merged
merged 5 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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="Suggestions are hidden" TextInputOptions.ShowSuggestions="False" />
<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.ShowSuggestions == false)
outAttrs.InputType |= InputTypes.TextVariationPassword | InputTypes.TextFlagNoSuggestions;

outAttrs.ImeOptions = options.ReturnKeyType switch
{
TextInputReturnKeyType.Return => ImeFlags.NoEnterAction,
Expand Down
36 changes: 35 additions & 1 deletion src/Avalonia.Base/Input/TextInput/TextInputOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ public static TextInputOptions FromStyledElement(StyledElement avaloniaObject)
AutoCapitalization = GetAutoCapitalization(avaloniaObject),
IsSensitive = GetIsSensitive(avaloniaObject),
Lowercase = GetLowercase(avaloniaObject),
Uppercase = GetUppercase(avaloniaObject)
Uppercase = GetUppercase(avaloniaObject),
ShowSuggestions = GetShowSuggestions(avaloniaObject),
};

return result;
Expand Down Expand Up @@ -253,4 +254,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="ShowSuggestions"/> property.
/// </summary>
public static readonly AttachedProperty<bool?> ShowSuggestionsProperty =
AvaloniaProperty.RegisterAttached<TextInputOptions, StyledElement, bool?>(
"ShowSuggestions",
inherits: true);

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

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

/// <summary>
/// Show virtual keyboard suggestions
/// </summary>
public bool? ShowSuggestions { get; set; }
}
11 changes: 9 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,10 @@ partial class TextInputResponder
public UITextAutocapitalizationType AutocapitalizationType { get; private set; }

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

[Export("keyboardType")]
public UIKeyboardType KeyboardType =>
Expand Down Expand Up @@ -64,7 +67,11 @@ 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?.ShowSuggestions == false ?
UITextSpellCheckingType.No :
UITextSpellCheckingType.Yes;

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

Expand Down
Loading