fix: Static method provides wrong zIndex context (#46012)

* fix: static confirm should has correct zIndex

* test: update test case

* chore: reorder

* fix: bump logic
This commit is contained in:
二货爱吃白萝卜 2023-11-22 18:02:32 +08:00 committed by GitHub
parent 5aafe6d39a
commit 6aff196c90
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 122 additions and 46 deletions

View File

@ -349,7 +349,7 @@ describe('Test useZIndex hooks', () => {
const instance = Modal.confirm({
title: 'bamboo',
content: 'little',
content: <Select open />,
});
await waitFakeTimer();
@ -358,6 +358,10 @@ describe('Test useZIndex hooks', () => {
zIndex: '2000',
});
expect(document.querySelector('.ant-select-dropdown')).toHaveStyle({
zIndex: '2050',
});
instance.destroy();
await waitFakeTimer();

View File

@ -44,7 +44,13 @@ export function useZIndex(
const [, token] = useToken();
const parentZIndex = React.useContext(zIndexContext);
const isContainer = isContainerType(componentType);
if (customZIndex !== undefined) {
return [customZIndex, customZIndex];
}
let zIndex = parentZIndex ?? 0;
if (isContainer) {
zIndex +=
// Use preset token zIndex by default but not stack when has parent container

View File

@ -17,7 +17,7 @@ import OkBtn from './components/ConfirmOkBtn';
import type { ModalContextProps } from './context';
import { ModalContextProvider } from './context';
import type { ModalFuncProps, ModalLocale } from './interface';
import Dialog from './Modal';
import Modal from './Modal';
import ConfirmCmp from './style/confirmCmp';
export interface ConfirmDialogProps extends ModalFuncProps {
@ -233,7 +233,7 @@ const ConfirmDialog: React.FC<ConfirmDialogProps> = (props) => {
// ========================= Render =========================
return (
<Dialog
<Modal
prefixCls={prefixCls}
className={classString}
wrapClassName={classNames(
@ -269,7 +269,7 @@ const ConfirmDialog: React.FC<ConfirmDialogProps> = (props) => {
focusTriggerAfterClose={focusTriggerAfterClose}
>
<ConfirmContent {...props} confirmPrefixCls={confirmPrefixCls} />
</Dialog>
</Modal>
);
};

View File

@ -670,31 +670,60 @@ exports[`renders components/modal/demo/modal-render.tsx extend context correctly
exports[`renders components/modal/demo/modal-render.tsx extend context correctly 2`] = `[]`;
exports[`renders components/modal/demo/nested.tsx extend context correctly 1`] = `
<button
aria-checked="false"
class="ant-switch"
role="switch"
style="position: relative; z-index: 0;"
type="button"
<div
class="ant-space ant-space-horizontal ant-space-align-center ant-space-gap-row-small ant-space-gap-col-small"
>
<div
class="ant-switch-handle"
/>
<span
class="ant-switch-inner"
class="ant-space-item"
>
<span
class="ant-switch-inner-checked"
<button
aria-checked="false"
class="ant-switch"
role="switch"
style="position: relative; z-index: 0;"
type="button"
>
Open
</span>
<span
class="ant-switch-inner-unchecked"
<div
class="ant-switch-handle"
/>
<span
class="ant-switch-inner"
>
<span
class="ant-switch-inner-checked"
>
Open
</span>
<span
class="ant-switch-inner-unchecked"
>
Close
</span>
</span>
</button>
</div>
<div
class="ant-space-item"
>
<button
class="ant-btn ant-btn-default"
type="button"
>
Close
</span>
</span>
</button>
<span>
Static
</span>
</button>
</div>
<div
class="ant-space-item"
/>
<div
class="ant-space-item"
/>
<div
class="ant-space-item"
/>
</div>
`;
exports[`renders components/modal/demo/nested.tsx extend context correctly 2`] = `[]`;

View File

@ -640,31 +640,60 @@ exports[`renders components/modal/demo/modal-render.tsx correctly 1`] = `
`;
exports[`renders components/modal/demo/nested.tsx correctly 1`] = `
<button
aria-checked="false"
class="ant-switch"
role="switch"
style="position:relative;z-index:0"
type="button"
<div
class="ant-space ant-space-horizontal ant-space-align-center ant-space-gap-row-small ant-space-gap-col-small"
>
<div
class="ant-switch-handle"
/>
<span
class="ant-switch-inner"
class="ant-space-item"
>
<span
class="ant-switch-inner-checked"
<button
aria-checked="false"
class="ant-switch"
role="switch"
style="position:relative;z-index:0"
type="button"
>
Open
</span>
<span
class="ant-switch-inner-unchecked"
<div
class="ant-switch-handle"
/>
<span
class="ant-switch-inner"
>
<span
class="ant-switch-inner-checked"
>
Open
</span>
<span
class="ant-switch-inner-unchecked"
>
Close
</span>
</span>
</button>
</div>
<div
class="ant-space-item"
>
<button
class="ant-btn ant-btn-default"
type="button"
>
Close
</span>
</span>
</button>
<span>
Static
</span>
</button>
</div>
<div
class="ant-space-item"
/>
<div
class="ant-space-item"
/>
<div
class="ant-space-item"
/>
</div>
`;
exports[`renders components/modal/demo/position.tsx correctly 1`] = `

View File

@ -18,14 +18,21 @@ const Demo: React.FC = () => {
const [isModalOpen, setIsModalOpen] = useState<boolean>(false);
const onShowStatic = () => {
Modal.confirm({
content: <Select open value="1" options={options} />,
});
};
return (
<>
<Space>
<Switch
style={{ position: 'relative', zIndex: isModalOpen ? 4000 : 0 }}
checkedChildren="Open"
unCheckedChildren="Close"
onChange={(open) => setIsModalOpen(open)}
/>
<Button onClick={onShowStatic}>Static</Button>
<Modal
title="Basic Modal"
open={isModalOpen}
@ -123,7 +130,7 @@ const Demo: React.FC = () => {
{messageHolder}
{notificationHolder}
</>
</Space>
);
};

View File

@ -50,6 +50,7 @@ const DEPRECIATED_VERSION = {
'5.10.0': ['https://github.com/ant-design/ant-design/issues/45289'],
'5.11.0': ['https://github.com/ant-design/ant-design/issues/45742'],
'5.11.1': ['https://github.com/ant-design/ant-design/issues/45883'],
'5.11.2': ['https://github.com/ant-design/ant-design/issues/46005'],
} as const;
function matchDeprecated(v: string) {