You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
817 B
27 lines
817 B
import type { TriggerProps } from 'rc-trigger';
|
|
import MockTrigger from 'rc-trigger/lib/mock';
|
|
import * as React from 'react';
|
|
import { TriggerMockContext } from '../shared/demoTestContext';
|
|
|
|
let OriginTrigger = jest.requireActual('rc-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;
|
|
|