Skip to content
This repository has been archived by the owner on Mar 27, 2023. It is now read-only.

Commit

Permalink
[fix] select scrollbar (#446)
Browse files Browse the repository at this point in the history
  • Loading branch information
menggeNiu authored and liufei committed Jan 21, 2019
1 parent 51e43bb commit ac5dfed
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions packages/react-impression/src/components/Select/Select.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,6 @@ export default class Select extends React.PureComponent {

componentDidMount() {
this.handleInit()
window.requestAnimationFrame(() => {
this.selectScrollbar = new PerfectScrollbar(this.selectInner, {
suppressScrollX: true,
})
})
}

/**
Expand Down Expand Up @@ -163,10 +158,7 @@ export default class Select extends React.PureComponent {
option.queryChange('')
})
this.selectPopper && this.selectPopper.destroy()
if (this.selectInner) {
this.selectInner.scrollTop = 0
this.handleUpdateSelectScroll()
}
this.handleDestroySelectScroll()
})
}

Expand Down Expand Up @@ -301,10 +293,6 @@ export default class Select extends React.PureComponent {
optionGroup.forEach(option => {
option.queryChange('')
})
if (this.selectInner) {
this.selectInner.scrollTop = 0
this.handleUpdateSelectScroll()
}
if (this.state.showOption) {
this.selectPopper = new Popper(this.selectMain, this.selectOption, {
positionFixed: true,
Expand All @@ -313,8 +301,10 @@ export default class Select extends React.PureComponent {
offset: { offset: '0, 10' },
},
})
this.handleInitSelectScroll()
} else {
this.selectPopper && this.selectPopper.destroy()
this.handleDestroySelectScroll()
}
}
)
Expand Down Expand Up @@ -351,6 +341,8 @@ export default class Select extends React.PureComponent {
this.setState({ currentPlaceholder: placeholder })
}
this.selectPopper && this.selectPopper.update()
this.selectInner.scrollTop = 0
this.handleUpdateSelectScroll()
if (e) e.stopPropagation()
}

Expand Down Expand Up @@ -407,10 +399,6 @@ export default class Select extends React.PureComponent {
*/
componentWillUnmount() {
System.unmanager(this)
if (this.selectScrollbar) {
this.selectScrollbar.destroy()
this.selectScrollbar = null
}
}

componentWillReceiveProps(props) {
Expand Down Expand Up @@ -465,6 +453,20 @@ export default class Select extends React.PureComponent {
})
}

handleInitSelectScroll = () => {
window.requestAnimationFrame(() => {
this.selectInner.scrollTop = 0
this.selectScrollbar = new PerfectScrollbar(this.selectInner, {
suppressScrollX: true,
})
})
}
handleDestroySelectScroll = () => {
if (this.selectScrollbar) {
this.selectScrollbar.destroy()
this.selectScrollbar = null
}
}
handleUpdateSelectScroll = () => {
window.requestAnimationFrame(() => {
this.selectScrollbar && this.selectScrollbar.update()
Expand Down

0 comments on commit ac5dfed

Please sign in to comment.