Skip to content

Commit 14e0cf5

Browse files
Merge pull request #80 from PriyadharshniM/main
Improved accessibility support for SfTextInputLayout control
2 parents 9827716 + c7780f2 commit 14e0cf5

File tree

3 files changed

+89
-8
lines changed

3 files changed

+89
-8
lines changed

maui/src/TextInputLayout/SfTextInputLayout.Methods.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@ internal void OnTextInputViewTextChanged(object? sender, TextChangedEventArgs e)
170170
InvalidateDrawable();
171171
}
172172

173+
SetCustomDescription(this.Content);
174+
173175
// Clear icon can't draw when isClearIconVisible property updated based on text.
174176
// So here call the InvalidateDrawable to draw the clear icon.
175177
if (Text?.Length <= 1)

maui/src/TextInputLayout/SfTextInputLayout.Properties.cs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,11 @@ static LabelStyle GetCounterLabelStyleDefaultValue()
753753
public bool ShowHint
754754
{
755755
get { return (bool)GetValue(ShowHintProperty); }
756-
set { SetValue(ShowHintProperty, value); }
756+
set
757+
{
758+
SetValue(ShowHintProperty, value);
759+
SetCustomDescription(this.Content);
760+
}
757761
}
758762

759763
/// <summary>
@@ -1274,8 +1278,12 @@ public bool IsHintAlwaysFloated
12741278
/// </example>
12751279
public string Hint
12761280
{
1277-
get => (string)GetValue(HintProperty);
1278-
set => SetValue(HintProperty, value);
1281+
get { return (string)GetValue(HintProperty); }
1282+
set
1283+
{
1284+
SetValue(HintProperty, value);
1285+
SetCustomDescription(this.Content);
1286+
}
12791287
}
12801288

12811289
/// <summary>
@@ -1755,7 +1763,11 @@ internal bool IsFilled
17551763
internal bool IsHintFloated
17561764
{
17571765
get { return (bool)GetValue(IsHintFloatedProperty); }
1758-
set { SetValue(IsHintFloatedProperty, value); }
1766+
set
1767+
{
1768+
SetValue(IsHintFloatedProperty, value);
1769+
SetCustomDescription(this.Content);
1770+
}
17591771
}
17601772

17611773
/// <summary>

maui/src/TextInputLayout/SfTextInputLayout.cs

Lines changed: 71 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,12 @@ public partial class SfTextInputLayout : SfContentView, ITouchListener, IParentT
224224
/// </summary>
225225
internal bool IsIconPressed { get; private set; } = false;
226226
#endif
227-
internal bool IsLayoutTapped { get; set; }
227+
228+
/// <summary>
229+
/// Gets or sets a value indicating whether the layout has been tapped.
230+
/// </summary>
231+
internal bool IsLayoutTapped { get; set; }
232+
228233
/// <summary>
229234
/// Gets or sets a value indicating the hint was animating from down to up.
230235
/// </summary>
@@ -337,7 +342,9 @@ public partial class SfTextInputLayout : SfContentView, ITouchListener, IParentT
337342
UIKit.UITextField? uiEntry;
338343
#endif
339344

340-
#endregion
345+
private string _initialContentDescription = string.Empty;
346+
347+
#endregion
341348

342349
#region Constructor
343350

@@ -688,8 +695,13 @@ protected override void OnContentChanged(object oldValue, object newValue)
688695
//Adjusted Opacity from 0 to 0.00001 to ensure the content remains functionally active while enabling the ReturnType property.
689696
if (newValue is InputView entryEditorContent)
690697
{
691-
entryEditorContent.Opacity = IsHintFloated ? 1 : (DeviceInfo.Platform == DevicePlatform.iOS ? 0.00001 : 0);
692-
}
698+
#if ANDROID || IOS
699+
entryEditorContent.Opacity = IsHintFloated ? 1 : 0.00001;
700+
#else
701+
entryEditorContent.Opacity = IsHintFloated ? 1 : 0;
702+
#endif
703+
_initialContentDescription = SemanticProperties.GetDescription(entryEditorContent);
704+
}
693705
else if (newValue is SfView numericEntryContent && numericEntryContent.Children.Count > 0)
694706
{
695707
if (numericEntryContent.Children[0] is Entry numericInputView)
@@ -711,8 +723,63 @@ protected override void OnContentChanged(object oldValue, object newValue)
711723
{
712724
OnEnabledPropertyChanged(IsEnabled);
713725
}
726+
727+
SetCustomDescription(newValue);
714728
}
715729

730+
/// <summary>
731+
/// Sets a custom semantic description for the content.
732+
/// </summary>
733+
private void SetCustomDescription(object content)
734+
{
735+
736+
if (this.Content == null || content == null)
737+
return;
738+
739+
var customDescription = string.Empty;
740+
#if ANDROID || MACCATALYST || IOS
741+
742+
if (content is InputView entryEditorContent)
743+
{
744+
customDescription = (string.IsNullOrEmpty(entryEditorContent.Text) && !string.IsNullOrEmpty(entryEditorContent.Placeholder) && DeviceInfo.Platform == DevicePlatform.Android) ? entryEditorContent.Placeholder : string.Empty;
745+
}
746+
747+
var layoutDescription = GetLayoutDescription();
748+
749+
var contentDescription = layoutDescription + (IsHintFloated ? customDescription + _initialContentDescription : string.Empty);
750+
751+
SemanticProperties.SetDescription(this.Content, contentDescription);
752+
#elif WINDOWS
753+
754+
customDescription = SemanticProperties.GetDescription(this);
755+
756+
if (string.IsNullOrEmpty(customDescription))
757+
{
758+
customDescription = ShowHint && !string.IsNullOrEmpty(Hint) ? Hint : string.Empty;
759+
SemanticProperties.SetDescription(this, customDescription);
760+
}
761+
#endif
762+
}
763+
764+
#if ANDROID || MACCATALYST || IOS
765+
/// <summary>
766+
/// Retrieves the layout semantic description.
767+
/// </summary>
768+
private string GetLayoutDescription()
769+
{
770+
var description = SemanticProperties.GetDescription(this);
771+
772+
if (string.IsNullOrEmpty(description))
773+
{
774+
description = ShowHint && !string.IsNullOrEmpty(Hint) ? Hint : string.Empty;
775+
}
776+
if(!string.IsNullOrEmpty(description))
777+
{
778+
description = description.EndsWith(".") ? description : description + ". ";
779+
}
780+
return description ?? string.Empty;
781+
}
782+
#endif
716783
/// <summary>
717784
/// Measures the size requirements for the content of the element.
718785
/// </summary>

0 commit comments

Comments
 (0)