Skip to content

Commit 097f312

Browse files
SubhikshaSf4851PureWeen
authored andcommitted
Fixed Stepper allows incrementing beyond the maximum value (#28398)
* Fix for stepper allows to increment value * Updating naming concern * Updates on minimum value and test case sample
1 parent 9c8a953 commit 097f312

File tree

3 files changed

+78
-2
lines changed

3 files changed

+78
-2
lines changed

src/Controls/src/Core/Stepper/Stepper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public partial class Stepper : View, IElementConfiguration<Stepper>, IStepper
1212
{
1313
/// <summary>Bindable property for <see cref="Maximum"/>.</summary>
1414
public static readonly BindableProperty MaximumProperty = BindableProperty.Create(nameof(Maximum), typeof(double), typeof(Stepper), 100.0,
15-
validateValue: (bindable, value) => (double)value > ((Stepper)bindable).Minimum,
15+
validateValue: (bindable, value) => (double)value >= ((Stepper)bindable).Minimum,
1616
coerceValue: (bindable, value) =>
1717
{
1818
var stepper = (Stepper)bindable;
@@ -22,7 +22,7 @@ public partial class Stepper : View, IElementConfiguration<Stepper>, IStepper
2222

2323
/// <summary>Bindable property for <see cref="Minimum"/>.</summary>
2424
public static readonly BindableProperty MinimumProperty = BindableProperty.Create(nameof(Minimum), typeof(double), typeof(Stepper), 0.0,
25-
validateValue: (bindable, value) => (double)value < ((Stepper)bindable).Maximum,
25+
validateValue: (bindable, value) => (double)value <= ((Stepper)bindable).Maximum,
2626
coerceValue: (bindable, value) =>
2727
{
2828
var stepper = (Stepper)bindable;
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
namespace Maui.Controls.Sample.Issues;
2+
[Issue(IssueTracker.Github, 28330, "Stepper allows to increment when value equals to maximum", PlatformAffected.All)]
3+
public class Issue28330 : TestContentPage
4+
{
5+
protected override void Init()
6+
{
7+
var layout = new StackLayout { };
8+
9+
Stepper Incrementstepper = new Stepper
10+
{
11+
AutomationId = "Incrementstepper",
12+
HorizontalOptions = LayoutOptions.Center,
13+
Increment = 1,
14+
Minimum = 1,
15+
Maximum = 1,
16+
Value = 1
17+
};
18+
19+
Label Incrementlabel = new Label
20+
{
21+
AutomationId = "Incrementlabel",
22+
HorizontalOptions = LayoutOptions.Center,
23+
FontSize = 32
24+
};
25+
Incrementlabel.SetBinding(Label.TextProperty, new Binding("Value", source: Incrementstepper));
26+
27+
Stepper Decrementstepper = new Stepper
28+
{
29+
AutomationId = "Decrementstepper",
30+
HorizontalOptions = LayoutOptions.Center,
31+
Increment = 1,
32+
Maximum = 1,
33+
Minimum = 1,
34+
Value = 1
35+
};
36+
37+
Label Decrementlabel = new Label
38+
{
39+
AutomationId = "Decrementlabel",
40+
HorizontalOptions = LayoutOptions.Center,
41+
FontSize = 32
42+
};
43+
Decrementlabel.SetBinding(Label.TextProperty, new Binding("Value", source: Decrementstepper));
44+
45+
layout.Children.Add(Incrementstepper);
46+
layout.Children.Add(Incrementlabel);
47+
layout.Children.Add(Decrementstepper);
48+
layout.Children.Add(Decrementlabel);
49+
50+
Content = layout;
51+
}
52+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using NUnit.Framework;
2+
using UITest.Appium;
3+
using UITest.Core;
4+
5+
namespace Microsoft.Maui.TestCases.Tests.Issues;
6+
public class Issue28330 : _IssuesUITest
7+
{
8+
public Issue28330(TestDevice device) : base(device)
9+
{
10+
}
11+
12+
public override string Issue => "Stepper allows to increment when value equals to maximum";
13+
14+
[Test]
15+
[Category(UITestCategories.Stepper)]
16+
public void Issue28330StepperIncrementShouldBeDisabled()
17+
{
18+
App.WaitForElement("Incrementlabel");
19+
App.IncreaseStepper("Incrementstepper");
20+
Assert.That(App.FindElement("Incrementlabel").GetText(), Is.EqualTo("1"));
21+
App.DecreaseStepper("Decrementstepper");
22+
Assert.That(App.FindElement("Decrementlabel").GetText(), Is.EqualTo("1"));
23+
}
24+
}

0 commit comments

Comments
 (0)