Skip to content

Reprise: Dropdown Menu layout respects menu items intrinsic sizes - #42033

Merged
shihaohong merged 3 commits into
flutter:masterfrom
HansMuller:dropdown_intrinsic_height
Oct 9, 2019
Merged

shihaohong merged 3 commits into
flutter:masterfrom
HansMuller:dropdown_intrinsic_height

Conversation

@HansMuller

@HansMuller HansMuller commented Oct 5, 2019 •

Copy link
Copy Markdown
Contributor

Fixes #40773.

This is an updated version of #41120.

Previously, dropdown menu items had a fixed height of 48 (kMinInteractiveDimension). Now, if DropdownButton.itemHeight is null, then menu items have a minimum height of kMinInteractiveDimension and no maximum height.

This test case demos dropdown menus with variable height items. It also uses the new selectedItemBuilder feature to render compact versions of the selected items within the dropdown button. If the selectedItemBuilder is not specified, then the DropdownButton's height will be as big as the largest menu item.

closed

Previous Current
old_menu0_open menu0_open
old_menu1_open menu1_open

@fluttergithubbot fluttergithubbot added p: material_ui material_ui package in flutter/packages framework flutter/packages/flutter repository. See also f: labels. labels Oct 5, 2019
@shihaohong
shihaohong self-requested a review October 7, 2019 20:07
@shihaohong shihaohong self-assigned this Oct 7, 2019
@shihaohong

Copy link
Copy Markdown
Contributor

Original PR for posterity: #41120

@shihaohong shihaohong left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

A few nits for code comments. Is it expected that when itemHeights is set to null and the menu is too tall to fit the screen, the scroll offset is always set to zero? If so, we should document that somewhere.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
// for the ListView that contains he menu items. The vertical center of the
// for the ListView that contains the menu items. The vertical center of the

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.

Done

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
// out, only works if the item heights are fixed. This works out when
// out. It only works if the item heights are fixed. This works out when

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.

Done

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could we also add a description for what would happen if the item heights aren't fixed? ie:

Suggested change
// the item heights are defined by kMinInteractiveDimension.
// the item heights are defined by kMinInteractiveDimension. If
// itemHeight is set to null, initialScrollOffset will be set to 0.

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.

Sure, done.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
// The Each item appears twice, once in the menu and once
// Each item appears twice, once in the menu and once

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.

Done

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This seems to still be here

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this comment belongs a few lines down (right above hint)

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.

I copied that from the original code, however I agree that it belongs above the Stack, so I moved it.

@shihaohong shihaohong Oct 7, 2019 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is it worth mentioning here that if the preferred menu height is too tall for the screen and itemHeights = null, the scroll offset will not be properly set and always be at zero?

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.

Yes, sadly yes. Updated the doc to explain this.

@HansMuller
HansMuller force-pushed the dropdown_intrinsic_height branch from efe3262 to ff0203a Compare October 8, 2019 21:00

@shihaohong shihaohong left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM with a few nits.

Also, it seems that if the options are too tall, the dropdown menu doesn't scroll to show the selected item. This might be the expected behavior. If not, we should fix it, but that's probably outside of the scope of this PR:

  1. Select item that is at bottom of the menu list
  2. Note that the dropdown always starts at the top of the menu instead of starting where the selected item is.

See gist for code, and see gif with current behavior:
dropdown_scroll

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This seems to still be here

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
// treating the items as if their heights were all equal to kMinInteractveDimension.
// treating the items as if their heights were all equal to kMinInteractiveDimension.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
// Otherwise the initialScrollOffset is just an rough approximation based on
// Otherwise the initialScrollOffset is just a rough approximation based on

@HansMuller
HansMuller force-pushed the dropdown_intrinsic_height branch from ff0203a to 2da8883 Compare October 9, 2019 14:31
@HansMuller

Copy link
Copy Markdown
Contributor Author

The reason an itemHeight:null dropdown menu with 4 very large menu items doesn't automatically scroll is that the dropdown doesn't know that the items need to be scrollable until after layout, which is too late. In other words, based on the initial assumption that all of the items have height=48, the menu appears to fit on the screen.

@shihaohong
shihaohong merged commit b770f34 into flutter:master Oct 9, 2019
@rajeshzmoke

Copy link
Copy Markdown

@shihaohong Any idea when this update will be available on "stable" branch?

Inconnu08 pushed a commit to Inconnu08/flutter that referenced this pull request Nov 26, 2019
…utter#42033)

* Reprise: Dropdown Menu layout respects menu items intrinsic sizes

* updated per review feedback

* updated per review feedback
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Aug 3, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

framework flutter/packages/flutter repository. See also f: labels. p: material_ui material_ui package in flutter/packages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DropdownMenuItems are fixed height

5 participants