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

MdMenu : keep menu open on item click #2612

Closed
Robouste opened this issue Jan 12, 2017 · 12 comments
Closed

MdMenu : keep menu open on item click #2612

Robouste opened this issue Jan 12, 2017 · 12 comments
Labels
feature This issue represents a new feature or feature request rather than a bug or bug fix needs: discussion Further discussion with the team is needed before proceeding

Comments

@Robouste
Copy link

Bug, feature request, or proposal:

feature request

What is the expected behavior?

It would be great to have an option to keep the menu open when we click a menu item

What is the current behavior?

On item menu click, the menu closes

What are the steps to reproduce?

Plunkr

What is the use-case or motivation for changing an existing behavior?

Putting checkboxes in the menu for example

Which versions of Angular, Material, OS, browsers are affected?

All

Is there anything else we should know?

@Robouste Robouste changed the title MdMenu : keep menu open on click MdMenu : keep menu open on item click Jan 12, 2017
@jelbourn jelbourn added discussion feature This issue represents a new feature or feature request rather than a bug or bug fix labels Jan 27, 2017
@nayfin
Copy link
Contributor

nayfin commented Feb 1, 2017

I would like to utilize this feature to allow menu to take text inputs. Perhaps a new directive:

md-menu-dont-close

We could throw this on the md-menu-items that we don't want to close the menu. We will likely have some items that we wish would close the menu and others that we wouldn't. Such as a short login form with with a few inputs and a submit button. We don't want menu to close while we are trying to enter text into inputs, but we do want it to close after clicking submit.

@nayfin
Copy link
Contributor

nayfin commented Feb 2, 2017

I just found this in the ReadMe:

`Not yet implemented

  • ‘prevent-close' option, to turn off automatic menu close when clicking outside the menu `

Which isn't quite what we are looking for, but it's close and a good indication that similar features are being considered.

From what I've read of the source we just need to prevent click events on md-menu-items from propagating up to the menu. If anyone has some pro tips before I get started I'm happy to hear them. I'll try to put together a splunkr over the weekend and submit a PR once it's working.

@nayfin
Copy link
Contributor

nayfin commented Feb 3, 2017

@Robouste Here's an ugly workaround. I'll turn it into a directive soon and update. For some reason using this with md-menu-item keeps menu open but doesn't allow inputs or checkboxes to register clicks or become focused. Take out the md-menu-item directive and everything works fine, just doesn't look quite as nice.

@Robouste
Copy link
Author

Robouste commented Feb 3, 2017

@nayfin Thank you, it seems to do the trick. But I choose the bootstrap dropdown, more customizable (for now !)

@randallmeeker
Copy link

I have an input in my menu and this worked find
<input class="input-log" (click)="$event.stopPropagation()" type="text" />

@ccadieux
Copy link

Being able to turn this off would be great. We implemented a menu very similar to the google inbox account menu and ran into this issue. We had to add a click handler and stopPropagation on the entire menu.

@jelbourn
Copy link
Member

Chatted w/ @kara about this and we decided that we don't want to add this as a feature to md-menu. This is largely because turning it on would be detrimental to the a11y experience (see https://www.w3.org/TR/wai-aria-practices-1.1/#menu), and we want to generally avoid adding APIs that go counter to a11y best practices.

@hghammoud
Copy link

For those who are waiting for this to be merged, this is how i did it to implement a multi-select columns in a table (i didnt want the input part of select).

I basically removed the md-menu-item directive and used the class mat-menu-item for the styling.

<md-menu #appMenu="mdMenu">
    <div *ngFor="let column of columns" class="mat-menu-item" style="overflow: visible;">
        <md-checkbox [(ngModel)]="column.show" (click)="$event.stopPropagation()" >{{column.name}}</md-checkbox>
    </div>
</md-menu>
<button md-button color="primary" [mdMenuTriggerFor]="appMenu">Select columns</button>

Hope this helps.

@mikila85
Copy link

mikila85 commented Mar 6, 2018

@jelbourn @kara
Dont know what you guys talking about.. ("This is largely because turning it on would be detrimental to the a11y experience")
a11yproject.com -> Menu->Dropdown
Sends you here:
Codepen
Codepen2

Clearly shows when clicking on the menu it doesn't close.
If so many people ask for it, probably needed and will help the users.
Please reconsider and dont c**k-block your ecosystem PLZ 🥇
<3

@sarbull
Copy link

sarbull commented Mar 29, 2018

import {Directive, HostListener} from '@angular/core';

@Directive({
    selector: '[click-stop-propagation]'
})
export class ClickStopPropagation {
    @HostListener('click', ['$event'])
    public onClick(event: any): void {
        event.stopPropagation();
    }
}
<div click-stop-propagation>Stop Propagation</div>

source: https://stackoverflow.com/a/41001184/1527666

@jpike88
Copy link

jpike88 commented Jun 3, 2019

turning it on would be detrimental to the a11y experience

And the irony is, blocking it from being used is detrimental to everyone's experience. Devs, and users included. I don't even know why this a11y thing is taking precedence over common sense, and established UI standards.

The only reason I'm even posting in this issue is that the angular material library has failed to provide some sort of popover component that animates from the button that was clicked, or instead opens as a full-screen overlay on narrow screens. Such a fundamental component that's been around on mobile and web forever (easily achievable on the Android and iOS SDK), which would utilise your existing components in a pretty simple way. I used to have md-panel at least:

https://material.angularjs.org/1.1.1/api/type/MdPanelPosition

But currently, I have to either twist a mat-menu to meet my needs, to use a dialog which also gives me no control over where it animates from. And what I'm making is totally fine from an accessibility standpoint...

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 10, 2019
@mmalerba mmalerba added the needs: discussion Further discussion with the team is needed before proceeding label Mar 3, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature This issue represents a new feature or feature request rather than a bug or bug fix needs: discussion Further discussion with the team is needed before proceeding
Projects
None yet
Development

No branches or pull requests

10 participants