Width of contextual menu

2019-07-26 19:57发布

I am trying to use the command bar of ng-office-ui-fabric, and modify the width of uif-contextextual-menu-item. Here is a code

<!DOCTYPE html>
<html>
<head>
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
  <link rel="stylesheet" href="https://static2.sharepointonline.com/files/fabric/office-ui-fabric-core/2.6.3/css/fabric.min.css" />
  <link rel="stylesheet" href="https://static2.sharepointonline.com/files/fabric/office-ui-fabric-core/2.6.3/css/fabric.components.min.css" />
  <script src="https://cdnjs.cloudflare.com/ajax/libs/ngOfficeUiFabric/0.15.3/ngOfficeUiFabric.min.js"></script>
  <style>
    .menu1.ms-ContextualMenu {
      width: 110px
    }
  </style>
</head>
<body ng-app="YourApp"> 
  <div ng-controller="YourController">
      <uif-command-bar>
        <uif-command-bar-main>
          <uif-command-bar-item>
            <span>14</span>
            <uif-icon uif-type="chevronDown"></uif-icon>
            <uif-contextual-menu uif-is-open="true" class="menu1">
              <uif-contextual-menu-item uif-text="'add'"></uif-contextual-menu-item>
              <uif-contextual-menu-item uif-text="'minus'"></uif-contextual-menu-item>
              <uif-contextual-menu-item uif-type="subMenu">
                <uif-content>Versions</uif-content>
                  <uif-contextual-menu uif-is-open="true">
                    <uif-contextual-menu-item uif-text="'1'"></uif-contextual-menu-item>
                    <uif-contextual-menu-item uif-text="'2'"></uif-contextual-menu-item>
                  </uif-contextual-menu>
                </uif-contextual-menu-item>
            </uif-contextual-menu>
          </uif-command-bar-item>
        </uif-command-bar-main>
      </uif-command-bar>
  </div>
  <script type="text/javascript"> 
    angular.module('YourApp', ['officeuifabric.core', 'officeuifabric.components'])
    .controller('YourController', ['$scope', function ($scope) {}])
  </script> 
</body>
</html>

As you can see, i managed to modify the width of the first menu by .menu1.ms-ContextualMenu (because it was too large), but the position of the submenu became uncorrect. Does anyone know how to fix this?

2条回答
一纸荒年 Trace。
2楼-- · 2019-07-26 20:37

Just change the left property for the submenu in CSS accordingly:

.ms-ContextualMenu-link.ms-ContextualMenu-link--hasMenu ~ .ms-ContextualMenu {
    left: 108px;
}

Modified your jsbin: https://jsbin.com/fowahoxiqu/edit?html,output

查看更多
贼婆χ
3楼-- · 2019-07-26 20:44

Similar to the previous answer, if you make left: 100% instead of a fixed pixel width, you can change the width of the navigation to your heart's content and it will always stay where it should.

.menu1.ms-ContextualMenu .ms-ContextualMenu {
    left: 100%;
}
查看更多
登录 后发表回答