-
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
Add No Follow toggle to Link Control #48722
base: trunk
Are you sure you want to change the base?
Conversation
After almost three years and a lot of fruitful discussion, it's finally here. The ability to add a nofollow rel to a link. Everything works in the backend as shown on the screengrab. The only thing I couldn't figure out in the time I had was how to save this to the markup so it also renders correctly on the frontend. Hope someone can help with this or point me in the right direction. Fixes WordPress#23011
One more thing: I've never written a test in a big project like this, so if someone can help me with updating any tests where necessary, that would also be greatly appreciated. 🙂 |
Thank you. This is on my radar to review. As explained we are in the WP 6.2 release cycle so I may not be able to get to this straight away. Also tagging in @jameskoster as he's been working on the Design here. |
@getdave Good luck with the release! |
A good place to add tests is in That said I think the tests are suitale generic as to not need anything additional for this new control. You'll see there's already a test The other option is an e2e test in |
Agreed. That's definitely one for another Issue. In fact I think we already have one 🤔 |
I think the test failures here are legit. We'll need to look into those. |
Do you know anyone that can help with this? :) |
I am happy to try and support that. Likely post-WP 6.2 release. |
I haven't forgotten about this. I've been super busy with 6.2. It's still on my list. |
Let me take a look at this today. |
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.
Let's try and get a @WordPress/gutenberg-design review on this one.
We should also add some e2e test coverage. I'm going to take a look at how we can extend what we have.
Apologies for the delay here but it's been an extremely busy period with the 6.2 release.
@@ -42,6 +42,9 @@ const LinkSettingsScreen = ( { | |||
const [ opensInNewWindow, setOpensInNewWindows ] = useState( | |||
activeAttributes.target === '_blank' | |||
); | |||
const [ markedAsNoFollow, setMarkedAsNoFollow ] = useState( | |||
( activeAttributes.rel = 'nofollow' ) |
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.
( activeAttributes.rel = 'nofollow' ) | |
( activeAttributes.rel?.includes( 'nofollow' ) ) |
Are there other options for this we need to consider?
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'd say let's keep the PR's simple and small, we can always add more later but that prevents them from getting to complex or going stale
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.
No sorry I was thinking if the attributes have other settings on rel
. For example noopener
like this PR accounts for elsewhere (e.g. packages/format-library/src/link/inline.js
).
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.
+1 to what @getdave asks as it is now it doesn't work because it expects a boolean value for markedAsNoFollow
Just following up on this comment: We should show the help text below both control and toggle to match the other instances where this is used: As for the PR itself, it seems clear enough that nofollow is a property you should be able to set on a link. It's also a somewhat advanced control, so to me this is an argument for keeping the "Advanced" toggle. This one: |
This comment was marked as outdated.
This comment was marked as outdated.
@@ -16,7 +16,7 @@ export default function useInternalInputValue( value ) { | |||
if ( value && value !== internalInputValue ) { | |||
setInternalInputValue( value ); | |||
} | |||
}, [ value ] ); | |||
}, [ internalInputValue, 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.
}, [ internalInputValue, value ] ); | |
}, [ value ] ); |
Please can we revert this change and use the eslint syntax to disable the warning?
The original code is clearly faulty (that is my fault) but we should avoid overcomplicating this PR by adding the dep here.
I will raise a separate Issue to fix this problem.
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.
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.
Once we revert this change we might see tests passing again 🤞
title: __( | ||
'Search engines should ignore this link (mark as nofollow)' | ||
), |
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.
title: __( | |
'Search engines should ignore this link (mark as nofollow)' | |
), | |
title: __( | |
'No follow' | |
), | |
help: __( | |
'Search engines should ignore this link' | |
), |
Let's extend this and then make changes within settings.js
to optionally include the help
prop on the ToggleControl
.
We also need to make the new setting optional in the UI and handling code. For an example of what I mean try adding a link to a Navigation block and try toggling the No follow setting. It doesn't work because the Nav block doesn't handle it yet. We can patch the Nav block code, but there will be other (3rd party) consumers of this code who may not know about this change and won't have time to adjust their code to account for it. One idea was that we could filter out any // filter out any settings not in the value
const filteredSettings = settings.filter( ( setting ) =>
Object.keys( value ).includes( setting.id )
); We would need to add a test for this type of scenario in
Could you elaborate on this a little? I tried with a paragraph block and it rendered on the front of the site. |
I've just assigned myself to check the |
<BottomSheet.SwitchCell | ||
icon={ external } | ||
label={ __( | ||
'Search engines should ignore this link (mark as nofollow)' |
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 a bit long for mobile so maybe we could use just the part "No follow" as suggested in this comment.
label={ __( | ||
'Search engines should ignore this link (mark as nofollow)' | ||
) } | ||
value={ markedAsNoFollow } |
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.
Since we are using the markedAsNoFollow
value here and it's within a useMemo
we should include it in the dependencies so it gets the updated value.
@@ -99,6 +102,7 @@ const LinkSettingsScreen = ( { | |||
const format = createLinkFormat( { | |||
url, | |||
opensInNewWindow, | |||
markedAsNoFollow, |
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.
markedAsNoFollow, | |
markAsNoFollow: markedAsNoFollow, |
Since the names are different we should update it so the right value gets to createLinkFormat
Hey @tomdevisser 👋 thank you for working on including these changes for the mobile editor as well, I've shared some comments/suggestions, let me know what you think. Thanks! |
Weighing in from an SEO perspective; a few things to watch out for:
Given the above, I'd be keen to make sure that this can be disabled, otherwise, it'll end up duplicating and degrading the functionality we offer in Yoast SEO. |
@jonoalderson Thanks for this useful feedback.
I'm curious about this. My previous review suggested that by way of backwards compatibility, this PR must be updatedd to not include any setting which is not provided in the Would this be sufficient to cater for 3rd party extenders (Yoast is one of these) who have an existing implementation which should be extending whatever is provided by Core Gutenberg. It sounds like we are thinking along the same lines, but I want to check we're not making any exceptions for any specific extenders 🙇♂️ @tomdevisser No pressure at all, but do you anticipate being able to continue working on this PR? |
@getdave I'm afraid some other higher priority issues are taking up all of my time at the moment. If you'd want to, feel free to move this forward! |
Same here. No rush 👍 |
A PR for this has been merged to Gutenberg Thank you for the agency in pushing this forward 🙇 |
What, why and how?
After almost three years and a lot of fruitful discussion, it's finally here. The ability to add a nofollow rel to a link.
Everything works in the backend as shown on the screengrab. The only thing I couldn't figure out in the time I had now was how to save this to the markup so it also renders correctly on the frontend. Hope someone can help with this or point me in the right direction.
Testing Instructions
A few important notes
Don't see this as finished yet, but I think we now have a very good starting point to start adding this feature!
Fixes #23011
nofollow.mov