mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-27 20:49:53 +08:00
502dac12aa
* docs: fix code * feat: lint * feat: prettier * feat: test * feat: review * feat: format html * feat: format html
28 lines
887 B
TypeScript
28 lines
887 B
TypeScript
import * as React from 'react';
|
|
import type { TriggerProps, TriggerRef } from '@rc-component/trigger';
|
|
import MockTrigger from '@rc-component/trigger/lib/mock';
|
|
|
|
import { TriggerMockContext } from '../../shared/demoTestContext';
|
|
|
|
let OriginTrigger = jest.requireActual('@rc-component/trigger');
|
|
OriginTrigger = OriginTrigger.default ?? OriginTrigger;
|
|
|
|
const ForwardTrigger = React.forwardRef<TriggerRef, TriggerProps>((props, ref) => {
|
|
const context = React.useContext(TriggerMockContext);
|
|
|
|
const mergedPopupVisible = context?.popupVisible ?? props.popupVisible;
|
|
(global as any).triggerProps = props;
|
|
|
|
const mergedProps: TriggerProps = {
|
|
...props,
|
|
popupVisible: mergedPopupVisible,
|
|
};
|
|
|
|
if (context?.mock === false) {
|
|
return <OriginTrigger ref={ref} {...mergedProps} />;
|
|
}
|
|
return <MockTrigger ref={ref} {...mergedProps} />;
|
|
});
|
|
|
|
export default ForwardTrigger;
|