Skip to content

Commit

Permalink
Add transition animation to tab width when returning to normal after …
Browse files Browse the repository at this point in the history
…a mouseover tab close button followed by a mouseout

Fix brave#7001
  • Loading branch information
petemill committed Oct 11, 2017
1 parent 74688c9 commit b086446
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions app/renderer/components/tabs/tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ class Tab extends React.Component {
return 0
}

const rect = this.tabNode.parentNode.getBoundingClientRect()
const rect = this.elementRef.getBoundingClientRect()
return rect && rect.width
}

Expand Down Expand Up @@ -279,6 +279,29 @@ class Tab extends React.Component {
return props
}

componentWillReceiveProps (nextProps) {
if (this.props.tabWidth && !nextProps.tabWidth) {
// remember the width so we can transition from it
this.originalWidth = this.elementRef.getBoundingClientRect().width
}
}

componentDidUpdate (prevProps) {
if (prevProps.tabWidth && !this.props.tabWidth) {
window.requestAnimationFrame(() => {
const newWidth = this.elementRef.getBoundingClientRect().width
this.elementRef.animate([
{ flexBasis: `${this.originalWidth}px`, flexGrow: 0, flexShrink: 0 },
{ flexBasis: `${newWidth}px`, flexGrow: 0, flexShrink: 0 }
], {
duration: 250,
iterations: 1,
easing: 'ease-in-out'
})
})
}
}

render () {
// we don't want themeColor if tab is private
const perPageStyles = !this.props.isPrivateTab && StyleSheet.create({
Expand Down Expand Up @@ -306,7 +329,9 @@ class Tab extends React.Component {
onMouseEnter={this.onMouseEnter}
onMouseLeave={this.onMouseLeave}
data-test-id='tab-area'
data-frame-key={this.props.frameKey}>
data-frame-key={this.props.frameKey}
ref={elementRef => { this.elementRef = elementRef }}
>
{
this.props.isActive && this.props.notificationBarActive
? <NotificationBarCaret />
Expand Down

0 comments on commit b086446

Please sign in to comment.