Skip to content

Improve ComboBox scrolling and selection interaction - #22018

Closed
zrt2399 wants to merge 3 commits into
AvaloniaUI:mainfrom
zrt2399:fix-combobox-focus-scroll-margin
Closed

Improve ComboBox scrolling and selection interaction#22018
zrt2399 wants to merge 3 commits into
AvaloniaUI:mainfrom
zrt2399:fix-combobox-focus-scroll-margin

Conversation

@zrt2399

@zrt2399 zrt2399 commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

What does the pull request do?

  • Include the ItemsPresenter margin when bringing a focused ComboBoxItem into view.
  • Respect AutoScrollToSelectedItem when opening the ComboBox dropdown.

What is the current behavior?

When a ComboBox dropdown uses an ItemsPresenter margin, focusing an item can scroll only to the item bounds and ignore the visual margin.
image

Additionally, opening a ComboBox with AutoScrollToSelectedItem="False" still scrolls to and focuses the selected item.

What is the updated/expected behavior with this PR?

The focused item is brought into view together with the presenter margin, ensuring correct scrolling with both the Fluent and Fluent v2 themes.
image
image

When AutoScrollToSelectedItem is disabled, opening the dropdown does not change its scroll offset.

Checklist

@avaloniaui-bot

Copy link
Copy Markdown

You can test this PR using the following package version. 12.2.999-cibuild0068497-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@MrJul MrJul added bug backport-candidate-12.1.x Consider this PR for backporting to 12.1 branch labels Aug 19, 2026
@avaloniaui-bot

Copy link
Copy Markdown

You can test this PR using the following package version. 12.2.999-cibuild0068557-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@grokys grokys self-assigned this Aug 27, 2026
if (IsDropDownOpen && dropDownItem.IsFocused && dropDownItem.IsArrangeValid)
{
dropDownItem.BringIntoView();
var margin = Presenter?.Margin ?? default;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels like a hack - I think this should be fixed in ScrollContentPresenter.BringDescendantIntoView for the general case.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By the way, should BringDescendantIntoView respect only the child's margin, or both the child's margin and its own padding?

{
var selectedIndex = SelectedIndex;
if (IsDropDownOpen && selectedIndex != -1)
if (IsDropDownOpen && AutoScrollToSelectedItem && selectedIndex != -1)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does feel like a valid fix though.

@grokys

grokys commented Aug 27, 2026

Copy link
Copy Markdown
Member

It might be worth closing this PR and opening two separate PRs with the separate fixes?

@zrt2399

zrt2399 commented Aug 27, 2026

Copy link
Copy Markdown
Contributor Author

It might be worth closing this PR and opening two separate PRs with the separate fixes?

Agreed.

@zrt2399

zrt2399 commented Aug 27, 2026

Copy link
Copy Markdown
Contributor Author

I’ll close this PR and follow your suggestion by opening two separate PRs.

@zrt2399 zrt2399 closed this Aug 27, 2026
@avaloniaui-bot

Copy link
Copy Markdown

You can test this PR using the following package version. 12.2.999-cibuild0068984-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@MrJul MrJul removed the backport-candidate-12.1.x Consider this PR for backporting to 12.1 branch label Aug 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants