Skip to content

Commit

Permalink
useBreakpointIndex: attach resize event listener to window inst…
Browse files Browse the repository at this point in the history
…ead of `document` (#33902)
  • Loading branch information
ciampo authored Aug 6, 2021
1 parent e459456 commit ac9ab86
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 4 additions & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Bug Fix

- Listen to `resize` events correctly in `useBreakpointIndex`. This hook is used in `useResponsiveValue` and consequently in the `Flex` and `Grid` components ([#33902](https://github.com/WordPress/gutenberg/pull/33902))

## 15.0.0 (2021-07-29)

### Breaking Change
Expand Down
8 changes: 4 additions & 4 deletions packages/components/src/ui/utils/use-responsive-value.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ export const useBreakpointIndex = (

onResize();

if ( typeof document !== 'undefined' ) {
if ( typeof window !== 'undefined' ) {
// Disable reason: We don't really care about what document we listen to, we just want to know that we're resizing.
/* eslint-disable @wordpress/no-global-event-listener */
document.addEventListener( 'resize', onResize );
window.addEventListener( 'resize', onResize );
}
return () => {
if ( typeof document !== 'undefined' ) {
document.removeEventListener( 'resize', onResize );
if ( typeof window !== 'undefined' ) {
window.removeEventListener( 'resize', onResize );
/* eslint-enable @wordpress/no-global-event-listener */
}
};
Expand Down

0 comments on commit ac9ab86

Please sign in to comment.