Skip to content

Commit

Permalink
style(list): fix code review comment
Browse files Browse the repository at this point in the history
fix #463
  • Loading branch information
feaswcy committed Sep 24, 2024
1 parent 40d7180 commit fb655da
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 30 deletions.
12 changes: 12 additions & 0 deletions src/hooks/useWindowHeight.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { useState } from 'react';

const useWindowHeight = () => {
const [height, setHeight] = useState(window.innerHeight);
window.onresize = () => {
const height = window.innerHeight;
setHeight(height);
};
return height;
};

export default useWindowHeight;
33 changes: 3 additions & 30 deletions src/list/list.tsx
Original file line number Diff line number Diff line change
@@ -1,36 +1,17 @@
import React, { useState, useRef, useEffect, useCallback } from 'react';
import React, { useRef, useEffect, useCallback } from 'react';
import { TdListProps } from './type';
import useConfig from '../_util/useConfig';

import TLoading from '../loading';
import parseTNode from '../_util/parseTNode';
import getScrollParent from '../_util/getScrollParent';
import useWindowHeight from '../hooks/useWindowHeight';

export interface ListProps extends TdListProps {
required?: boolean;
readonly?: boolean;
}

function isElement(node: Element) {
const ELEMENT_NODE_TYPE = 1;
return node.tagName !== 'HTML' && node.tagName !== 'BODY' && node.nodeType === ELEMENT_NODE_TYPE;
}

const overflowScrollReg = /scroll|auto/i;

function getScrollParent(el: Element, root = window) {
let node = el;

while (node && node !== root && isElement(node)) {
const { overflowY } = window.getComputedStyle(node);
if (overflowScrollReg.test(overflowY)) {
return node;
}
node = node.parentNode as Element;
}

return root;
}

const List: React.FC<ListProps> = (props) => {
const { classPrefix } = useConfig();
const { asyncLoading, header, footer, children } = props;
Expand All @@ -43,14 +24,6 @@ const List: React.FC<ListProps> = (props) => {

const root = useRef(null);

const useWindowHeight = () => {
const [height, setHeight] = useState(window.innerHeight);
window.onresize = () => {
const height = window.innerHeight;
setHeight(height);
};
return height;
};
const height = useWindowHeight();

const onLoadMore = () => {
Expand Down

0 comments on commit fb655da

Please sign in to comment.