Skip to content

Conversation

@gspencergoog
Copy link
Contributor

@gspencergoog gspencergoog commented Sep 22, 2022

Description

This implements a MenuBar widget that can render a Material menu bar, and a MenuAnchor widget used to create a cascading menu in a region. The menus are drawn in the overlay, while the menu bar itself is in the regular widget tree. Keyboard traversal works between the two.

This implementation of the MenuBar uses MenuAnchor to create a cascading menu that contains widgets representing the menu items. These menu items can be any kind of widget, but are typically SubmenuButtons that host submenus, or MenuItemButtons that have shortcut hints (but don't actually activate the shortcuts) and don't host submenus.

Cascading menus can be created outside of a MenuBar by using a MenuAnchor. They can be either given a specific location to appear (a coordinate), or they can be located by the MenuAnchor region that wraps the control that opens them.

The developer may also create a MenuController to pass to the various menu primitives (MenuBar or MenuAnchor) to associate menus so that they can be traversed together and closed together. Creating a controller is not required.

Things that are not implemented in this PR, but will need to be:

  • Accelerators
  • Showing the "selection trail" for selected menus. Parent menus should show as selected when a child is highlighted.
  • A checkbox menu item that automatically shows and manages its own checkbox. You can technically do it right now with the prefix icon, but it's not very clean.
  • Opening the menu initially with the keyboard (e.g. the Alt key on Linux/Windows, Ctrl-F2 on macOS).

This draft PR still includes the contents of #112106 as well, which will be factored out once that PR lands.

Related Issues

Previous Iterations

This is the fifth iteration of this API, as we continue to refine the API so that it is most useful, while avoiding churn in a published API. Previous (closed, not submitted) PRs for this API are:

Tests

  • Many tests for all of the menu operations and configurations

Design Doc

@flutter-dashboard flutter-dashboard bot added a: text input Entering text in a text field or keyboard related problems d: api docs Issues with https://api.flutter.dev/ d: examples Sample code and demos documentation f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. c: contributor-productivity Team-specific productivity, code health, technical debt. labels Sep 22, 2022
@gspencergoog gspencergoog changed the title Menu bar v Implement Material MenuBar and MenuAnchor Sep 23, 2022
@gspencergoog gspencergoog marked this pull request as ready for review September 23, 2022 20:14
Copy link
Member

@goderbauer goderbauer left a comment

Choose a reason for hiding this comment

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

Not a full review, just went through the samples before lunch to warm up for the full review 😝

@gspencergoog gspencergoog force-pushed the menu_bar_v branch 3 times, most recently from 3f2cdf0 to b423d53 Compare September 28, 2022 00:56
@gspencergoog
Copy link
Contributor Author

Okay, I've updated the commit with the latest iteration. A word of warning: I did some spring (fall?) cleaning by changing the name of menu_bar.dart (and associated tests, examples) to menu_anchor.dart, since that is really the "star" of the file now. I also made the function order more consistent in all the classes. If you want to see just the code changes since your last review, the rename/rearrange is all in the last change, so just look at the one before that.

Copy link
Member

@goderbauer goderbauer left a comment

Choose a reason for hiding this comment

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

LGTM

@goderbauer
Copy link
Member

Looks like some tests are unhappy.

@gspencergoog gspencergoog added the autosubmit Merge PR when tree becomes green via auto submit App label Sep 28, 2022
@auto-submit
Copy link
Contributor

auto-submit bot commented Sep 28, 2022

auto label is removed for flutter/flutter, pr: 112239, due to - The status or check suite Linux docs_test has failed. Please fix the issues identified (or deflake) before re-applying this label.

  • The status or check suite docs-linux has failed. Please fix the issues identified (or deflake) before re-applying this label.

@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Sep 28, 2022
@gspencergoog gspencergoog added the autosubmit Merge PR when tree becomes green via auto submit App label Sep 28, 2022
@auto-submit
Copy link
Contributor

auto-submit bot commented Sep 28, 2022

auto label is removed for flutter/flutter, pr: 112239, due to - The status or check suite ci.yaml validation has failed. Please fix the issues identified (or deflake) before re-applying this label.

@pmartelletti
Copy link

Hi - I'm trying to change the scrollbar theme of the menu, but I cannot find the proper way to do it. I'm assuming it's because the menu is in the overlay, and it's not in the context that I'm wrapping with a scrollbartheme widget.

How would you go around that?

@gspencergoog
Copy link
Contributor Author

@pmartelletti Hmm. Yes, that is probably correct that it's not possible right now. Can you please file an issue about it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: text input Entering text in a text field or keyboard related problems c: contributor-productivity Team-specific productivity, code health, technical debt. d: api docs Issues with https://api.flutter.dev/ d: examples Sample code and demos f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants