-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
URL Input: Use Popover instead of custom positionning and custom modals #6911
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
5ab713a
URL Input: Use Popover instead of custom positionning and custom modals
youknowriad 491828d
Remove the link offset
youknowriad 813bd2e
Force popover rerender when we click on another link
youknowriad e483cf5
URL Input: Inheritwq focus style
youknowriad 569ec28
Use the selectedNodeId instead of another popoverId
youknowriad File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ import { | |
ToggleControl, | ||
Toolbar, | ||
withSpokenMessages, | ||
Popover, | ||
} from '@wordpress/components'; | ||
import { keycodes } from '@wordpress/utils'; | ||
import { prependHTTP } from '@wordpress/url'; | ||
|
@@ -62,6 +63,7 @@ class FormatToolbar extends Component { | |
settingsVisible: false, | ||
opensInNewWindow: false, | ||
linkValue: '', | ||
popoverId: 1, // Used to force popover render to force recomputing the anchor | ||
}; | ||
|
||
this.addLink = this.addLink.bind( this ); | ||
|
@@ -98,6 +100,7 @@ class FormatToolbar extends Component { | |
settingsVisible: false, | ||
opensInNewWindow: !! nextProps.formats.link && !! nextProps.formats.link.target, | ||
linkValue: '', | ||
popoverId: this.state.popoverId + 1, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we re-use |
||
} ); | ||
} | ||
} | ||
|
@@ -167,7 +170,7 @@ class FormatToolbar extends Component { | |
|
||
render() { | ||
const { formats, focusPosition, enabledControls = DEFAULT_CONTROLS, customControls = [] } = this.props; | ||
const { linkValue, settingsVisible, opensInNewWindow } = this.state; | ||
const { linkValue, settingsVisible, opensInNewWindow, popoverId } = this.state; | ||
const isAddingLink = formats.link && formats.link.isAdding; | ||
|
||
const toolbarControls = FORMATTING_CONTROLS.concat( customControls ) | ||
|
@@ -208,58 +211,60 @@ class FormatToolbar extends Component { | |
{ ( isAddingLink || formats.link ) && ( | ||
<Fill name="RichText.Siblings"> | ||
<div className="editor-format-toolbar__link-container" style={ { ...focusPosition } }> | ||
{ isAddingLink && ( | ||
<Popover position="bottom center" focusOnMount={ !! isAddingLink } key={ popoverId }> | ||
{ isAddingLink && ( | ||
// Disable reason: KeyPress must be suppressed so the block doesn't hide the toolbar | ||
/* eslint-disable jsx-a11y/no-noninteractive-element-interactions */ | ||
<form | ||
className="editor-format-toolbar__link-modal" | ||
onKeyPress={ stopKeyPropagation } | ||
onKeyDown={ this.onKeyDown } | ||
onSubmit={ this.submitLink }> | ||
<div className="editor-format-toolbar__link-modal-line"> | ||
<UrlInput value={ linkValue } onChange={ this.onChangeLinkValue } /> | ||
<IconButton icon="editor-break" label={ __( 'Apply' ) } type="submit" /> | ||
<IconButton | ||
className="editor-format-toolbar__link-settings-toggle" | ||
icon="ellipsis" | ||
label={ __( 'Link Settings' ) } | ||
onClick={ this.toggleLinkSettingsVisibility } | ||
aria-expanded={ settingsVisible } | ||
/> | ||
</div> | ||
{ linkSettings } | ||
</form> | ||
<form | ||
className="editor-format-toolbar__link-modal" | ||
onKeyPress={ stopKeyPropagation } | ||
onKeyDown={ this.onKeyDown } | ||
onSubmit={ this.submitLink }> | ||
<div className="editor-format-toolbar__link-modal-line"> | ||
<UrlInput value={ linkValue } onChange={ this.onChangeLinkValue } /> | ||
<IconButton icon="editor-break" label={ __( 'Apply' ) } type="submit" /> | ||
<IconButton | ||
className="editor-format-toolbar__link-settings-toggle" | ||
icon="ellipsis" | ||
label={ __( 'Link Settings' ) } | ||
onClick={ this.toggleLinkSettingsVisibility } | ||
aria-expanded={ settingsVisible } | ||
/> | ||
</div> | ||
{ linkSettings } | ||
</form> | ||
/* eslint-enable jsx-a11y/no-noninteractive-element-interactions */ | ||
) } | ||
) } | ||
|
||
{ formats.link && ! isAddingLink && ( | ||
{ formats.link && ! isAddingLink && ( | ||
// Disable reason: KeyPress must be suppressed so the block doesn't hide the toolbar | ||
/* eslint-disable jsx-a11y/no-static-element-interactions */ | ||
<div | ||
className="editor-format-toolbar__link-modal" | ||
onKeyPress={ stopKeyPropagation } | ||
> | ||
<div className="editor-format-toolbar__link-modal-line"> | ||
<a | ||
className="editor-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 | ||
className="editor-format-toolbar__link-settings-toggle" | ||
icon="ellipsis" | ||
label={ __( 'Link Settings' ) } | ||
onClick={ this.toggleLinkSettingsVisibility } | ||
aria-expanded={ settingsVisible } | ||
/> | ||
<div | ||
className="editor-format-toolbar__link-modal" | ||
onKeyPress={ stopKeyPropagation } | ||
> | ||
<div className="editor-format-toolbar__link-modal-line"> | ||
<a | ||
className="editor-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 | ||
className="editor-format-toolbar__link-settings-toggle" | ||
icon="ellipsis" | ||
label={ __( 'Link Settings' ) } | ||
onClick={ this.toggleLinkSettingsVisibility } | ||
aria-expanded={ settingsVisible } | ||
/> | ||
</div> | ||
{ linkSettings } | ||
</div> | ||
{ linkSettings } | ||
</div> | ||
/* eslint-enable jsx-a11y/no-static-element-interactions */ | ||
) } | ||
) } | ||
</Popover> | ||
</div> | ||
</Fill> | ||
) } | ||
|
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not very consistent with modifier class naming which are otherwise boolean-ish. I might have preferred something like
has-no-arrow
oris-without-arrow
oris-no-arrow
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like how you see a comment from Andrew from time to time on old PRs :P
Anyway, I just pushed a fix to master (accidentally, I thought I was on a branch 😬 )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3ce3fee
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I enjoy to surf the
git blame
😄