Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Realign popup menu to target after DOM updated #92

Closed
wants to merge 1 commit into from
Closed
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
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
28 changes: 28 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,15 @@ const Select = React.createClass({
} else {
inputNode.style.width = '';
}
// fix for https://github.com/ant-design/ant-design/issues/1827
if (props.choiceTransitionName) {
// wait animation completed
setTimeout(() => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setTimeout 不行的

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

呃,除了 setTimeout,有其他更好的方法么?

this.alignPopupMenu();
}, 400);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

400 就是乱来了

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

测试发现 400 ms 是个安全的临界值。。

} else {
this.alignPopupMenu();
}
}
},

Expand Down Expand Up @@ -339,6 +349,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 +488,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 +540,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