-
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
Update LinkControl
component to utilitse dynamic settings for additional settings "drawer"
#18285
Update LinkControl
component to utilitse dynamic settings for additional settings "drawer"
#18285
Conversation
@phpbits This is relevant to #17557 (comment) |
@retrofox I'm interested in how you see my change working with https://github.com/WordPress/gutenberg/pull/18062/files#diff-17e2993cb0b8cf64434015038b235162R214 |
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.
Testing
I've tested locally in my dev env. It looks pretty good!
It's pretty easy to use and narrows very good with the block attributes:
<LinkControl
currentSettings={ [
{
id: 'opensInNewTab',
title: __( 'Open in New Tab' ),
checked: opensInNewTab,
},
{
id: 'noFollow',
title: 'No follow',
checked: noFollow,
},
] }
onSettingsChange={ ( setting, value ) => setAttributes( { [ setting ]: value } ) }
/>
btw feel free to go-ahead not waiting for #18062 👍 |
I'll be rebasing this branch shortly and tweaking the visual styles. Then we're 👍 to merge. |
Make settings an array so that it can be ordered. Fix incorrect conditional testing for .length to ensure it passes if settings _does_ have a length.
Previously only a “new tab” setting was hardcoded. Update so retain “new tab” as the default, but also allow for custom settings if/when provided.
ae9da61
to
0458a32
Compare
@retrofox Having to pass the entire config object even to use the default setting feels like a lot of effort:
Is there a way to make this API nicer? |
While I was testing I immediately thought that the <LinkControl
currentSettings={ [
{
id: 'opensInNewTab',
title: __( 'Open in New Tab' ), // why can't I omit this?
},
] } About the title, maybe? I guess that maybe it could be handled by the parent component? Not sure, though. We can just remove the title if it isn't defined. |
Dave, I think we should update how the Menu Item updates the link settings: something like that? const updateLinkSetting = ( setter ) => ( setting, value ) => {
setter( { [setting]: value } );
}; |
Also, we will need to update the setting ID here to |
Ok @retrofox this is updated. |
Closes #18206.
The new experimental Link UI provided by
LinkControl
allows for a currently selected link to have settings such as "Open in new tab"...etcAs things stand the only setting that is possible is "new tab" as this has been hard coded.
This PR updates so that multiple settings can be provided by passing the
currentSettings
prop toLinkControl
:How has this been tested?
Automated tests cover this change.
Types of changes
Breaking change (fix or feature that would cause existing functionality to not work as expected).
As this updates
LinkControl
we can expect this PR to break. It will need updating so that:new-tab
becomesnewTab
in any settings provided.Checklist: