Skip to content
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

feat: add hidesuggestions property to textbox #17815

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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="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
Loading