diff --git a/examples/docs/en-US/menu.md b/examples/docs/en-US/menu.md index ea60f81b5..46f6807be 100644 --- a/examples/docs/en-US/menu.md +++ b/examples/docs/en-US/menu.md @@ -3,7 +3,7 @@ .el-menu-demo { padding-left: 55px; } - .el-menu-vertical-demo { + .el-menu-vertical-demo:not(.el-menu--collapse) { width: 200px; min-height: 400px; } @@ -33,7 +33,8 @@ data() { return { activeIndex: '1', - activeIndex2: '1' + activeIndex2: '1', + isCollapse: false }; }, methods: { @@ -179,10 +180,70 @@ Vertical NavMenu with sub-menus. ``` ::: +### Collapse + +Vertical NavMenu could be collapsed. + +::: demo +```html + + expand + collapse + + + + + + Group One + item one + item two + + + item three + + + item four + item one + + + + + Navigator Two + + + + Navigator Three + + + + +``` +::: + ### Menu Attribute | Attribute | Description | Type | Accepted Values | Default | |---------- |-------- |---------- |------------- |-------- | | mode | menu display mode | string | horizontal/vertical | vertical | +| collapse | whether the menu is collapsed (available only in vertical mode) | boolean | — | false | | theme | theme color | string | light/dark | light | | default-active | index of currently active menu | string | — | — | | default-openeds | array that contains keys of currently active sub-menus | Array | — | — | diff --git a/examples/docs/zh-CN/menu.md b/examples/docs/zh-CN/menu.md index 34ad52f80..2e594b940 100644 --- a/examples/docs/zh-CN/menu.md +++ b/examples/docs/zh-CN/menu.md @@ -3,7 +3,7 @@ .el-menu-demo { padding-left: 55px; } - .el-menu-vertical-demo { + .el-menu-vertical-demo:not(.el-menu--collapse) { width: 200px; min-height: 400px; } @@ -33,7 +33,8 @@ data() { return { activeIndex: '1', - activeIndex2: '1' + activeIndex2: '1', + isCollapse: true }; }, methods: { @@ -181,10 +182,68 @@ ``` ::: +### 折叠 + +::: demo +```html + + 展开 + 收起 + + + + + + 分组一 + 选项1 + 选项2 + + + 选项3 + + + 选项4 + 选项1 + + + + + 导航二 + + + + 导航三 + + + + +``` +::: + ### Menu Attribute | 参数 | 说明 | 类型 | 可选值 | 默认值 | |---------- |-------- |---------- |------------- |-------- | | mode | 模式 | string | horizontal,vertical | vertical | +| collapse | 是否水平折叠收起菜单(仅在 mode 为 vertical 时可用)| boolean | — | false | | theme | 主题色 | string | light,dark | light | | default-active | 当前激活菜单的 index | string | — | — | | default-openeds | 当前打开的submenu的 key 数组 | Array | — | — | diff --git a/packages/menu/src/menu-item-group.vue b/packages/menu/src/menu-item-group.vue index 23d9d8a2b..617a63601 100644 --- a/packages/menu/src/menu-item-group.vue +++ b/packages/menu/src/menu-item-group.vue @@ -15,6 +15,7 @@ componentName: 'ElMenuItemGroup', + inject: ['rootMenu'], props: { title: { type: String @@ -29,6 +30,7 @@ levelPadding() { let padding = 10; let parent = this.$parent; + if (this.rootMenu.collapse) return 20; while (parent && parent.$options.componentName !== 'ElMenu') { if (parent.$options.componentName === 'ElSubmenu') { padding += 20; diff --git a/packages/menu/src/menu-item.vue b/packages/menu/src/menu-item.vue index 6469ee7b7..ac0df06a2 100644 --- a/packages/menu/src/menu-item.vue +++ b/packages/menu/src/menu-item.vue @@ -6,7 +6,19 @@ 'is-active': active, 'is-disabled': disabled }"> - + +
+
+ +
+
+ diff --git a/packages/theme-default/src/common/transition.css b/packages/theme-default/src/common/transition.css index c2a06560c..7a4dc6ddd 100644 --- a/packages/theme-default/src/common/transition.css +++ b/packages/theme-default/src/common/transition.css @@ -68,9 +68,25 @@ transform: scaleY(0); } +.el-zoom-in-left-enter-active, +.el-zoom-in-left-leave-active { + opacity: 1; + transform: scale(1, 1); + transition: var(--md-fade-transition); + transform-origin: top left; +} +.el-zoom-in-left-enter, +.el-zoom-in-left-leave-active { + opacity: 0; + transform: scale(.45, .45); +} + .collapse-transition { transition: 0.3s height ease-in-out, 0.3s padding-top ease-in-out, 0.3s padding-bottom ease-in-out; } +.horizontal-collapse-transition { + transition: 0.3s width ease-in-out, 0.3s padding-left ease-in-out, 0.3s padding-right ease-in-out; +} .el-list-enter-active, .el-list-leave-active { @@ -79,4 +95,8 @@ .el-list-enter, .el-list-leave-active { opacity: 0; transform: translateY(-30px); +} + +.el-opacity-transition { + transition: opacity .3s cubic-bezier(.55,0,.1,1); } \ No newline at end of file diff --git a/packages/theme-default/src/menu.css b/packages/theme-default/src/menu.css index c9aec06c0..c42e87f30 100644 --- a/packages/theme-default/src/menu.css +++ b/packages/theme-default/src/menu.css @@ -23,7 +23,7 @@ padding-left: 0; background-color: var(--menu-item-fill); @utils-clearfix; - + & li { list-style: none; } @@ -137,6 +137,45 @@ } } } + @m collapse { + width: 64px; + + > .el-menu-item, + > .el-submenu > .el-submenu__title { + text-align: center; + [class^="el-icon-"] { + margin: 0; + vertical-align: middle; + } + .el-submenu__icon-arrow { + display: none; + } + span { + height: 0; + width: 0; + overflow: hidden; + visibility: hidden; + display: inline-block; + } + } + + .el-submenu { + position: relative; + & .el-menu { + position: absolute; + margin-left: 5px; + top: 0; + left: 100%; + z-index: 10; + } + + &.is-opened { + > .el-submenu__title .el-submenu__icon-arrow { + transform: none; + } + } + } + } } @b menu-item { @extend menu-item; @@ -175,6 +214,7 @@ height: 50px; line-height: 50px; padding: 0 45px; + min-width: 200px; &:hover { background-color: var(--color-base-gray);