Skip to content

Commit

Permalink
Ensure NavigationView pane items are brought into view when selected
Browse files Browse the repository at this point in the history
  • Loading branch information
bdlukaa committed Dec 8, 2022
1 parent 878ad91 commit 520527d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- Ensure combobox scroll controller has a client attached before using it ([#620](https://github.com/bdlukaa/fluent_ui/issues/620))
- Correctly use `TextFormBox.initialValue`
- Added `TreeViewState.toggleItem`, which toggles the item expanded state ([#493](https://github.com/bdlukaa/fluent_ui/issues/493))
- Ensure `NavigationView` pane items are brought into view when selected

## 4.1.0

Expand Down
1 change: 1 addition & 0 deletions lib/src/controls/navigation/navigation_view/pane.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1278,6 +1278,7 @@ class _OpenNavigationPaneState extends State<_OpenNavigationPane>
shrinkWrap: true,
key: widget.listKey,
primary: true,
addAutomaticKeepAlives: true,
children: widget.pane.items.map((item) {
return _OpenNavigationPane.buildItem(
context,
Expand Down
14 changes: 14 additions & 0 deletions lib/src/controls/navigation/navigation_view/view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,20 @@ class NavigationViewState extends State<NavigationView> {

if (oldWidget.pane?.selected != widget.pane?.selected) {
_oldIndex = oldWidget.pane?.selected ?? -1;

final item = widget.pane?.selectedItem.itemKey.currentContext;

if (item != null) {
final atEnd =
(widget.pane!.effectiveItems.length / 2) < widget.pane!.selected!;

Scrollable.ensureVisible(
item,
alignmentPolicy: atEnd
? ScrollPositionAlignmentPolicy.keepVisibleAtEnd
: ScrollPositionAlignmentPolicy.keepVisibleAtStart,
);
}
}

if (oldWidget.pane?.effectiveItems.length !=
Expand Down

0 comments on commit 520527d

Please sign in to comment.