Perfect your code
With built-in code review tools, GitHub makes it easy to raise the quality bar before you ship. Join the 40 million developers who've merged over 200 million pull requests.
Sign up for free See pricing for teams and enterprisesUpdate `LinkControl` component to utilitse dynamic settings for additional settings "drawer" #18285
Conversation
This comment has been minimized.
This comment has been minimized.
|
@phpbits This is relevant to #17557 (comment) |
This comment has been minimized.
This comment has been minimized.
|
@retrofox I'm interested in how you see my change working with https://github.com/WordPress/gutenberg/pull/18062/files#diff-17e2993cb0b8cf64434015038b235162R214 |
TestingI'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 } ) }
/> |
This comment has been minimized.
This comment has been minimized.
|
btw feel free to go-ahead not waiting for #18062 |
This comment has been minimized.
This comment has been minimized.
|
I'll be rebasing this branch shortly and tweaking the visual styles. Then we're |
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
This comment has been minimized.
This comment has been minimized.
|
@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? |
This comment has been minimized.
This comment has been minimized.
|
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. |
This comment has been minimized.
This comment has been minimized.
|
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 } );
}; |
This comment has been minimized.
This comment has been minimized.
|
Also, we will need to update the setting ID here to |
…stency
This comment has been minimized.
This comment has been minimized.
|
Ok @retrofox this is updated. |
Addresses #18285 (comment)
…ional settings "drawer" (WordPress#18285) * Adds basic coverage test for new tab setting * Refactor ‘new-tab` to camelCase for consistency * Fix bug with null render if settings has a length and convert to array 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. * Updates to loop over supplied settings 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. * Updates docs * Updates Nav Item Block to utilise new setting format * Updates spacing between individual setting controls * Update docs for settings * Updates setting key/id to match attribute to simply and improve consistency * Fix Nav Menu Block dynamic setting of attribute Addresses WordPress#18285 (comment)




getdave commentedNov 5, 2019
•
edited
Closes #18206.
The new experimental Link UI provided by
LinkControlallows 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
currentSettingsprop 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
LinkControlwe can expect this PR to break. It will need updating so that:new-tabbecomesnewTabin any settings provided.Checklist: