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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"devDependencies": {
"@types/classnames": "^2.2.6",
"@types/enzyme": "^3.1.15",
"@types/raf": "^3.4.0",
"@types/react": "^16.7.17",
"@types/react-dom": "^16.0.11",
"@types/warning": "^3.0.0",
Expand Down
23 changes: 19 additions & 4 deletions src/SelectTrigger.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import classnames from 'classnames';
import * as PropTypes from 'prop-types';
import raf from 'raf';
import Trigger from 'rc-trigger';
import * as React from 'react';
import * as ReactDOM from 'react-dom';
Expand Down Expand Up @@ -98,6 +99,7 @@ export default class SelectTrigger extends React.Component<
public saveTriggerRef: (ref: any) => void;
public dropdownMenuRef: DropdownMenu | null = null;
public triggerRef: any;
public rafInstance: number | null = null;

constructor(props: Partial<ISelectTriggerProps>) {
super(props);
Expand All @@ -118,11 +120,24 @@ export default class SelectTrigger extends React.Component<
this.setDropdownWidth();
}

public componentWillUnmount() {
this.cancelRafInstance();
}

public setDropdownWidth = () => {
const dom = ReactDOM.findDOMNode(this) as HTMLDivElement;
const width = dom.offsetWidth;
if (width !== this.state.dropdownWidth) {
this.setState({ dropdownWidth: width });
this.cancelRafInstance();
this.rafInstance = raf(() => {
const dom = ReactDOM.findDOMNode(this) as HTMLDivElement;
const width = dom.offsetWidth;
if (width !== this.state.dropdownWidth) {
this.setState({ dropdownWidth: width });
}
});
};

public cancelRafInstance = () => {
if (this.rafInstance) {
raf.cancel(this.rafInstance);
}
};

Expand Down
2 changes: 0 additions & 2 deletions typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,4 @@ declare module 'rc-util/lib/KeyCode';

declare module 'dom-scroll-into-view';

declare module 'raf';

declare module 'rc-trigger';