material icon indicating copy to clipboard operation
material copied to clipboard

How do you set the md-menu active Item

Open deliriousrhino opened this issue 11 years ago • 15 comments

When you first click the menu the first item has a grey background https://material.angularjs.org/latest/#/demo/material.components.menu

How do I set which item is preselected like this or get rid of this altogether. screen shot 2015-06-23 at 2 14 00 pm

deliriousrhino avatar Jun 23 '15 04:06 deliriousrhino

(function () {
    "use strict";
    angular
        .module('starter.directives', [])
        .directive('mdLink',function($location){
            return {
                restrict:'A',
                link:function(scope, element, attrs){
                    var url=attrs.href;
                    var addedCss=attrs.mdLink;
                    scope.location=$location;
                    scope.$watch('location.absUrl()',function(newUrl){
                        if (url === newUrl) {
                            element.addClass(addedCss);
                        } else {
                            element.removeClass(addedCss);
                        }
                    });
                }
            }
        });
})();

tianvan avatar Jun 23 '15 05:06 tianvan

@vanntian How does this relate to the md-menu directive https://material.angularjs.org/latest/#/demo/material.components.menu

deliriousrhino avatar Jun 23 '15 05:06 deliriousrhino

@deliriousrhino that is added for accessibility. It is a focus state. Will talk to the team to see if this is something that we want to support removing

rschmukler avatar Jul 09 '15 17:07 rschmukler

+1

michaelkrog avatar Jul 15 '15 16:07 michaelkrog

+1

george3447 avatar Jul 15 '15 18:07 george3447

:+1:

Edit: My current use case requires to remove auto-focusing the first element. Users get confused because they think that this element is already active.

maelfrize avatar Jul 29 '15 08:07 maelfrize

Please give us the option to remove it. It's good for accessibility, but doesn't really make sense for users to have the first item auto focused.

johnnyluu avatar Jul 30 '15 10:07 johnnyluu

+1

lbialachowski-act avatar Jul 31 '15 13:07 lbialachowski-act

It's a problem that the first element is still active while I hover over other items. That way, it looks like multiple items are active at the same time. It also looks like the first item is "something special"/highlighted, because it stays highlighted until I click a menu item or press an arrow button. It draws extra attention where extra attention is not wanted/needed.

menu-issue

iver56 avatar Aug 18 '15 17:08 iver56

+1, problem persisting here, same above.

felipekm avatar Aug 28 '15 19:08 felipekm

This is especially problematic when you have an ng-repeat of md-menu-items followed by manually added md-menu-items. See this codepen: http://codepen.io/anon/pen/xwjzMy?editors=101. If you scroll all the way down and back up, you'll see that the "Save search as filter" stays highlighted.

erinjanae avatar Oct 28 '15 19:10 erinjanae

The hover issues described by @erinjanae have been resolved. The focus and hover states now behave correctly. The initial focus state is per the spec and important for accessibility. If you really want to restyle it, the best way would probably be by overriding styles.

Here is the demo above running on master

rschmukler avatar Nov 12 '15 19:11 rschmukler

@rschmukler OK, so this initial focus state is according to the spec? I will argue that this behaviour needs looking at again and that there should be an override option. I'm experiencing the exact problem that @iver56 has above.

ghost avatar Nov 21 '15 13:11 ghost

For anyone still having issue with this, this is how I got around it:

.system-menu {
  .md-button.md-default-theme:not([disabled]):focus, .md-button:not([disabled]):focus {
    background-color: transparent;
  }
}

ulesta avatar Nov 14 '16 01:11 ulesta

I was able to fix this with the following. This is the only thing that worked for me and we also had a disabled class so I applied the enabled selector to prevent the disabled items from showing the gray hover background:

  .md-button:first-child:enabled {
    background-color: #fff;
  }

  .md-button:first-child:hover:enabled {
    background-color: rgba(158,158,158,0.2);
  }

jenktam avatar May 29 '18 21:05 jenktam