Skip to content

Commit

Permalink
NumberBox to Announce Min/Max Values (#6145)
Browse files Browse the repository at this point in the history
* add min max values to textbox name

* add test

* fix whitespaces

* update numberbox UIAName test
  • Loading branch information
karkarl authored Nov 9, 2021
1 parent 3ac8fc1 commit 01aef0e
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 2 deletions.
18 changes: 18 additions & 0 deletions dev/NumberBox/APITests/NumberBoxTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,24 @@ public void VerifyUIANameBehavior()
RunOnUIThread.Execute(() =>
{
VerifyUIAName("Some UIA name");
numberBox.Minimum = 0;
numberBox.Maximum = 10;
});

IdleSynchronizer.Wait();

RunOnUIThread.Execute(() =>
{
VerifyUIAName("Some UIA name Minimum0 Maximum10");
numberBox.Minimum = 50;
numberBox.Maximum = 100;
});

IdleSynchronizer.Wait();

RunOnUIThread.Execute(() =>
{
VerifyUIAName("Some UIA name Minimum50 Maximum100");
});

void VerifyUIAName(string value)
Expand Down
13 changes: 11 additions & 2 deletions dev/NumberBox/NumberBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ void NumberBox::OnMinimumPropertyChanged(const winrt::DependencyPropertyChangedE
CoerceValue();

UpdateSpinButtonEnabled();
ReevaluateForwardedUIAName();
}

void NumberBox::OnMaximumPropertyChanged(const winrt::DependencyPropertyChangedEventArgs& args)
Expand All @@ -283,6 +284,7 @@ void NumberBox::OnMaximumPropertyChanged(const winrt::DependencyPropertyChangedE
CoerceValue();

UpdateSpinButtonEnabled();
ReevaluateForwardedUIAName();
}

void NumberBox::OnSmallChangePropertyChanged(const winrt::DependencyPropertyChangedEventArgs& args)
Expand Down Expand Up @@ -363,17 +365,24 @@ void NumberBox::ReevaluateForwardedUIAName()
if (const auto textBox = m_textBox.get())
{
const auto name = winrt::AutomationProperties::GetName(*this);
const auto minimum = Minimum() == -std::numeric_limits<double>::max() ?
winrt::hstring{} :
winrt::hstring{ L" " + ResourceAccessor::GetLocalizedStringResource(SR_NumberBoxMinimumValueStatus) + winrt::to_hstring(Minimum()) };
const auto maximum = Maximum() == std::numeric_limits<double>::max() ?
winrt::hstring{} :
winrt::hstring{ L" " + ResourceAccessor::GetLocalizedStringResource(SR_NumberBoxMaximumValueStatus) + winrt::to_hstring(Maximum()) };

if (!name.empty())
{
// AutomationProperties.Name is a non empty string, we will use that value.
winrt::AutomationProperties::SetName(textBox, name);
winrt::AutomationProperties::SetName(textBox, name + minimum + maximum );
}
else
{
if (const auto headerAsString = Header().try_as<winrt::IReference<winrt::hstring>>())
{
// Header is a string, we can use that as our UIA name.
winrt::AutomationProperties::SetName(textBox, headerAsString.Value());
winrt::AutomationProperties::SetName(textBox, headerAsString.Value() + minimum + maximum );
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions dev/NumberBox/Strings/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,12 @@
<value>Increase</value>
<comment>Automation name for the up button</comment>
</data>
<data name="NumberBoxMaximumValueStatus" xml:space="preserve">
<value>Maximum</value>
<comment>Maximum value declaration</comment>
</data>
<data name="NumberBoxMinimumValueStatus" xml:space="preserve">
<value>Minimum</value>
<comment>Minimum value declaration</comment>
</data>
</root>
2 changes: 2 additions & 0 deletions dev/ResourceHelper/ResourceAccessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@ class ResourceAccessor sealed
#define SR_TabViewScrollIncreaseButtonTooltip L"TabViewScrollIncreaseButtonTooltip"
#define SR_NumberBoxUpSpinButtonName L"NumberBoxUpSpinButtonName"
#define SR_NumberBoxDownSpinButtonName L"NumberBoxDownSpinButtonName"
#define SR_NumberBoxMaximumValueStatus L"NumberBoxMaximumValueStatus"
#define SR_NumberBoxMinimumValueStatus L"NumberBoxMinimumValueStatus"
#define SR_ExpanderDefaultControlName L"ExpanderDefaultControlName"

#define SR_InfoBarCloseButtonName L"InfoBarCloseButtonName"
Expand Down

0 comments on commit 01aef0e

Please sign in to comment.