Skip to content

Commit

Permalink
fix: Dropdown 传给 Trigger 的 props 修改
Browse files Browse the repository at this point in the history
  • Loading branch information
chenchen32 committed Sep 23, 2021
1 parent c732e68 commit c0180f0
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 12 deletions.
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ module.exports = {
},
moduleFileExtensions: ['js', 'jsx', 'json', 'ts', 'tsx', 'md'],
testURL: 'http://localhost',
testMatch: [...getRefactoredCompMatch()],
testMatch: [...getRefactoredCompMatch('**')],

testPathIgnorePatterns: [
'<rootDir>/node_modules/',
Expand Down
57 changes: 46 additions & 11 deletions source/components/Dropdown/src/Dropdown.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React from 'react';
import ReactDOM from 'react-dom';
import PropTypes from 'prop-types';
import Trigger from 'rc-trigger';
import useControlledState from "../../../hooks/useControlledState";
import useControlledState from '../../../hooks/useControlledState';
import placements from './placements';

export interface RcDropDownProps {
Expand All @@ -26,22 +27,21 @@ export interface RcDropDownProps {
defaultVisible?: boolean;
}

const Dropdown = (props: RcDropDownProps, ref) => {
const InternalDropdown: React.ForwardRefRenderFunction<any, RcDropDownProps> = (props, ref) => {
const { visible, defaultVisible } = props;
const {
prefixCls = 'rc-dropdown',
visible,
defaultVisible = false,
prefixCls,
children,
transitionName,
animation,
align,
placement = 'bottomLeft',
placement,
getPopupContainer,
showAction = [],
hideAction,
overlayClassName = '',
overlayStyle = {},
trigger = ['hover'],
overlayClassName,
overlayStyle,
trigger,
...otherProps
} = props;

Expand All @@ -51,7 +51,7 @@ const Dropdown = (props: RcDropDownProps, ref) => {
onChange: props.onVisibleChange,
});

const triggerRef = React.useRef(null);
const triggerRef = React.useRef<any>(null);
React.useImperativeHandle(ref, () => triggerRef.current);

const onClick = e => {
Expand Down Expand Up @@ -141,4 +141,39 @@ const Dropdown = (props: RcDropDownProps, ref) => {
);
};

export default React.forwardRef(Dropdown);
const Dropdown = React.forwardRef(InternalDropdown);

Dropdown.propTypes = {
minOverlayWidthMatchTrigger: PropTypes.bool,
onVisibleChange: PropTypes.func,
onOverlayClick: PropTypes.func,
prefixCls: PropTypes.string,
children: PropTypes.node,
transitionName: PropTypes.string,
overlayClassName: PropTypes.string,
animation: PropTypes.string,
align: PropTypes.object,
overlayStyle: PropTypes.object,
placement: PropTypes.string,
overlay: PropTypes.node,
trigger: PropTypes.array,
alignPoint: PropTypes.bool,
showAction: PropTypes.array,
hideAction: PropTypes.array,
getPopupContainer: PropTypes.func,
visible: PropTypes.bool,
defaultVisible: PropTypes.bool,
};

Dropdown.defaultProps = {
prefixCls: 'rc-dropdown',
trigger: ['hover'],
showAction: [],
overlayClassName: '',
overlayStyle: {},
defaultVisible: false,
onVisibleChange() {},
placement: 'bottomLeft',
};

export default Dropdown;

0 comments on commit c0180f0

Please sign in to comment.