Skip to content

Commit

Permalink
fix(indexes): 修复索引为数字字符串时侧边栏不能正常激活的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
Lyan-u committed Sep 6, 2024
1 parent 378f862 commit 33d0836
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions src/indexes/indexes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,27 @@ import {
onBeforeUnmount,
provide,
computed,
ComponentInternalInstance,
watch,
ComponentPublicInstance,
} from 'vue';
import throttle from 'lodash/throttle';
import { preventDefault } from '../shared/dom';
import config from '../config';
import IndexesProps from './props';
import { usePrefixClass } from '../hooks/useClass';
import { useTNodeJSX } from '../hooks/tnode';

interface Child extends ComponentInternalInstance {
[key: string]: any;
}
import { TdIndexesAnchorProps } from './type';

interface State {
showSidebarTip: boolean;
activeSidebar: string | number;
children: Child[];
children: ComponentPublicInstance<TdIndexesAnchorProps>[];
}

interface GroupTop {
height: number;
top: number;
anchor: string;
anchor: string | number;
totalHeight: number;
}

Expand Down Expand Up @@ -146,14 +143,12 @@ export default defineComponent({
const getAnchorsRect = () => {
return Promise.all(
state.children.map((child) => {
const { $el } = child;
const { dataset } = $el;
const { index } = dataset;
const { $el, index } = child;
const rect = $el.getBoundingClientRect();
groupTop.push({
height: rect.height,
top: rect.top - parentRect.value.top,
anchor: /^\d+$/.test(index) ? Number(index) : index,
anchor: index,
totalHeight: 0,
});
return child;
Expand All @@ -168,15 +163,15 @@ export default defineComponent({
const target = document.elementFromPoint(clientX, clientY);
if (target && target.className === `${indexesClass.value}__sidebar-item` && target instanceof HTMLElement) {
const { index } = target.dataset;
const curIndex = /^\d+$/.test(index ?? '') ? Number(index) : index;
const curIndex = indexList.value.find((idx) => String(idx) === index);
if (curIndex !== undefined && state.activeSidebar !== curIndex) {
setActiveSidebarAndTip(curIndex);
scrollToByIndex(curIndex);
}
}
};

const relation = (child: ComponentInternalInstance) => {
const relation = (child: ComponentPublicInstance) => {
child && state.children.push(child);
};

Expand Down

0 comments on commit 33d0836

Please sign in to comment.