From caec76095418593ef885a210df8831c514346443 Mon Sep 17 00:00:00 2001 From: Tim Miller Date: Thu, 14 Aug 2025 17:12:50 +0900 Subject: [PATCH] Track TabIndex value in NumericUpDown (#19348) * Track TabIndex value in NumericUpDown * Use template * Add TabNavigationProperty.OverrideDefaultValue --- .../NumericUpDown/NumericUpDown.cs | 2 ++ .../NumericUpDownTests.cs | 17 +++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/Avalonia.Controls/NumericUpDown/NumericUpDown.cs b/src/Avalonia.Controls/NumericUpDown/NumericUpDown.cs index eac1403554..90cfb41c65 100644 --- a/src/Avalonia.Controls/NumericUpDown/NumericUpDown.cs +++ b/src/Avalonia.Controls/NumericUpDown/NumericUpDown.cs @@ -379,6 +379,7 @@ namespace Avalonia.Controls FocusableProperty.OverrideDefaultValue(true); IsTabStopProperty.OverrideDefaultValue(false); + KeyboardNavigation.TabNavigationProperty.OverrideDefaultValue(KeyboardNavigationMode.Local); } /// @@ -408,6 +409,7 @@ namespace Avalonia.Controls if (TextBox != null) { TextBox.Text = Text; + TextBox[!TabIndexProperty] = this[!TabIndexProperty]; TextBox.PointerPressed += TextBoxOnPointerPressed; _textBoxTextChangedSubscription = TextBox.GetObservable(TextBox.TextProperty).Subscribe(txt => TextBoxOnTextChanged()); } diff --git a/tests/Avalonia.Controls.UnitTests/NumericUpDownTests.cs b/tests/Avalonia.Controls.UnitTests/NumericUpDownTests.cs index 10139be0d4..1d31129175 100644 --- a/tests/Avalonia.Controls.UnitTests/NumericUpDownTests.cs +++ b/tests/Avalonia.Controls.UnitTests/NumericUpDownTests.cs @@ -152,5 +152,22 @@ namespace Avalonia.Controls.UnitTests }.RegisterInNameScope(scope); }); } + + [Fact] + public void TabIndex_Should_Be_Synchronized_With_Inner_TextBox() + { + RunTest((control, textbox) => + { + // Set TabIndex on NumericUpDown + control.TabIndex = 5; + + // The inner TextBox should inherit the same TabIndex + Assert.Equal(5, textbox.TabIndex); + + // Change TabIndex and verify it gets synchronized + control.TabIndex = 10; + Assert.Equal(10, textbox.TabIndex); + }); + } } }