Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Menu Web Component [ PRIORITY 1 ] #27906

Conversation

brianchristopherbrady
Copy link
Contributor

Menu

A Menu component for handling menus and menu items in a user interface.


Design Spec

Link to Menu Design Spec in Figma


Engineering Spec


The Menu component is responsible for managing menus and their associated menu items. It handles the open/close functionality, focus management, and positioning strategy for showing the menu items.


Use Case

Creating a menu component that can be used to display a list of options or actions.


Class: Menu


Variables


Fields

Name Privacy Type Default Description
menu public HTMLElement[] The menu element(s) to be displayed
trigger public HTMLElement[] The trigger element(s) for opening/closing menu
expanded public boolean false Specifies if the menu is expanded or collapsed
menuContainer public HTMLElement The container element for the menu items
openOnHover public boolean false Sets whether the menu opens on hover of menu trigger

Methods

  • setPositioning(): Calculates and applies the positioning of the menu list based on available viewport space.
  • focus(): Focuses the first item in the menu.

Attributes

Name Field
expanded expanded
open-on-hover openOnHover

Slots

Name Description
trigger The trigger element for the menu
The menulist element

Template

<slot name="trigger" ${slotted({ property: 'trigger', filter: elements() })}></slot>
<span class="menu-list-container" ${ref('menuListContainer')} ?hidden="${(x) => !x.expanded}">
  <slot ${slotted({ property: 'menu', filter: elements() })}></slot>
</span>

Accessibility

WAI-ARIA Roles, States, and Properties

  • aria-haspopup
  • aria-expanded

Preparation

Fluent Web Component v3 v.s Fluent React 9


Component and Slot Mapping

Fluent UI React 9 Fluent Web Components 3
<Menu> <fluent-menu>
<MenuList> <fluent-menu-list>
<MenuItem> <fluent-menu-item>

Fluent UI React 9 Fluent Web Components Description of difference
hasIcons React implementation requires user to pass the hasIcons to align menu items with icons. The web components implimentation aligns content by default.
hasCheckmarks React implementation requires user to pass the hasCheckmarks to align menu items with checkmarks. The web components implimentation aligns content by default.

@fabricteam
Copy link
Collaborator

fabricteam commented May 18, 2023

📊 Bundle size report

🤖 This report was generated against 8057ad6e936dfd0473be71ce04bafad0ae582daa

@codesandbox-ci
Copy link

codesandbox-ci bot commented May 18, 2023

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 8d53f9c:

Sandbox Source
@fluentui/react 8 starter Configuration
@fluentui/react-components 9 starter Configuration

@size-auditor
Copy link

size-auditor bot commented May 18, 2023

Asset size changes

Size Auditor did not detect a change in bundle size for any component!

Baseline commit: 8057ad6e936dfd0473be71ce04bafad0ae582daa (build)


## **Design Spec**

