Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 12 additions & 14 deletions src/DropdownMenu.jsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import React, { cloneElement } from 'react';
import { findDOMNode } from 'react-dom';
import PropTypes from 'prop-types';
import createClass from 'create-react-class';
import toArray from 'rc-util/lib/Children/toArray';
import Menu from 'rc-menu';
import scrollIntoView from 'dom-scroll-into-view';
import { getSelectKeys, preventDefaultEvent } from './util';

const DropdownMenu = createClass({
propTypes: {
export default class DropdownMenu extends React.Component {
static propTypes= {
defaultActiveFirstOption: PropTypes.bool,
value: PropTypes.any,
dropdownMenuStyle: PropTypes.object,
Expand All @@ -20,24 +19,24 @@ const DropdownMenu = createClass({
menuItems: PropTypes.any,
inputValue: PropTypes.string,
visible: PropTypes.bool,
},
}

componentWillMount() {
this.lastInputValue = this.props.inputValue;
},
}

componentDidMount() {
this.scrollActiveItemToView();
this.lastVisible = this.props.visible;
},
}

shouldComponentUpdate(nextProps) {
if (!nextProps.visible) {
this.lastVisible = false;
}
// freeze when hide
return nextProps.visible;
},
}

componentDidUpdate(prevProps) {
const props = this.props;
Expand All @@ -46,17 +45,17 @@ const DropdownMenu = createClass({
}
this.lastVisible = props.visible;
this.lastInputValue = props.inputValue;
},
}

scrollActiveItemToView() {
scrollActiveItemToView = () => {
// scroll into view
const itemComponent = findDOMNode(this.firstActiveItem);
if (itemComponent) {
scrollIntoView(itemComponent, findDOMNode(this.refs.menu), {
onlyScrollIfNeeded: true,
});
}
},
}

renderMenu() {
const props = this.props;
Expand Down Expand Up @@ -127,7 +126,7 @@ const DropdownMenu = createClass({
</Menu>);
}
return null;
},
}

render() {
const renderMenu = this.renderMenu();
Expand All @@ -140,8 +139,7 @@ const DropdownMenu = createClass({
{renderMenu}
</div>
) : null;
},
});
}
}

DropdownMenu.displayName = 'DropdownMenu';
export default DropdownMenu;
40 changes: 19 additions & 21 deletions src/SelectTrigger.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import Trigger from 'rc-trigger';
import React from 'react';
import PropTypes from 'prop-types';
import createClass from 'create-react-class';
import classnames from 'classnames';
import DropdownMenu from './DropdownMenu';
import ReactDOM from 'react-dom';
Expand All @@ -28,8 +27,8 @@ const BUILT_IN_PLACEMENTS = {
},
};

const SelectTrigger = createClass({
propTypes: {
export default class SelectTrigger extends React.Component {
static propTypes= {
onPopupFocus: PropTypes.func,
dropdownMatchSelectWidth: PropTypes.bool,
dropdownAlign: PropTypes.object,
Expand All @@ -44,7 +43,7 @@ const SelectTrigger = createClass({
prefixCls: PropTypes.string,
popupClassName: PropTypes.string,
children: PropTypes.any,
},
}

componentDidUpdate() {
const { visible, dropdownMatchSelectWidth } = this.props;
Expand All @@ -55,17 +54,17 @@ const SelectTrigger = createClass({
dropdownDOMNode.style[widthProp] = `${ReactDOM.findDOMNode(this).offsetWidth}px`;
}
}
},
}

getInnerMenu() {
getInnerMenu = () => {
return this.popupMenu && this.popupMenu.refs.menu;
},
}

getPopupDOMNode() {
getPopupDOMNode = () => {
return this.refs.trigger.getPopupDomNode();
},
}

getDropdownElement(newProps) {
getDropdownElement = (newProps) => {
const props = this.props;
return (<DropdownMenu
ref={this.saveMenu}
Expand All @@ -77,24 +76,25 @@ const SelectTrigger = createClass({
defaultActiveFirstOption={props.defaultActiveFirstOption}
dropdownMenuStyle={props.dropdownMenuStyle}
/>);
},
}

getDropdownTransitionName() {
getDropdownTransitionName = () => {
const props = this.props;
let transitionName = props.transitionName;
if (!transitionName && props.animation) {
transitionName = `${this.getDropdownPrefixCls()}-${props.animation}`;
}
return transitionName;
},
}

getDropdownPrefixCls() {
getDropdownPrefixCls = () => {
return `${this.props.prefixCls}-dropdown`;
},
}

saveMenu(menu) {
saveMenu = (menu) => {
this.popupMenu = menu;
},
}

render() {
const { onPopupFocus, ...props } = this.props;
const { multiple, visible, inputValue, dropdownAlign,
Expand Down Expand Up @@ -135,9 +135,7 @@ const SelectTrigger = createClass({
popupClassName={classnames(popupClassName)}
popupStyle={props.dropdownStyle}
>{props.children}</Trigger>);
},
});
}
}

SelectTrigger.displayName = 'SelectTrigger';

export default SelectTrigger;