最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to customize md-select's popup menu in Angular Material? - Stack Overflow

programmeradmin6浏览0评论

I need to define a special class for some md-select's popup menus (not to all). But I have no idea how to do that.

Here is a code sample of typical usage and here is no place where I can define a class for menu container that will appear.

<md-input-container md-no-float class="md-block defaultInputSelect filterType">
  <md-select ng-model="value.filter_type" md-on-close="viewChanged()">
    <md-option ng-repeat="(key, value) in filterTypes" value="{{value}}">
      {{filterTypesNames[key]}}
    </md-option>
  </md-select>
</md-input-container>

Actually, I want to change the width of popup menu. By default it is limited by the width of md-select.

I need to define a special class for some md-select's popup menus (not to all). But I have no idea how to do that.

Here is a code sample of typical usage and here is no place where I can define a class for menu container that will appear.

<md-input-container md-no-float class="md-block defaultInputSelect filterType">
  <md-select ng-model="value.filter_type" md-on-close="viewChanged()">
    <md-option ng-repeat="(key, value) in filterTypes" value="{{value}}">
      {{filterTypesNames[key]}}
    </md-option>
  </md-select>
</md-input-container>

Actually, I want to change the width of popup menu. By default it is limited by the width of md-select.

Share Improve this question edited Jun 25, 2018 at 13:16 Mosh Feu 29.4k18 gold badges93 silver badges141 bronze badges asked May 18, 2016 at 5:31 splash27splash27 2,1176 gold badges26 silver badges54 bronze badges 2
  • Could you clarify what exactly you want to do? Maybe then we can point you in the right direction – johan Commented May 18, 2016 at 5:40
  • @johan, I want to change the width of popup menu. Edited the question. – splash27 Commented May 18, 2016 at 5:51
Add a ment  | 

1 Answer 1

Reset to default 5

Hi there please look at the following plunkr, the following selector seems to work fine to affect the whole ponent

https://plnkr.co/edit/sp7mKuaeztfAgtujARcw?p=preview

 <style type="text/css">
    md-input-container,
    md-input-container > * {
      width: 100% !important;
    }
  </style>

Edit: Here you go, this will only affect the select dropdown

https://plnkr.co/edit/sp7mKuaeztfAgtujARcw?p=preview

<style type="text/css">
   ._md-select-menu-container
    {
      width: 100% !important;
    }
  </style>

Final Edit: Simply add the md-container-class="myclass" directive to your md-select

https://plnkr.co/edit/sp7mKuaeztfAgtujARcw?p=preview

<style type="text/css">
  .myclass {
    width: 100% !important;
  }
</style>

<md-select md-container-class="myclass" ng-model="selectedItem" md-selected-text="getSelectedText()">
  <md-optgroup label="items">
    <md-option ng-value="item" ng-repeat="item in items">Item {{item}}</md-option>
  </md-optgroup>
</md-select>
发布评论

评论列表(0)

  1. 暂无评论