Merge pull request #316 from irihitech/286-modal

Automatically focus on overlay modal dialog/messagebox/drawer
This commit is contained in:
Dong Bin
2024-09-05 17:28:17 +08:00
committed by GitHub
10 changed files with 47 additions and 13 deletions

View File

@@ -1,5 +1,6 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Layout;
namespace Ursa.Controls;
@@ -93,6 +94,7 @@ public static class OverlayDialog
{
Content = view,
DataContext = vm,
[KeyboardNavigation.TabNavigationProperty] = KeyboardNavigationMode.Cycle
};
ConfigureCustomDialogControl(t, options);
host.AddDialog(t);
@@ -108,6 +110,7 @@ public static class OverlayDialog
{
Content = new TView(),
DataContext = vm,
[KeyboardNavigation.TabNavigationProperty] = KeyboardNavigationMode.Cycle
};
ConfigureDefaultDialogControl(t, options);
host.AddModalDialog(t);
@@ -123,6 +126,7 @@ public static class OverlayDialog
{
Content = control,
DataContext = vm,
[KeyboardNavigation.TabNavigationProperty] = KeyboardNavigationMode.Cycle
};
ConfigureDefaultDialogControl(t, options);
host.AddModalDialog(t);
@@ -139,6 +143,7 @@ public static class OverlayDialog
{
Content = new TView(),
DataContext = vm,
[KeyboardNavigation.TabNavigationProperty] = KeyboardNavigationMode.Cycle
};
ConfigureCustomDialogControl(t, options);
host.AddModalDialog(t);
@@ -154,6 +159,7 @@ public static class OverlayDialog
{
Content = control,
DataContext = vm,
[KeyboardNavigation.TabNavigationProperty] = KeyboardNavigationMode.Cycle
};
ConfigureCustomDialogControl(t, options);
host.AddModalDialog(t);
@@ -172,6 +178,7 @@ public static class OverlayDialog
{
Content = view,
DataContext = vm,
[KeyboardNavigation.TabNavigationProperty] = KeyboardNavigationMode.Cycle
};
ConfigureCustomDialogControl(t, options);
host.AddModalDialog(t);

View File

@@ -1,5 +1,6 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Input;
using Ursa.Common;
using Ursa.Controls.Options;
@@ -60,7 +61,8 @@ public static class Drawer
var drawer = new DefaultDrawerControl
{
Content = new TView(),
DataContext = vm
DataContext = vm,
[KeyboardNavigation.TabNavigationProperty] = KeyboardNavigationMode.Cycle
};
ConfigureDefaultDrawer(drawer, options);
host.AddModalDrawer(drawer);
@@ -75,7 +77,8 @@ public static class Drawer
var drawer = new DefaultDrawerControl
{
Content = control,
DataContext = vm
DataContext = vm,
[KeyboardNavigation.TabNavigationProperty] = KeyboardNavigationMode.Cycle
};
ConfigureDefaultDrawer(drawer, options);
host.AddModalDrawer(drawer);
@@ -92,7 +95,8 @@ public static class Drawer
var drawer = new DefaultDrawerControl
{
Content = view,
DataContext = vm
DataContext = vm,
[KeyboardNavigation.TabNavigationProperty] = KeyboardNavigationMode.Cycle
};
ConfigureDefaultDrawer(drawer, options);
host.AddModalDrawer(drawer);
@@ -152,7 +156,8 @@ public static class Drawer
var dialog = new CustomDrawerControl
{
Content = new TView(),
DataContext = vm
DataContext = vm,
[KeyboardNavigation.TabNavigationProperty] = KeyboardNavigationMode.Cycle
};
ConfigureCustomDrawer(dialog, options);
host.AddModalDrawer(dialog);
@@ -167,7 +172,8 @@ public static class Drawer
var dialog = new CustomDrawerControl
{
Content = control,
DataContext = vm
DataContext = vm,
[KeyboardNavigation.TabNavigationProperty] = KeyboardNavigationMode.Cycle
};
ConfigureCustomDrawer(dialog, options);
host.AddModalDrawer(dialog);
@@ -185,7 +191,8 @@ public static class Drawer
var dialog = new CustomDrawerControl
{
Content = view,
DataContext = vm
DataContext = vm,
[KeyboardNavigation.TabNavigationProperty] = KeyboardNavigationMode.Cycle
};
ConfigureCustomDrawer(dialog, options);
host.AddModalDrawer(dialog);

View File

@@ -1,6 +1,7 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Input;
namespace Ursa.Controls;
@@ -63,7 +64,8 @@ public static class MessageBox
Content = message,
Title = title,
Buttons = button,
MessageIcon = icon
MessageIcon = icon,
[KeyboardNavigation.TabNavigationProperty] = KeyboardNavigationMode.Cycle
};
host.AddModalDialog(messageControl);
var result = await messageControl.ShowAsync<MessageBoxResult>();

View File

@@ -1,5 +1,6 @@
using Avalonia;
using Avalonia.Input;
using Avalonia.VisualTree;
using Irihi.Avalonia.Shared.Helpers;
using Irihi.Avalonia.Shared.Shapes;
using Ursa.Controls.OverlayShared;
@@ -170,9 +171,13 @@ public partial class OverlayDialogHost
{
_maskAppearAnimation.RunAsync(mask);
}
var element = control.GetVisualDescendants().OfType<InputElement>().FirstOrDefault(a => a.Focusable);
element?.Focus();
_modalCount++;
IsInModalStatus = _modalCount > 0;
control.IsClosed = false;
control.Focus();
}
// Handle dialog layer change event

View File

@@ -2,7 +2,9 @@ using Avalonia;
using Avalonia.Animation;
using Avalonia.Animation.Easings;
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Styling;
using Avalonia.VisualTree;
using Irihi.Avalonia.Shared.Shapes;
using Ursa.Common;
using Ursa.Controls.OverlayShared;
@@ -67,6 +69,8 @@ public partial class OverlayDialogHost
{
await Task.WhenAll(animation.RunAsync(control), _maskAppearAnimation.RunAsync(mask));
}
var element = control.GetVisualDescendants().OfType<InputElement>().FirstOrDefault(a => a.Focusable);
element?.Focus();
}
private void SetDrawerPosition(DrawerControlBase control)

View File

@@ -20,6 +20,7 @@ public abstract class OverlayFeedbackElement: ContentControl
static OverlayFeedbackElement()
{
FocusableProperty.OverrideDefaultValue<OverlayFeedbackElement>(false);
DataContextProperty.Changed.AddClassHandler<OverlayFeedbackElement, object?>((o, e) => o.OnDataContextChange(e));
ClosedEvent.AddClassHandler<OverlayFeedbackElement>((o,e)=>o.OnClosed(e));
}