Skip to content

Commit

Permalink
Merge pull request #3224 from WordPress/try/3211-link-dialog-position
Browse files Browse the repository at this point in the history
FIX: Link Dialog's position appears randomly generated
  • Loading branch information
tg-ephox authored Oct 31, 2017
2 parents 038bd41 + 9c62023 commit 27f81fd
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 27 deletions.
55 changes: 32 additions & 23 deletions blocks/editable/format-toolbar/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/**
* External dependencies
*/
import { Fill } from 'react-slot-fill';

/**
* WordPress dependencies
*/
Expand Down Expand Up @@ -172,32 +177,36 @@ class FormatToolbar extends Component {
<Toolbar controls={ toolbarControls } />

{ ( isAddingLink || isEditingLink ) &&
<form
className="blocks-format-toolbar__link-modal"
style={ linkStyle }
onSubmit={ this.submitLink }>
<UrlInput value={ newLinkValue } onChange={ this.onChangeLinkValue } />
<IconButton icon="editor-break" label={ __( 'Apply' ) } type="submit" />
<IconButton icon="editor-unlink" label={ __( 'Remove link' ) } onClick={ this.dropLink } />
<IconButton icon="admin-generic" onClick={ this.toggleLinkSettingsVisibility } aria-expanded={ settingsVisible } />
{ linkSettings }
</form>
<Fill name="Editable.Siblings">
<form
className="blocks-format-toolbar__link-modal"
style={ linkStyle }
onSubmit={ this.submitLink }>
<UrlInput value={ newLinkValue } onChange={ this.onChangeLinkValue } />
<IconButton icon="editor-break" label={ __( 'Apply' ) } type="submit" />
<IconButton icon="editor-unlink" label={ __( 'Remove link' ) } onClick={ this.dropLink } />
<IconButton icon="admin-generic" onClick={ this.toggleLinkSettingsVisibility } aria-expanded={ settingsVisible } />
{ linkSettings }
</form>
</Fill>
}

{ !! formats.link && ! isAddingLink && ! isEditingLink &&
<div className="blocks-format-toolbar__link-modal" style={ linkStyle }>
<a
className="blocks-format-toolbar__link-value"
href={ formats.link.value }
target="_blank"
>
{ formats.link.value && filterURLForDisplay( decodeURI( formats.link.value ) ) }
</a>
<IconButton icon="edit" label={ __( 'Edit' ) } onClick={ this.editLink } />
<IconButton icon="editor-unlink" label={ __( 'Remove link' ) } onClick={ this.dropLink } />
<IconButton icon="admin-generic" onClick={ this.toggleLinkSettingsVisibility } aria-expanded={ settingsVisible } />
{ linkSettings }
</div>
<Fill name="Editable.Siblings">
<div className="blocks-format-toolbar__link-modal" style={ linkStyle }>
<a
className="blocks-format-toolbar__link-value"
href={ formats.link.value }
target="_blank"
>
{ formats.link.value && filterURLForDisplay( decodeURI( formats.link.value ) ) }
</a>
<IconButton icon="edit" label={ __( 'Edit' ) } onClick={ this.editLink } />
<IconButton icon="editor-unlink" label={ __( 'Remove link' ) } onClick={ this.dropLink } />
<IconButton icon="admin-generic" onClick={ this.toggleLinkSettingsVisibility } aria-expanded={ settingsVisible } />
{ linkSettings }
</div>
</Fill>
}
</div>
);
Expand Down
9 changes: 5 additions & 4 deletions blocks/editable/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
noop,
} from 'lodash';
import { nodeListToReact } from 'dom-react';
import { Fill } from 'react-slot-fill';
import { Fill, Slot } from 'react-slot-fill';
import 'element-closest';

/**
Expand Down Expand Up @@ -325,9 +325,9 @@ export default class Editable extends Component {
// is absolute positioned and it's not shown when we compute the position here
// so we compute the position about its parent relative position and adds the offset
const toolbarOffset = this.props.inlineToolbar ?
{ top: 50, left: 0 } :
{ top: 40, left: -( ( blockPadding * 2 ) + blockMoverMargin ) };
const linkModalWidth = 250;
{ top: 10, left: 0 } :
{ top: 0, left: -( ( blockPadding * 2 ) + blockMoverMargin ) };
const linkModalWidth = 305;

return {
top: position.top - containerPosition.top + ( position.height ) + toolbarOffset.top,
Expand Down Expand Up @@ -709,6 +709,7 @@ export default class Editable extends Component {
{ MultilineTag ? <MultilineTag>{ placeholder }</MultilineTag> : placeholder }
</Tagname>
}
{ focus && <Slot name="Editable.Siblings" /> }
</div>
);
}
Expand Down

0 comments on commit 27f81fd

Please sign in to comment.