Skip to content

Commit

Permalink
Fix link dialog position
Browse files Browse the repository at this point in the history
  • Loading branch information
tg-ephox committed Oct 30, 2017
1 parent c5ebeca commit 970b10f
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="Formatting.LinkDialog">
<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="Formatting.LinkDialog">
<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="Formatting.LinkDialog" /> }
</div>
);
}
Expand Down

0 comments on commit 970b10f

Please sign in to comment.