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: 修复 popup 内容超长滚动问题 #1145

Merged
merged 1 commit into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"packages": ["packages/*"],
"workspaces": ["packages/*"],
"version": "independent",
"command": {
"publish": {
Expand Down
69 changes: 48 additions & 21 deletions packages/zarm/src/modal/demo.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ const initState = {
customContainer: {
visible: false,
},
overlength: {
visible: false,
},
};

const reducer = (state, action) => {
Expand Down Expand Up @@ -140,6 +143,15 @@ const Demo = () => {
>
挂载到指定 DOM 节点
</List.Item>
<List.Item
suffix={
<Button size="xs" onClick={() => toggle('overlength')}>
开启
</Button>
}
>
超长内容
</List.Item>
</List>

<div id="test-div" style={{ position: 'relative', zIndex: 1 }} ref={myRef} />
Expand Down Expand Up @@ -192,6 +204,21 @@ const Demo = () => {
>
挂载到指定dom节点
</Modal>

<Modal
visible={state.overlength.visible}
title="标题"
closable
onClose={() => toggle('overlength')}
maskClosable
>
{Array.from(Array(100).fill(0)).map((_, index) => (
<div key={index}>
模态框内容
<br />
</div>
))}
</Modal>
</>
);
};
Expand Down Expand Up @@ -454,24 +481,24 @@ const confirm = Modal.confirm({

## CSS 变量

| 属性 | 默认值 | 说明 |
| :------------------------------- | :---------------------------------- | :------------------- |
| --background | 'rgb(242, 242, 242)' | 背景色 |
| --border-radius | '14px' | 圆角大小 |
| --shadow | '0 7px 21px var(--za-color-shadow)' | 阴影样式 |
| --title-font-size | '17px' | 标题字体大小 |
| --title-font-weight | 500 | 标题字体粗细 |
| --title-text-color | 'var(--za-color-text)' | 标题字体颜色 |
| --close-size | '20px' | 关闭图标字体大小 |
| --close-color | '#ccc' | 关闭图标颜色 |
| --close-active-color | '#999' | 关闭图标激活状态颜色 |
| --body-font-size | '13px' | 内容字体大小 |
| --body-text-color | 'var(--za-color-text)' | 内容字体颜色 |
| --body-padding | '16px' | 内容内边距 |
| --button-background | 'transparent' | 操作按钮背景 |
| --button-height | '44px' | 操作按钮高度 |
| --button-font-size | '17px' | 操作按钮字体大小 |
| --button-font-weight | 500 | 操作按钮字体粗细 |
| --button-text-color | 'var(--za-theme-primary)' | 操作按钮字体颜色 |
| --button-active-background | 'var(--za-background-active)' | 操作按钮选中背景 |
| --button-disabled-opacity | 'var(--za-opacity-disabled)' | 操作按钮禁用状态时的透明度 |
| 属性 | 默认值 | 说明 |
| :------------------------- | :---------------------------------- | :------------------------- |
| --background | 'rgb(242, 242, 242)' | 背景色 |
| --border-radius | '14px' | 圆角大小 |
| --shadow | '0 7px 21px var(--za-color-shadow)' | 阴影样式 |
| --title-font-size | '17px' | 标题字体大小 |
| --title-font-weight | 500 | 标题字体粗细 |
| --title-text-color | 'var(--za-color-text)' | 标题字体颜色 |
| --close-size | '20px' | 关闭图标字体大小 |
| --close-color | '#ccc' | 关闭图标颜色 |
| --close-active-color | '#999' | 关闭图标激活状态颜色 |
| --body-font-size | '13px' | 内容字体大小 |
| --body-text-color | 'var(--za-color-text)' | 内容字体颜色 |
| --body-padding | '16px' | 内容内边距 |
| --button-background | 'transparent' | 操作按钮背景 |
| --button-height | '44px' | 操作按钮高度 |
| --button-font-size | '17px' | 操作按钮字体大小 |
| --button-font-weight | 500 | 操作按钮字体粗细 |
| --button-text-color | 'var(--za-theme-primary)' | 操作按钮字体颜色 |
| --button-active-background | 'var(--za-background-active)' | 操作按钮选中背景 |
| --button-disabled-opacity | 'var(--za-opacity-disabled)' | 操作按钮禁用状态时的透明度 |
20 changes: 18 additions & 2 deletions packages/zarm/src/popup/Popup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ const Popup = React.forwardRef<HTMLDivElement, PopupProps>((props, ref) => {
} = props;

const { prefixCls, mountContainer: globalMountContainer } = React.useContext(ConfigContext);
const nodeRef = React.useRef<HTMLDivElement>(null);
const maskRef = React.useRef<HTMLDivElement>(null);
const bem = createBEM('popup', { prefixCls });

useLockScroll(visible! && lockScroll!);
Expand All @@ -52,12 +54,22 @@ const Popup = React.forwardRef<HTMLDivElement, PopupProps>((props, ref) => {
onEsc?.();
}, []);

const handleClick = (event: React.MouseEvent) => {
if (nodeRef.current !== event.target && nodeRef.current.contains(event.target as HTMLElement)) {
return;
}
maskRef.current?.click();
};

const transitionName = animationType ?? TRANSITION_NAMES[direction!];

React.useImperativeHandle(ref, () => nodeRef.current);

return (
<Trigger visible={visible} onClose={handleEsc}>
{mask && (
<Mask
ref={maskRef}
className={maskClassName}
style={maskStyle}
visible={visible}
Expand All @@ -73,7 +85,7 @@ const Popup = React.forwardRef<HTMLDivElement, PopupProps>((props, ref) => {
/>
)}
<Transition
nodeRef={ref}
nodeRef={nodeRef}
visible={visible}
tranisitionName={`${prefixCls}-${transitionName}`}
duration={animationDuration}
Expand All @@ -96,7 +108,11 @@ const Popup = React.forwardRef<HTMLDivElement, PopupProps>((props, ref) => {
const { display, ...restStyle } = style;
return renderToContainer(
props.mountContainer ?? globalMountContainer,
<div className={bem('wrapper', [props.className])} style={{ ...props.style, display }}>
<div
className={bem('wrapper', [{ center: direction === 'center' }, props.className])}
style={{ ...props.style, display }}
onClick={handleClick}
>
<div
ref={setNodeRef}
className={bem([{ [`${direction}`]: !!direction }, className])}
Expand Down
24 changes: 13 additions & 11 deletions packages/zarm/src/popup/style/component.scss
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
@include b(popup) {
-webkit-overflow-scrolling: touch;
margin: auto;
pointer-events: all;
transform: perspective(0);

@include e(wrapper) {
@include define(mask-zindex, var(--za-zindex-mask));

position: fixed;
top: 0;
bottom: 0;
left: 0;
right: 0;
display: flex;
align-items: center;
justify-content: center;
z-index: var(--mask-zindex);
overflow: auto;
padding: 60px 0;
-webkit-overflow-scrolling: touch;

@include m(center) {
top: 0;
bottom: 0;
left: 0;
right: 0;
display: flex;
align-items: center;
justify-content: center;
overflow: auto;
padding: 60px 0;
-webkit-overflow-scrolling: touch;
}
}

@include m(bottom) {
Expand Down
1 change: 1 addition & 0 deletions packages/zarm/src/toast/Toast.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const Toast = React.forwardRef<HTMLDivElement, ToastProps>((props, ref) => {
}}
maskColor={maskColor}
lockScroll={!maskClickable}
className={bem('wrapper')}
{...rest}
>
<div
Expand Down
6 changes: 6 additions & 0 deletions packages/zarm/src/toast/style/component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,18 @@
align-items: center;
display: flex;

@include e(wrapper) {
pointer-events: none;
}

@include m(text) {
padding: var(--za-padding-v-md) var(--za-padding-h-md);
pointer-events: all;
}

@include m(icon) {
padding: 15px;
pointer-events: all;

@include e(text) {
min-width: 70px;
Expand Down
Loading