-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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 (#64819)
co-authored-by: kevin940726 <kevin940726@git.wordpress.org>Co-authored-by: aaronrobertshaw <aaronrobertshaw@git.wordpress.org>Co-authored-by: andrewserong <andrewserong@git.wordpress.org>Co-authored-by: ramonjd <ramonopoly@git.wordpress.org> * 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 }; |