fix: dropdown submenu style error #4351

close #4351
pull/4361/head
tangjinzhou 2021-07-11 14:13:07 +08:00
parent fb94726a1e
commit c20c1f2a32
5 changed files with 15 additions and 6 deletions

View File

@ -63,7 +63,7 @@ const Dropdown = defineComponent({
// menu should be focusable in dropdown defaultly // menu should be focusable in dropdown defaultly
const overlayProps = overlayNode && getPropsData(overlayNode); const overlayProps = overlayNode && getPropsData(overlayNode);
const { selectable = false, focusable = true } = (overlayProps || {}) as any; const { selectable = false, focusable = true } = (overlayProps || {}) as any;
const expandIcon = ( const expandIcon = () => (
<span class={`${prefixCls}-menu-submenu-arrow`}> <span class={`${prefixCls}-menu-submenu-arrow`}>
<RightOutlined class={`${prefixCls}-menu-submenu-arrow-icon`} /> <RightOutlined class={`${prefixCls}-menu-submenu-arrow-icon`} />
</span> </span>

View File

@ -68,6 +68,9 @@
&-submenu-popup { &-submenu-popup {
position: absolute; position: absolute;
z-index: @zindex-dropdown; z-index: @zindex-dropdown;
background: transparent;
box-shadow: none;
transform-origin: 0 0;
> .@{dropdown-prefix-cls}-menu { > .@{dropdown-prefix-cls}-menu {
transform-origin: 0 0; transform-origin: 0 0;
@ -81,7 +84,6 @@
ul { ul {
margin-right: 0.3em; margin-right: 0.3em;
margin-left: 0.3em; margin-left: 0.3em;
padding: 0;
} }
} }

View File

@ -49,6 +49,8 @@ export const menuProps = {
triggerSubMenuAction: { type: String as PropType<TriggerSubMenuAction>, default: 'hover' }, triggerSubMenuAction: { type: String as PropType<TriggerSubMenuAction>, default: 'hover' },
getPopupContainer: Function as PropType<(node: HTMLElement) => HTMLElement>, getPopupContainer: Function as PropType<(node: HTMLElement) => HTMLElement>,
expandIcon: Function as PropType<(p?: { isOpen: boolean; [key: string]: any }) => any>,
}; };
export type MenuProps = Partial<ExtractPropTypes<typeof menuProps>>; export type MenuProps = Partial<ExtractPropTypes<typeof menuProps>>;
@ -66,6 +68,7 @@ export default defineComponent({
'click', 'click',
'update:activeKey', 'update:activeKey',
], ],
slots: ['expandIcon'],
setup(props, { slots, emit }) { setup(props, { slots, emit }) {
const { prefixCls, direction } = useConfigInject('menu', props); const { prefixCls, direction } = useConfigInject('menu', props);
const store = ref<Record<string, StoreMenuInfo>>({}); const store = ref<Record<string, StoreMenuInfo>>({});
@ -371,6 +374,7 @@ export default defineComponent({
unRegisterMenuInfo, unRegisterMenuInfo,
selectedSubMenuEventKeys, selectedSubMenuEventKeys,
isRootMenu: true, isRootMenu: true,
expandIcon: props.expandIcon || slots.expandIcon,
}); });
return () => { return () => {
const childList = flattenChildren(slots.default?.()); const childList = flattenChildren(slots.default?.());

View File

@ -24,6 +24,7 @@ const subMenuProps = {
popupOffset: Array as PropType<number[]>, popupOffset: Array as PropType<number[]>,
internalPopupClose: Boolean, internalPopupClose: Boolean,
eventKey: String, eventKey: String,
expandIcon: Function as PropType<(p?: { isOpen: boolean; [key: string]: any }) => any>,
}; };
export type SubMenuProps = Partial<ExtractPropTypes<typeof subMenuProps>>; export type SubMenuProps = Partial<ExtractPropTypes<typeof subMenuProps>>;
@ -32,7 +33,7 @@ export default defineComponent({
name: 'ASubMenu', name: 'ASubMenu',
inheritAttrs: false, inheritAttrs: false,
props: subMenuProps, props: subMenuProps,
slots: ['icon', 'title'], slots: ['icon', 'title', 'expandIcon'],
emits: ['titleClick', 'mouseenter', 'mouseleave'], emits: ['titleClick', 'mouseenter', 'mouseleave'],
setup(props, { slots, attrs, emit }) { setup(props, { slots, attrs, emit }) {
useProvideFirstLevel(false); useProvideFirstLevel(false);
@ -84,6 +85,7 @@ export default defineComponent({
selectedSubMenuEventKeys, selectedSubMenuEventKeys,
motion, motion,
defaultMotions, defaultMotions,
expandIcon: menuExpandIcon,
} = useInjectMenu(); } = useInjectMenu();
registerMenuInfo(eventKey, menuInfo); registerMenuInfo(eventKey, menuInfo);
@ -226,6 +228,7 @@ export default defineComponent({
const icon = getPropsSlot(slots, props, 'icon'); const icon = getPropsSlot(slots, props, 'icon');
const title = renderTitle(getPropsSlot(slots, props, 'title'), icon); const title = renderTitle(getPropsSlot(slots, props, 'title'), icon);
const subMenuPrefixClsValue = subMenuPrefixCls.value; const subMenuPrefixClsValue = subMenuPrefixCls.value;
const expandIcon = props.expandIcon || slots.expandIcon || menuExpandIcon;
let titleNode = ( let titleNode = (
<div <div
style={directionStyle.value} style={directionStyle.value}
@ -244,8 +247,8 @@ export default defineComponent({
{title} {title}
{/* Only non-horizontal mode shows the icon */} {/* Only non-horizontal mode shows the icon */}
{mode.value !== 'horizontal' && slots.expandIcon ? ( {mode.value !== 'horizontal' && expandIcon ? (
slots.expandIcon({ ...props, isOpen: open.value }) expandIcon({ ...props, isOpen: open.value })
) : ( ) : (
<i class={`${subMenuPrefixClsValue}-arrow`} /> <i class={`${subMenuPrefixClsValue}-arrow`} />
)} )}

View File

@ -77,7 +77,7 @@ export interface MenuContextProps {
// // Icon // // Icon
// itemIcon?: RenderIconType; // itemIcon?: RenderIconType;
// expandIcon?: RenderIconType; expandIcon?: (p?: { isOpen: boolean; [key: string]: any }) => any;
// // Function // // Function
onItemClick: MenuClickEventHandler; onItemClick: MenuClickEventHandler;