mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-18 11:18:14 +08:00
ac5a06027e
This reverts commit ea8ed28209
.
28 lines
853 B
TypeScript
28 lines
853 B
TypeScript
import type { TriggerProps } from '@rc-component/trigger';
|
|
import MockTrigger from '@rc-component/trigger/lib/mock';
|
|
import * as React from 'react';
|
|
import { TriggerMockContext } from '../../shared/demoTestContext';
|
|
|
|
let OriginTrigger = jest.requireActual('@rc-component/trigger');
|
|
OriginTrigger = OriginTrigger.default ?? OriginTrigger;
|
|
|
|
const ForwardTrigger = React.forwardRef<any, TriggerProps>((props, ref) => {
|
|
const context = React.useContext(TriggerMockContext);
|
|
|
|
const mergedPopupVisible = context?.popupVisible ?? props.popupVisible;
|
|
(global as any).triggerProps = props;
|
|
|
|
const mergedProps = {
|
|
...props,
|
|
ref,
|
|
popupVisible: mergedPopupVisible as boolean,
|
|
};
|
|
|
|
if (context?.mock === false) {
|
|
return <OriginTrigger {...mergedProps} />;
|
|
}
|
|
return <MockTrigger {...mergedProps} />;
|
|
});
|
|
|
|
export default ForwardTrigger;
|