Skip to content

Commit

Permalink
Merge branch 'develop' into feat/statistic
Browse files Browse the repository at this point in the history
  • Loading branch information
HaixingOoO committed Nov 27, 2023
2 parents 8658aaf + 6b96937 commit 7c81262
Show file tree
Hide file tree
Showing 8 changed files with 346 additions and 303 deletions.
2 changes: 1 addition & 1 deletion src/drawer/Drawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const Drawer = forwardRef<HTMLDivElement, DrawerProps>((originalProps, ref) => {
return dragSizeValue || sizeMap[size] || size;
}, [dragSizeValue, size]);

useLockStyle({ ...props, sizeValue });
useLockStyle({ ...props, sizeValue, drawerWrapper: drawerWrapperRef.current });
useImperativeHandle(ref, () => containerRef.current);

useEffect(() => {
Expand Down
9 changes: 6 additions & 3 deletions src/drawer/__tests__/drawer.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,12 @@ describe('test Drawer', () => {
test('Drawer mode push', () => {
const { getByText } = render(<DrawerDemo attach="body" mode="push" />);
fireEvent.click(getByText('Open'));
expect(document.body).toHaveStyle({
margin: '0 0 0 -300px',
});

setTimeout(() => {
expect(document.body).toHaveStyle({
margin: '0 0 0 -300px',
});
}, 1000);
});
test('Drawer onCancel', () => {
const onCancelFn = vi.fn();
Expand Down
72 changes: 37 additions & 35 deletions src/drawer/_example/attach-parent.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,44 +25,46 @@ export default function () {
borderRadius: '2px',
}}
>
<Space direction="vertical">
<p>渲染在当前元素中。</p>
<div>
<span>抽屉弹出方向:</span>
<Radio.Group value={placement} onChange={(value) => setPlacement(value)}>
<Radio.Button value="left">左侧</Radio.Button>
<Radio.Button value="right">右侧</Radio.Button>
<Radio.Button value="top">上方</Radio.Button>
<Radio.Button value="bottom">下方</Radio.Button>
</Radio.Group>
</div>
<div id="demo-suf-container">
<Space direction="vertical">
<p>渲染在当前元素中。</p>
<div>
<span>抽屉弹出方向:</span>
<Radio.Group value={placement} onChange={(value) => setPlacement(value)}>
<Radio.Button value="left">左侧</Radio.Button>
<Radio.Button value="right">右侧</Radio.Button>
<Radio.Button value="top">上方</Radio.Button>
<Radio.Button value="bottom">下方</Radio.Button>
</Radio.Group>
</div>

<div>
<span>抽屉弹出模式:</span>
<Radio.Group value={mode} onChange={(value) => setMode(value)}>
<Radio.Button value="push">push</Radio.Button>
<Radio.Button value="overlay">overlay</Radio.Button>
</Radio.Group>
</div>
<div>
<span>抽屉弹出模式:</span>
<Radio.Group value={mode} onChange={(value) => setMode(value)}>
<Radio.Button value="push">push</Radio.Button>
<Radio.Button value="overlay">overlay</Radio.Button>
</Radio.Group>
</div>

<div>
<Button theme="primary" onClick={handleClick}>
Open
</Button>
</div>
<div>
<Button theme="primary" onClick={handleClick}>
Open
</Button>
</div>

<Drawer
showInAttachedElement
placement={placement}
header="Drawer"
visible={visible}
onClose={handleClose}
mode={mode}
attach="#demo-container"
>
<p>This is a drawer</p>
</Drawer>
</Space>
<Drawer
showInAttachedElement
placement={placement}
header="Drawer"
visible={visible}
onClose={handleClose}
mode={mode}
attach="#demo-suf-container"
>
<p>This is a drawer</p>
</Drawer>
</Space>
</div>
</div>
);
}
20 changes: 17 additions & 3 deletions src/drawer/hooks/useLockStyle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { getScrollbarWidth } from '../../_common/js/utils/getScrollbarWidth';
let key = 1;

export default function useLockStyle(props) {
const { preventScrollThrough, mode, visible, showInAttachedElement, placement, sizeValue } = props;
const { preventScrollThrough, mode, visible, showInAttachedElement, placement, sizeValue, drawerWrapper } = props;
const lockStyleRef = useRef<HTMLStyleElement>(null);
const timerRef = useRef(null);

Expand All @@ -32,17 +32,31 @@ export default function useLockStyle(props) {
if (!lockStyleRef.current) {
lockStyleRef.current = document.createElement('style');
}

const hasScrollBar = document.documentElement.scrollHeight > document.documentElement.clientHeight;
const scrollbarWidth = hasScrollBar ? getScrollbarWidth() : 0;
lockStyleRef.current.dataset.id = `td_drawer_${+new Date()}_${(key += 1)}`;
lockStyleRef.current.innerHTML = `
html body {
overflow-y: hidden;
transition: margin 300ms cubic-bezier(0.7, 0.3, 0.1, 1) 0s;
${mode === 'push' ? marginString : `width: calc(100% - ${scrollbarWidth}px);`}
${mode === 'push' ? '' : `width: calc(100% - ${scrollbarWidth}px);`}
}
`;
}, [mode, marginString]);
}, [mode]);

useLayoutEffect(() => {
if (drawerWrapper && mode === 'push') {
if (visible) {
drawerWrapper.parentNode.style.cssText += `
transition: margin 300ms cubic-bezier(0.7, 0.3, 0.1, 1) 0s;
${marginString};}
`;
} else {
drawerWrapper.parentNode.style.cssText = drawerWrapper.parentNode.style.cssText.replace(/margin:.+;/, '');
}
}
}, [mode, marginString, drawerWrapper, visible]);

useLayoutEffect(() => {
if (typeof document === 'undefined') return;
Expand Down
4 changes: 3 additions & 1 deletion src/tree/TreeItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,9 @@ const TreeItem = forwardRef(
data-value={node.value}
data-level={level}
className={classNames(treeClassNames.treeNode, {
[treeClassNames.treeNodeOpen]: node.expanded,
[treeClassNames.treeNodeOpen]:
node.expanded &&
(typeof node.data.children === 'boolean' ? node.data.children : node.data.children !== undefined),
[treeClassNames.actived]: node.isActivable() ? node.actived : false,
[treeClassNames.disabled]: node.isDisabled(),
[treeClassNames.treeNodeDraggable]: node.isDraggable(),
Expand Down
14 changes: 14 additions & 0 deletions src/tree/__tests__/tree.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,20 @@ describe('Tree test', () => {
expect(onChangeFn1).not.toHaveBeenCalled();
});

it('should calculate right class of tree item.', async () => {
const { container } = await renderTreeWithProps({
expanded: [1, '1-2', '1-2', 2],
});

await mockDelay(300);
const allItems = container.querySelectorAll('.t-tree__item');
expect(allItems.length).toBe(4);
const nodeOpenItems = container.querySelectorAll('.t-tree__item--open');
// only set expanded when node has children
// or children is `true` when the tree is lazy
expect(nodeOpenItems.length).toBe(1);
});

test('props.line', async () => {
const data = [
{
Expand Down
Loading

0 comments on commit 7c81262

Please sign in to comment.