Skip to content

Commit

Permalink
realign popup menu to target after DOM updated
Browse files Browse the repository at this point in the history
  • Loading branch information
superRaytin committed May 25, 2016
1 parent 7d7b742 commit a657e59
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"dependencies": {
"classnames": "2.x",
"component-classes": "1.x",
"dom-align": "1.x",
"dom-scroll-into-view": "1.x",
"rc-animate": "2.x",
"rc-menu": "4.x",
Expand Down
27 changes: 27 additions & 0 deletions src/Select.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { PropTypes } from 'react';
import ReactDOM from 'react-dom';
import { KeyCode } from 'rc-util';
import classnames from 'classnames';
import domAlign from 'dom-align';
import OptGroup from './OptGroup';
import Animate from 'rc-animate';
import classes from 'component-classes';
Expand Down Expand Up @@ -134,6 +135,14 @@ const Select = React.createClass({
} else {
inputNode.style.width = '';
}
if (props.choiceTransitionName) {
// wait animation completed
setTimeout(() => {
this.alignPopupMenu();
}, 400);
} else {
this.alignPopupMenu();
}
}
},

Expand Down Expand Up @@ -339,6 +348,14 @@ const Select = React.createClass({
}
},

getPopupMenuAlign() {
const selectTrigger = this.refs.trigger;
const trigger = selectTrigger.refs.trigger;
const builtinPlacements = trigger.props.builtinPlacements;
const popupPlacement = trigger.props.popupPlacement;
return { ...builtinPlacements[popupPlacement] };
},

getLabelBySingleValue(children, value) {
if (value === undefined) {
return null;
Expand Down Expand Up @@ -470,12 +487,14 @@ const Select = React.createClass({
}
});
},

clearBlurTime() {
if (this.blurTimer) {
clearTimeout(this.blurTimer);
this.blurTimer = null;
}
},

updateFocusClassName() {
const { refs, props } = this;
// avoid setState and its side effect
Expand Down Expand Up @@ -520,6 +539,14 @@ const Select = React.createClass({
return value;
},

alignPopupMenu() {
const popupMenu = this.refs.trigger.popupMenu;
const source = ReactDOM.findDOMNode(popupMenu).parentNode;
const target = this.refs.selection;
const popupMenuAlign = this.getPopupMenuAlign();
domAlign(source, target, popupMenuAlign);
},

removeSelected(selectedKey) {
const props = this.props;
if (props.disabled) {
Expand Down

0 comments on commit a657e59

Please sign in to comment.