[Link to Menu Design Spec in Figma](https://www.figma.com/file/xyz12345/Menu?node-id=2%3A476)
Copy link
Contributor

Choose a reason for hiding this comment

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

Broken link, but I can't find the actual Menu spec in the folder with the rest of the specs.


| Fluent UI React 9 | Fluent Web Components | Description of difference |
| ----------------- | --------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `hasIcons` | | React implementation requires user to pass the `hasIcons` to align menu items with icons. The web components implimentation aligns content by default. |
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: spelling -> implementation

| Fluent UI React 9 | Fluent Web Components | Description of difference |
| ----------------- | --------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `hasIcons` | | React implementation requires user to pass the `hasIcons` to align menu items with icons. The web components implimentation aligns content by default. |
| `hasCheckmarks` | | React implementation requires user to pass the `hasCheckmarks` to align menu items with checkmarks. The web components implimentation aligns content by default. |
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: spelling -> implementation

| `open` | public | `boolean` | `false` | Specifies if the menu is open or closed |
| `menuContainer` | public | `HTMLElement` | | The container element for the menu items |
| `openOnHover` | public | `boolean` | `false` | Sets whether the menu opens on hover of menu trigger |

Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want to add the other openOn* attributes from the React V9 implementation, such as: openOnContext, openOnChange?

Comment on lines +143 to +145
if (this.closeOnScroll) {
document.removeEventListener('scroll', this.closeMenu);
}
Copy link
Member

Choose a reason for hiding this comment

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

Edge case: if the close-on-scroll attribute changes between open and close, the event listener is never removed.

@brianchristopherbrady brianchristopherbrady merged commit 980b0d3 into microsoft:web-components-v3 Sep 27, 2023
chrisdholt pushed a commit that referenced this pull request Apr 29, 2024
* radio init

* styles radio

* reverts branch

* input spec init

* cleans up spec

* formatting

* updates component name to text input

* updates component name in spec

* menu: menu init

* menu: updates README

* menu: updates template, styles

* menu: updates menu and stories

* menu: removes dead code

* menu: removes folder and file

* yarn change

* menu: removes tab index on template slot

* menu changes based on feedback

* menu: updates stories

* menu, emits event on expanded change

* menu: updatews attr/property name to align with fluent ( expand --> open )

* menu: cleans up code

* reverts dead file

* menu: removes block styling

* enhances cleanup of autoUpdate, conditionally remove mouseover event listener

* Add defaultPrevented check to handleTriggerKeydown function

* menu: adds open/close features

* menu: fixes spelling error in readme

* menu: adds part selector to positioningRegion

* menu: adds z-index css variable, updates docs accordingly

* menu: adds attr changed callback for closeOnScroll to manage event listeners

* menu: adds exports
radium-v pushed a commit to radium-v/fluentui that referenced this pull request Apr 29, 2024
* radio init

* styles radio

* reverts branch

* input spec init

* cleans up spec

* formatting

* updates component name to text input

* updates component name in spec

* menu: menu init

* menu: updates README

* menu: updates template, styles

* menu: updates menu and stories

* menu: removes dead code

* menu: removes folder and file

* yarn change

* menu: removes tab index on template slot

* menu changes based on feedback

* menu: updates stories

* menu, emits event on expanded change

* menu: updatews attr/property name to align with fluent ( expand --> open )

* menu: cleans up code

* reverts dead file

* menu: removes block styling

* enhances cleanup of autoUpdate, conditionally remove mouseover event listener

* Add defaultPrevented check to handleTriggerKeydown function

* menu: adds open/close features

* menu: fixes spelling error in readme

* menu: adds part selector to positioningRegion

* menu: adds z-index css variable, updates docs accordingly

* menu: adds attr changed callback for closeOnScroll to manage event listeners

* menu: adds exports
radium-v pushed a commit to radium-v/fluentui that referenced this pull request Apr 29, 2024
* radio init

* styles radio

* reverts branch

* input spec init

* cleans up spec

* formatting

* updates component name to text input

* updates component name in spec

* menu: menu init

* menu: updates README

* menu: updates template, styles

* menu: updates menu and stories

* menu: removes dead code

* menu: removes folder and file

* yarn change

* menu: removes tab index on template slot

* menu changes based on feedback

* menu: updates stories

* menu, emits event on expanded change

* menu: updatews attr/property name to align with fluent ( expand --> open )

* menu: cleans up code

* reverts dead file

* menu: removes block styling

* enhances cleanup of autoUpdate, conditionally remove mouseover event listener

* Add defaultPrevented check to handleTriggerKeydown function

* menu: adds open/close features

* menu: fixes spelling error in readme

* menu: adds part selector to positioningRegion

* menu: adds z-index css variable, updates docs accordingly

* menu: adds attr changed callback for closeOnScroll to manage event listeners

* menu: adds exports
radium-v pushed a commit to radium-v/fluentui that referenced this pull request Apr 30, 2024
* radio init

* styles radio

* reverts branch

* input spec init

* cleans up spec

* formatting

* updates component name to text input

* updates component name in spec

* menu: menu init

* menu: updates README

* menu: updates template, styles

* menu: updates menu and stories

* menu: removes dead code

* menu: removes folder and file

* yarn change

* menu: removes tab index on template slot

* menu changes based on feedback

* menu: updates stories

* menu, emits event on expanded change

* menu: updatews attr/property name to align with fluent ( expand --> open )

* menu: cleans up code

* reverts dead file

* menu: removes block styling

* enhances cleanup of autoUpdate, conditionally remove mouseover event listener

* Add defaultPrevented check to handleTriggerKeydown function

* menu: adds open/close features

* menu: fixes spelling error in readme

* menu: adds part selector to positioningRegion

* menu: adds z-index css variable, updates docs accordingly

* menu: adds attr changed callback for closeOnScroll to manage event listeners

* menu: adds exports
radium-v pushed a commit that referenced this pull request Apr 30, 2024
* radio init

* styles radio

* reverts branch

* input spec init

* cleans up spec

* formatting

* updates component name to text input

* updates component name in spec

* menu: menu init

* menu: updates README

* menu: updates template, styles

* menu: updates menu and stories

* menu: removes dead code

* menu: removes folder and file

* yarn change

* menu: removes tab index on template slot

* menu changes based on feedback

* menu: updates stories

* menu, emits event on expanded change

* menu: updatews attr/property name to align with fluent ( expand --> open )

* menu: cleans up code

* reverts dead file

* menu: removes block styling

* enhances cleanup of autoUpdate, conditionally remove mouseover event listener

* Add defaultPrevented check to handleTriggerKeydown function

* menu: adds open/close features

* menu: fixes spelling error in readme

* menu: adds part selector to positioningRegion

* menu: adds z-index css variable, updates docs accordingly

* menu: adds attr changed callback for closeOnScroll to manage event listeners

* menu: adds exports
radium-v pushed a commit that referenced this pull request May 2, 2024
* radio init

* styles radio

* reverts branch

* input spec init

* cleans up spec

* formatting

* updates component name to text input

* updates component name in spec

* menu: menu init

* menu: updates README

* menu: updates template, styles

* menu: updates menu and stories

* menu: removes dead code

* menu: removes folder and file

* yarn change

* menu: removes tab index on template slot

* menu changes based on feedback

* menu: updates stories

* menu, emits event on expanded change

* menu: updatews attr/property name to align with fluent ( expand --> open )

* menu: cleans up code

* reverts dead file

* menu: removes block styling

* enhances cleanup of autoUpdate, conditionally remove mouseover event listener

* Add defaultPrevented check to handleTriggerKeydown function

* menu: adds open/close features

* menu: fixes spelling error in readme

* menu: adds part selector to positioningRegion

* menu: adds z-index css variable, updates docs accordingly

* menu: adds attr changed callback for closeOnScroll to manage event listeners

* menu: adds exports
radium-v pushed a commit that referenced this pull request May 2, 2024
* radio init

* styles radio

* reverts branch

* input spec init

* cleans up spec

* formatting

* updates component name to text input

* updates component name in spec

* menu: menu init

* menu: updates README

* menu: updates template, styles

* menu: updates menu and stories

* menu: removes dead code

* menu: removes folder and file

* yarn change

* menu: removes tab index on template slot

* menu changes based on feedback

* menu: updates stories

* menu, emits event on expanded change

* menu: updatews attr/property name to align with fluent ( expand --> open )

* menu: cleans up code

* reverts dead file

* menu: removes block styling

* enhances cleanup of autoUpdate, conditionally remove mouseover event listener

* Add defaultPrevented check to handleTriggerKeydown function

* menu: adds open/close features

* menu: fixes spelling error in readme

* menu: adds part selector to positioningRegion

* menu: adds z-index css variable, updates docs accordingly

* menu: adds attr changed callback for closeOnScroll to manage event listeners

* menu: adds exports
radium-v pushed a commit that referenced this pull request May 2, 2024
* radio init

* styles radio

* reverts branch

* input spec init

* cleans up spec

* formatting

* updates component name to text input

* updates component name in spec

* menu: menu init

* menu: updates README

* menu: updates template, styles

* menu: updates menu and stories

* menu: removes dead code

* menu: removes folder and file

* yarn change

* menu: removes tab index on template slot

* menu changes based on feedback

* menu: updates stories

* menu, emits event on expanded change

* menu: updatews attr/property name to align with fluent ( expand --> open )

* menu: cleans up code

* reverts dead file

* menu: removes block styling

* enhances cleanup of autoUpdate, conditionally remove mouseover event listener

* Add defaultPrevented check to handleTriggerKeydown function

* menu: adds open/close features

* menu: fixes spelling error in readme

* menu: adds part selector to positioningRegion

* menu: adds z-index css variable, updates docs accordingly

* menu: adds attr changed callback for closeOnScroll to manage event listeners

* menu: adds exports
radium-v pushed a commit that referenced this pull request May 3, 2024
* radio init

* styles radio

* reverts branch

* input spec init

* cleans up spec

* formatting

* updates component name to text input

* updates component name in spec

* menu: menu init

* menu: updates README

* menu: updates template, styles

* menu: updates menu and stories

* menu: removes dead code

* menu: removes folder and file

* yarn change

* menu: removes tab index on template slot

* menu changes based on feedback

* menu: updates stories

* menu, emits event on expanded change

* menu: updatews attr/property name to align with fluent ( expand --> open )

* menu: cleans up code

* reverts dead file

* menu: removes block styling

* enhances cleanup of autoUpdate, conditionally remove mouseover event listener

* Add defaultPrevented check to handleTriggerKeydown function

* menu: adds open/close features

* menu: fixes spelling error in readme

* menu: adds part selector to positioningRegion

* menu: adds z-index css variable, updates docs accordingly

* menu: adds attr changed callback for closeOnScroll to manage event listeners

* menu: adds exports
radium-v pushed a commit that referenced this pull request May 6, 2024
* radio init

* styles radio

* reverts branch

* input spec init

* cleans up spec

* formatting

* updates component name to text input

* updates component name in spec

* menu: menu init

* menu: updates README

* menu: updates template, styles

* menu: updates menu and stories

* menu: removes dead code

* menu: removes folder and file

* yarn change

* menu: removes tab index on template slot

* menu changes based on feedback

* menu: updates stories

* menu, emits event on expanded change

* menu: updatews attr/property name to align with fluent ( expand --> open )

* menu: cleans up code

* reverts dead file

* menu: removes block styling

* enhances cleanup of autoUpdate, conditionally remove mouseover event listener

* Add defaultPrevented check to handleTriggerKeydown function

* menu: adds open/close features

* menu: fixes spelling error in readme

* menu: adds part selector to positioningRegion

* menu: adds z-index css variable, updates docs accordingly

* menu: adds attr changed callback for closeOnScroll to manage event listeners

* menu: adds exports
radium-v pushed a commit that referenced this pull request May 6, 2024
* radio init

* styles radio

* reverts branch

* input spec init

* cleans up spec

* formatting

* updates component name to text input

* updates component name in spec

* menu: menu init

* menu: updates README

* menu: updates template, styles

* menu: updates menu and stories

* menu: removes dead code

* menu: removes folder and file

* yarn change

* menu: removes tab index on template slot

* menu changes based on feedback

* menu: updates stories

* menu, emits event on expanded change

* menu: updatews attr/property name to align with fluent ( expand --> open )

* menu: cleans up code

* reverts dead file

* menu: removes block styling

* enhances cleanup of autoUpdate, conditionally remove mouseover event listener

* Add defaultPrevented check to handleTriggerKeydown function

* menu: adds open/close features

* menu: fixes spelling error in readme

* menu: adds part selector to positioningRegion

* menu: adds z-index css variable, updates docs accordingly

* menu: adds attr changed callback for closeOnScroll to manage event listeners

* menu: adds exports
radium-v pushed a commit that referenced this pull request May 8, 2024
* radio init

* styles radio

* reverts branch

* input spec init

* cleans up spec

* formatting

* updates component name to text input

* updates component name in spec

* menu: menu init

* menu: updates README

* menu: updates template, styles

* menu: updates menu and stories

* menu: removes dead code

* menu: removes folder and file

* yarn change

* menu: removes tab index on template slot

* menu changes based on feedback

* menu: updates stories

* menu, emits event on expanded change

* menu: updatews attr/property name to align with fluent ( expand --> open )

* menu: cleans up code

* reverts dead file

* menu: removes block styling

* enhances cleanup of autoUpdate, conditionally remove mouseover event listener

* Add defaultPrevented check to handleTriggerKeydown function

* menu: adds open/close features

* menu: fixes spelling error in readme

* menu: adds part selector to positioningRegion

* menu: adds z-index css variable, updates docs accordingly

* menu: adds attr changed callback for closeOnScroll to manage event listeners

* menu: adds exports
radium-v pushed a commit that referenced this pull request May 10, 2024
* radio init

* styles radio

* reverts branch

* input spec init

* cleans up spec

* formatting

* updates component name to text input

* updates component name in spec

* menu: menu init

* menu: updates README

* menu: updates template, styles

* menu: updates menu and stories

* menu: removes dead code

* menu: removes folder and file

* yarn change

* menu: removes tab index on template slot

* menu changes based on feedback

* menu: updates stories

* menu, emits event on expanded change

* menu: updatews attr/property name to align with fluent ( expand --> open )

* menu: cleans up code

* reverts dead file

* menu: removes block styling

* enhances cleanup of autoUpdate, conditionally remove mouseover event listener

* Add defaultPrevented check to handleTriggerKeydown function

* menu: adds open/close features

* menu: fixes spelling error in readme

* menu: adds part selector to positioningRegion

* menu: adds z-index css variable, updates docs accordingly

* menu: adds attr changed callback for closeOnScroll to manage event listeners

* menu: adds exports
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants