Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Dropdown): fix dropdown item calcuation height #4484

Merged
merged 1 commit into from
Aug 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/dropdown/dropdown-menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export default defineComponent({
const dropdownClass = usePrefixClass('dropdown');
const dropdownMenuClass = usePrefixClass('dropdown__menu');
const scrollTopMap = reactive({});
const itemHeight = ref(null);
const menuRef = ref<HTMLElement>();
const isOverMaxHeight = ref(false);
const { ChevronRightIcon } = useGlobalIcon({
Expand All @@ -39,6 +40,7 @@ export default defineComponent({
const menuHeight = parseInt(window?.getComputedStyle(menuRef.value).height, 10);
if (menuHeight >= props.maxHeight) isOverMaxHeight.value = true;
}
itemHeight.value = document.querySelector(`.${dropdownClass.value}__item`).scrollHeight + 2;
});

const getContent = (content: string | TNode) => {
Expand All @@ -54,7 +56,7 @@ export default defineComponent({
let renderContent;
data.forEach?.((menu, idx) => {
const optionItem = { ...(menu as DropdownOption) };
const onViewIdx = idx - Math.ceil(scrollTopMap[deep] / 30);
const onViewIdx = idx - Math.ceil(scrollTopMap[deep] / itemHeight.value);
const renderIdx = onViewIdx >= 0 ? onViewIdx : idx;

if (optionItem.children) {
Expand Down Expand Up @@ -86,7 +88,7 @@ export default defineComponent({
]}
style={{
position: 'absolute',
top: `${renderIdx * 30}px`,
top: `${renderIdx * itemHeight.value}px`,
}}
>
<div
Expand Down
Loading