Skip to content

Commit

Permalink
feat: stop the snackbar from hiding when hovered (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
egoist authored Jun 22, 2019
1 parent b3a3e83 commit 2e9d645
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,16 @@ export class Snackbar {
}
}

// Add timeout
if (this.options.timeout) {
this.timeoutId = self.setTimeout(
() => this.destroy(),
this.options.timeout
)
}
this.startTimer()

// Stop timer when mouseenter
// Restart timer when mouseleave
el.addEventListener('mouseenter', () => {
this.stopTimer()
})
el.addEventListener('mouseleave', () => {
this.startTimer()
})

this.el = el

Expand Down Expand Up @@ -170,9 +173,19 @@ export class Snackbar {
this.el = undefined
}

startTimer() {
if (this.options.timeout && !this.timeoutId) {
this.timeoutId = self.setTimeout(
() => this.destroy(),
this.options.timeout
)
}
}

stopTimer() {
if (this.timeoutId) {
clearTimeout(this.timeoutId)
this.timeoutId = undefined
}
}
}
Expand Down

0 comments on commit 2e9d645

Please sign in to comment.