Skip to content

Commit

Permalink
feat: optimize code
Browse files Browse the repository at this point in the history
  • Loading branch information
kiner-tang committed Aug 31, 2023
1 parent 9f076da commit 913e53f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
4 changes: 4 additions & 0 deletions src/Icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ export interface IconProps {
export default function Icon({ icon, props, children }: IconProps) {
let iconNode: React.ReactElement;

if (icon === null || icon === false) {
return null;
}

if (typeof icon === 'function') {
iconNode = React.createElement(icon as any, {
...props,
Expand Down
7 changes: 2 additions & 5 deletions src/SubMenu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ const InternalSubMenu = (props: SubMenuProps) => {
// ================================ Icon ================================
const mergedItemIcon = itemIcon ?? contextItemIcon;
const mergedExpandIcon = expandIcon ?? contextExpandIcon;
const expandable = mergedExpandIcon !== null && mergedExpandIcon !== false;

// ================================ Open ================================
const originOpen = openKeys.includes(eventKey);
Expand Down Expand Up @@ -248,9 +247,8 @@ const InternalSubMenu = (props: SubMenuProps) => {
{title}

{/* Only non-horizontal mode shows the icon */}
{expandable && (
<Icon
icon={mode !== 'horizontal' ? mergedExpandIcon : null}
<Icon
icon={mode !== 'horizontal' ? mergedExpandIcon : undefined}
props={{
...props,
isOpen: open,
Expand All @@ -260,7 +258,6 @@ const InternalSubMenu = (props: SubMenuProps) => {
>
<i className={`${subMenuPrefixCls}-arrow`} />
</Icon>
)}

</div>
);
Expand Down

0 comments on commit 913e53f

Please sign in to comment.