Skip to content

Commit

Permalink
Fix: Inline image width pop-up 'wanders' down page (#20232)
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgefilipecosta authored Feb 17, 2020
1 parent 5870caf commit 6f55017
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion packages/format-library/src/image/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export const image = {
this.onKeyDown = this.onKeyDown.bind( this );
this.openModal = this.openModal.bind( this );
this.closeModal = this.closeModal.bind( this );
this.anchorRef = null;
this.state = {
modal: false,
};
Expand Down Expand Up @@ -95,6 +96,22 @@ export const image = {
this.setState( { modal: false } );
}

componentDidMount() {
this.anchorRef = getRange();
}

componentDidUpdate( prevProps ) {
// When the popover is open or when the selected image changes,
// update the anchorRef.
if (
( ! prevProps.isObjectActive && this.props.isObjectActive ) ||
prevProps.activeObjectAttributes.url !==
this.props.activeObjectAttributes.url
) {
this.anchorRef = getRange();
}
}

render() {
const {
value,
Expand Down Expand Up @@ -151,7 +168,7 @@ export const image = {
<Popover
position="bottom center"
focusOnMount={ false }
anchorRef={ getRange() }
anchorRef={ this.anchorRef }
>
{
// Disable reason: KeyPress must be suppressed so the block doesn't hide the toolbar
Expand Down

0 comments on commit 6f55017

Please sign in to comment.