From 5cfd0fa06f059b9d00b8828db665f847ced8c09d Mon Sep 17 00:00:00 2001 From: youluna Date: Thu, 18 Jul 2019 18:33:53 +0800 Subject: [PATCH] fix(Nav): label should show in iconOnly mode, close #894 --- src/nav/group.jsx | 5 +---- src/nav/item.jsx | 5 +---- src/nav/main.scss | 20 +++++++------------- src/nav/popup-item.jsx | 2 -- src/nav/sub-nav.jsx | 2 -- test/nav/index-spec.js | 8 ++++---- 6 files changed, 13 insertions(+), 29 deletions(-) diff --git a/src/nav/group.jsx b/src/nav/group.jsx index 1b16d6b05d..839ad321e6 100644 --- a/src/nav/group.jsx +++ b/src/nav/group.jsx @@ -37,10 +37,7 @@ class Group extends Component { let newLabel = label; if (iconOnly) { // TODO: add a group icon ? - newLabel = [ - , - {label}, - ]; + newLabel = [{label}]; } const cls = classNames({ diff --git a/src/nav/item.jsx b/src/nav/item.jsx index dbb2ea1b2e..3dcf8e28ce 100644 --- a/src/nav/item.jsx +++ b/src/nav/item.jsx @@ -34,15 +34,12 @@ class Item extends Component { render() { const { prefix, iconOnly, hasTooltip } = this.context; const { icon, children, ...others } = this.props; - let iconEl = + const iconEl = typeof icon === 'string' ? ( ) : ( icon ); - if (iconOnly && !iconEl) { - iconEl = ; - } const item = ( diff --git a/src/nav/main.scss b/src/nav/main.scss index 5d434695ef..3b8b8ed502 100644 --- a/src/nav/main.scss +++ b/src/nav/main.scss @@ -18,14 +18,6 @@ $nav-icononly-width: $s-15; font-weight: inherit; } - &-icon-placeholder { - display: inline-block; - width: $nav-icon-only-font-size; - height: $nav-icon-only-font-size; - margin-left: ($nav-icononly-width - $nav-icon-only-font-size) / 2 - $nav-ver-item-padding-lr - $nav-primary-border-width; - margin-right: ($nav-icononly-width - $nav-icon-only-font-size) / 2 - $nav-ver-item-padding-lr - $nav-primary-border-width; - } - &-group-label { height: $nav-group-height; line-height: $nav-group-height; @@ -349,10 +341,10 @@ $nav-icononly-width: $s-15; text-overflow: clip; } - #{$menu-prefix}-item-text > span, - #{$nav-prefix}-group-label > #{$menu-prefix}-item-inner > span { - opacity: 0; - } + // #{$menu-prefix}-item-text > span, + // #{$nav-prefix}-group-label > #{$menu-prefix}-item-inner > span { + // opacity: 0; + // } &.#{$css-prefix}normal { #{$nav-prefix}-icon.#{$css-prefix}icon { @@ -387,7 +379,8 @@ $nav-icononly-width: $s-15; #{$nav-prefix}-icon-only-arrow.#{$css-prefix}icon { @include icon-size( $size: $nav-icon-only-font-size, - $marginLeft: (18px - $nav-icon-only-font-size) / 2 + $marginLeft: (18px - $nav-icon-only-font-size) / 2, + $marginRight: (18px - $nav-icon-only-font-size) / 2 ); transition: all ease .3s; transform-origin: center 46%; @@ -397,6 +390,7 @@ $nav-icononly-width: $s-15; @include icon-size( $size: $nav-icon-only-font-size, $marginLeft: (18px - $nav-icon-only-font-size) / 2, + $marginRight: (18px - $nav-icon-only-font-size) / 2, $transform: rotate(180deg) ); } diff --git a/src/nav/popup-item.jsx b/src/nav/popup-item.jsx index 91224da625..785d27543f 100644 --- a/src/nav/popup-item.jsx +++ b/src/nav/popup-item.jsx @@ -57,8 +57,6 @@ class PopupItem extends Component { type="arrow-right" /> ); - } else if (!iconEl) { - iconEl = ; } } const newLabel = [ diff --git a/src/nav/sub-nav.jsx b/src/nav/sub-nav.jsx index 2a9b51c2d6..16e95fa217 100644 --- a/src/nav/sub-nav.jsx +++ b/src/nav/sub-nav.jsx @@ -66,8 +66,6 @@ class SubNav extends Component { type={mode === 'popup' ? 'arrow-right' : 'arrow-down'} /> ); - } else if (!iconEl) { - iconEl = ; } } const newLabel = [ diff --git a/test/nav/index-spec.js b/test/nav/index-spec.js index 5c0f28be1d..5404b82291 100644 --- a/test/nav/index-spec.js +++ b/test/nav/index-spec.js @@ -265,7 +265,7 @@ describe('Nav', () => { let items = nav.find('li.next-nav-item'); assert(items.at(0).find('i.next-nav-icon').length === 1); - assert(items.at(1).find('span.next-nav-icon-placeholder').length === 1); + assert(items.at(1).find('i.next-nav-icon').length === 0); let subNavItems = nav.find('li.next-nav-sub-nav-item'); assert( @@ -296,7 +296,7 @@ describe('Nav', () => { ); const groupLabel = nav.find('li.next-nav-group-label'); - assert(groupLabel.find('span.next-nav-icon-placeholder').length === 1); + assert(groupLabel.find('.next-menu-item-inner > span').length === 1); wrapper.setProps({ mode: 'popup', @@ -324,13 +324,13 @@ describe('Nav', () => { subNavItems = nav.find('li.next-nav-sub-nav-item'); assert(subNavItems.at(0).find('i.next-nav-icon').length === 1); assert( - subNavItems.at(1).find('span.next-nav-icon-placeholder').length === + subNavItems.at(1).find('.next-menu-item-text > span').length === 1 ); popupItems = nav.find('li.next-nav-popup-item'); assert(popupItems.at(0).find('i.next-nav-icon').length === 1); assert( - popupItems.at(1).find('span.next-nav-icon-placeholder').length === 1 + popupItems.at(1).find('.next-menu-item-text > span').length === 1 ); items = nav.find('li.next-nav-item'); items.at(0).simulate('mouseenter');