|
@ -1,4 +1,4 @@ |
|
|
import type { TriggerProps } from '@rc-component/trigger'; |
|
|
import type { TriggerProps, TriggerRef } from '@rc-component/trigger'; |
|
|
import MockTrigger from '@rc-component/trigger/lib/mock'; |
|
|
import MockTrigger from '@rc-component/trigger/lib/mock'; |
|
|
import * as React from 'react'; |
|
|
import * as React from 'react'; |
|
|
import { TriggerMockContext } from '../../shared/demoTestContext'; |
|
|
import { TriggerMockContext } from '../../shared/demoTestContext'; |
|
@ -6,22 +6,21 @@ import { TriggerMockContext } from '../../shared/demoTestContext'; |
|
|
let OriginTrigger = jest.requireActual('@rc-component/trigger'); |
|
|
let OriginTrigger = jest.requireActual('@rc-component/trigger'); |
|
|
OriginTrigger = OriginTrigger.default ?? OriginTrigger; |
|
|
OriginTrigger = OriginTrigger.default ?? OriginTrigger; |
|
|
|
|
|
|
|
|
const ForwardTrigger = React.forwardRef<any, TriggerProps>((props, ref) => { |
|
|
const ForwardTrigger = React.forwardRef<TriggerRef, TriggerProps>((props, ref) => { |
|
|
const context = React.useContext(TriggerMockContext); |
|
|
const context = React.useContext(TriggerMockContext); |
|
|
|
|
|
|
|
|
const mergedPopupVisible = context?.popupVisible ?? props.popupVisible; |
|
|
const mergedPopupVisible = context?.popupVisible ?? props.popupVisible; |
|
|
(global as any).triggerProps = props; |
|
|
(global as any).triggerProps = props; |
|
|
|
|
|
|
|
|
const mergedProps = { |
|
|
const mergedProps: TriggerProps = { |
|
|
...props, |
|
|
...props, |
|
|
ref, |
|
|
popupVisible: mergedPopupVisible, |
|
|
popupVisible: mergedPopupVisible as boolean, |
|
|
|
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
if (context?.mock === false) { |
|
|
if (context?.mock === false) { |
|
|
return <OriginTrigger {...mergedProps} />; |
|
|
return <OriginTrigger ref={ref} {...mergedProps} />; |
|
|
} |
|
|
} |
|
|
return <MockTrigger {...mergedProps} />; |
|
|
return <MockTrigger ref={ref} {...mergedProps} />; |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
export default ForwardTrigger; |
|
|
export default ForwardTrigger; |
|
|