Skip to content

Commit

Permalink
fix(dropdown): menu overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
uyarn committed Dec 8, 2022
1 parent cbbe935 commit 5944b0c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
25 changes: 22 additions & 3 deletions src/dropdown/dropdown-menu.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { CreateElement } from 'vue';
import { ScopedSlotReturnValue } from 'vue/types/vnode';
import { defineComponent, h } from '@vue/composition-api';
import {
defineComponent, h, ref, onMounted,
} from '@vue/composition-api';
import { ChevronRightIcon as TdChevronRightIcon, ChevronLeftIcon as TdChevronLeftIcon } from 'tdesign-icons-vue';
import isFunction from 'lodash/isFunction';

Expand All @@ -17,7 +19,8 @@ export default defineComponent({
setup(props, { emit }) {
const dropdownClass = usePrefixClass('dropdown');
const dropdownMenuClass = usePrefixClass('dropdown__menu');

const menuRef = ref<HTMLElement>();
const isOverMaxHeight = ref(false);
const handleItemClick = (
optionItem: { disabled: boolean; children: unknown },
options: { data: DropdownOption; context: { e: MouseEvent } },
Expand All @@ -30,10 +33,19 @@ export default defineComponent({
emit('click', data, context);
};

onMounted(() => {
if (menuRef.value) {
const menuHeight = parseInt(window?.getComputedStyle(menuRef.value).height, 10);
if (menuHeight >= props.maxHeight) isOverMaxHeight.value = true;
}
});

return {
dropdownClass,
dropdownMenuClass,
handleItemClick,
menuRef,
isOverMaxHeight,
};
},
methods: {
Expand Down Expand Up @@ -141,7 +153,14 @@ export default defineComponent({
render() {
return (
<div
class={[this.dropdownMenuClass, `${this.dropdownMenuClass}--${this.direction}`]}
class={[
this.dropdownMenuClass,
`${this.dropdownMenuClass}--${this.direction}`,
{
[`${this.dropdownMenuClass}--overflow`]: this.isOverMaxHeight,
},
]}
ref="menuRef"
style={{
maxHeight: `${this.maxHeight}px`,
}}
Expand Down
4 changes: 2 additions & 2 deletions src/dropdown/dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default defineComponent({
props: { ...props },
setup(props: TdDropdownProps, { emit }) {
const dropdownClass = usePrefixClass('dropdown');
const isPopupVisible = ref(false);
const isPopupVisible = ref(true);

const handleMenuClick = (data: DropdownOption, context: { e: MouseEvent }) => {
if (props.hideAfterItemClick) {
Expand All @@ -25,7 +25,7 @@ export default defineComponent({
};

const handleVisibleChange = (visible: boolean, context: PopupVisibleChangeContext) => {
isPopupVisible.value = visible;
// isPopupVisible.value = visible;
props.popupProps?.onVisibleChange?.(visible, context);
};

Expand Down
1 change: 0 additions & 1 deletion src/popup/popup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,6 @@ export default mixins(classPrefixMixins).extend({
const triggerEl = this.$el as HTMLElement;
const overlayEl = this.$refs?.overlay as HTMLElement;

if (!triggerEl || !overlayEl) return;
if (typeof overlayStyle === 'function') {
return overlayStyle(triggerEl, overlayEl);
}
Expand Down

0 comments on commit 5944b0c

Please sign in to comment.