forked from WordPress/gutenberg
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix resizing to max width in classic themes (WordPress#64819)
co-authored-by: kevin940726 <[email protected]>Co-authored-by: aaronrobertshaw <[email protected]>Co-authored-by: andrewserong <[email protected]>Co-authored-by: ramonjd <[email protected]> * Fix resizing to max width in classic themes * Fix padding and max-width * Reverse the condition * Try ignoring if layout doesn't exist
- Loading branch information
1 parent
ec58c51
commit 6a60081
Showing
4 changed files
with
58 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
packages/block-library/src/image/use-max-width-observer.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useRef } from '@wordpress/element'; | ||
import { useResizeObserver } from '@wordpress/compose'; | ||
|
||
function useMaxWidthObserver() { | ||
const [ contentResizeListener, { width } ] = useResizeObserver(); | ||
const observerRef = useRef(); | ||
|
||
const maxWidthObserver = ( | ||
<div | ||
// Some themes set max-width on blocks. | ||
className="wp-block" | ||
aria-hidden="true" | ||
style={ { | ||
position: 'absolute', | ||
inset: 0, | ||
width: '100%', | ||
height: 0, | ||
margin: 0, | ||
} } | ||
ref={ observerRef } | ||
> | ||
{ contentResizeListener } | ||
</div> | ||
); | ||
|
||
return [ maxWidthObserver, width ]; | ||
} | ||
|
||
export { useMaxWidthObserver }; |