Skip to content

Commit

Permalink
fix(Dropdown): fix dropdown item calcuation height
Browse files Browse the repository at this point in the history
  • Loading branch information
uyarn committed Aug 16, 2024
1 parent 17918f1 commit cc9e78f
Showing 1 changed file with 4 additions and 2 deletions.
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

0 comments on commit cc9e78f

Please sign in to comment.