{"record":{"id":"a8ea3a1e5875fccd","repo":"AvaloniaUI/Avalonia","slug":"only-next-previous-up-down-left-and-right-dire","errorCode":null,"errorMessage":"Only Next, Previous, Up, Down, Left and Right directions are supported","messagePattern":"Only Next, Previous, Up, Down, Left and Right directions are supported","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Avalonia.Base/Input/FocusManager.cs","lineNumber":365,"sourceCode":"            ValidateDirection(direction);\n\n            var focusOptions = ToFocusOptions(options, false);\n            var result = FindNextFocus(options?.FocusedElement ?? Current, direction, focusOptions);\n            _reusableFocusOptions = focusOptions;\n            return result;\n        }\n\n        private static void ValidateDirection(NavigationDirection direction)\n        {\n            if (direction is not (\n                NavigationDirection.Next or\n                NavigationDirection.Previous or\n                NavigationDirection.Up or\n                NavigationDirection.Down or\n                NavigationDirection.Left or\n                NavigationDirection.Right))\n            {\n                throw new ArgumentOutOfRangeException(\n                    nameof(direction),\n                    direction,\n                    $\"Only {nameof(NavigationDirection.Next)}, {nameof(NavigationDirection.Previous)}, \" +\n                    $\"{nameof(NavigationDirection.Up)}, {nameof(NavigationDirection.Down)},\" +\n                    $\" {nameof(NavigationDirection.Left)} and {nameof(NavigationDirection.Right)} directions are supported\");\n            }\n        }\n\n        private XYFocusOptions ToFocusOptions(FindNextElementOptions? options, bool updateManifold)\n        {\n            // XYFocus only uses the options and never modifies them; we can cache and reset them between calls.\n            var focusOptions = _reusableFocusOptions;\n            _reusableFocusOptions = null;\n\n            if (focusOptions is null)\n                focusOptions = new XYFocusOptions();\n            else\n                focusOptions.Reset();","sourceCodeStart":347,"sourceCodeEnd":383,"githubUrl":"https://github.com/AvaloniaUI/Avalonia/blob/11c542726898ae954a1ef668c65ec79ec92ab17d/src/Avalonia.Base/Input/FocusManager.cs#L347-L383","documentation":"FocusManager directional navigation (Move with XYFocus) only accepts the spatial/sequential directions Next, Previous, Up, Down, Left, Right. Other NavigationDirection values (e.g. First, Last, PageDown, Tab) are meaningless for XY directional focus, so ValidateDirection throws ArgumentOutOfRangeException.","triggerScenarios":"Calling `FocusManager.Instance.Move(NavigationDirection.First)` or any non-spatial direction through the code path that invokes ValidateDirection (the directional/XYFocus path).","commonSituations":"Reusing a NavigationDirection variable for both tab and directional navigation. Passing a UI-driven direction (PageDown/First) into the directional Move API.","solutions":["Pass only Next/Previous/Up/Down/Left/Right to the directional Move overload.","Use the tab-based Move path (or GetNextTab/GetPrevTab) for Tab/First/Last semantics.","Branch on the direction: spatial vs sequential APIs differ."],"exampleFix":"// before:\nFocusManager.Instance?.Move(NavigationDirection.First); // throws in XY path\n\n// after:\nFocusManager.Instance?.Move(NavigationDirection.Next); // valid for directional\n// or use tab navigation APIs for First/Last.","handlingStrategy":"validation","validationCode":"if (direction is not (NavigationDirection.Next or NavigationDirection.Previous or\n    NavigationDirection.Up or NavigationDirection.Down or\n    NavigationDirection.Left or NavigationDirection.Right))\n    throw new ArgumentOutOfRangeException(nameof(direction));\nFocusManager.Instance?.Move(direction);","typeGuard":"static bool IsDirectional(NavigationDirection d) => d is NavigationDirection.Next or NavigationDirection.Previous or NavigationDirection.Up or NavigationDirection.Down or NavigationDirection.Left or NavigationDirection.Right;","tryCatchPattern":null,"preventionTips":["Use the directional Move overload only for spatial directions.","Route Tab/First/Last through tab-navigation APIs.","Don't share one NavigationDirection variable across both APIs."],"tags":["focus","navigation","argument-out-of-range","input"],"backgroundTag":null,"analyzedSha":"11c542726898ae954a1ef668c65ec79ec92ab17d","analyzedAt":"2026-08-13T11:57:40.261Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}