-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Editor: Extract LinkContainer from FormatToolbar #9192
Conversation
import { __ } from '@wordpress/i18n'; | ||
import { displayShortcut } from '@wordpress/keycodes'; | ||
|
||
export const DEFAULT_CONTROLS = [ 'bold', 'italic', 'strikethrough', 'link', 'code' ]; |
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.
@iseulde I moved those contants to its own file. It's now easy to notice that code is listed as a default control, but it's not provided in formatting controls. Any thoughts?
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'm also not sure why there are two constants, and why code
is there... code
does have a shortcut and a pattern, but this constant is not used there.
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.
Perhaps code
should be taken away here?
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.
yes, let's remove it.
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 looking good and it will make it easier to port the toolbar to RN.
I added fix in e08af7b which resolves the issue with race condition between props update and internal state changes. To make it work properly the derived state always set |
@@ -1000,7 +999,7 @@ RichText.contextTypes = { | |||
}; | |||
|
|||
RichText.defaultProps = { | |||
formattingControls: DEFAULT_FORMATS, | |||
formattingControls: FORMATTING_CONTROLS.map( ( { format } ) => format ), |
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.
@iseulde - as you pointed out, we don't need this constant as we can produce it from the default FORMATTING_CONTROLS
.
f2dfed9
to
d2fc77a
Compare
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.
Looks good! We're definitely overdue to break up this component 🙂
I'm wondering if we should move all of the code that knows about links out of FormatToolbar
?
@@ -140,19 +107,16 @@ class FormatToolbar extends Component { | |||
} | |||
|
|||
addLink() { |
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.
Why not move these methods to LinkContainer
?
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.
It should be now possible as I removed the usage of setState
in both methods shared with toolbarControls
variable. I will double check if this is expected on mobile and open a follow-up PR 👍
d2fc77a
to
7b73a20
Compare
@@ -140,19 +107,16 @@ class FormatToolbar extends Component { | |||
} | |||
|
|||
addLink() { |
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.
It should be now possible as I removed the usage of setState
in both methods shared with toolbarControls
variable. I will double check if this is expected on mobile and open a follow-up PR 👍
@@ -164,8 +129,6 @@ class FormatToolbar extends Component { | |||
rel: this.state.opensInNewWindow ? 'noreferrer noopener' : null, | |||
value, | |||
} } ); | |||
|
|||
this.setState( { linkValue: value, isEditingLink: false } ); | |||
if ( ! this.props.formats.link.value ) { |
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.
We call this.props.onChange
so we don't need to update state explicitly because getDerivedStateFromProps
will handle it properly.
As commented already. It wasn't possible initially because both |
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.
Looks good to me!
Description
Extracted out of #9012.
This PR extracts
LinkContainer
to make it easier to provide React Native implementation for the parts that need to work differently on mobile devices.How has this been tested?
npm test
npm run build
All of those should work properly.
Types of changes
There should be no visual changes. It should be still possible to add/remove links from
RichText
powered fields like Paragraph block.Checklist: