Snackbar not closing #1398
Description
What MDC-Web Version are you using?
0.22.0
What browser(s) is this bug affecting?
Chrome (Version 61.0.3163.100 (Official Build) (64-bit))
User agent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36"
What OS are you using?
macOS Sierra (version 10.12.6)
What are the steps to reproduce the bug?
- Open Snackbar demo page: https://material-components-web.appspot.com/snackbar.html
- Snackbar settings should be left as is (only Dismiss on action enabled)
- Click the "Show" button twice and switch browser tab (within the 2750ms timer which should close the first snackbar and open the second one)
- Switch back to the snackbar demo tab and the snackbar never closes (even when setting focus on other elements)
What is the expected behavior?
The snackbar should close.
What is the actual behavior?
It doesn't close.
Any other information you believe would be useful?
I was digging through the Snackbar component and found out that it gets focus when switching tab to the tab that is showing the snackbar. When it has focus, it doesn't close (expected behaviour). The blur handler should then kick in when moving focus to some other element, but AFAIK the blur handler doesn't trigger any more. I am not sure yet why. The blur handler does kick in when performing the steps above, but clicking the "Show" button only once at step 3.
Besides the actual bug I'd also like to know why the Snackbar gets focus when switching tab? Shouldn't it just continue (or restart) the snackbar timer for closure?
EDIT:
Found a dirty workaround: manually set the snackbarHasFocus variable to false when the visibility change handler is triggered (make sure the MDC visibility change handler is run first by using setTimeout as it sets the snackbarHasFocus variable to true...) and there is a Snackbar queue.