-
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
Link Control - Add support for text only labels #47930
Link Control - Add support for text only labels #47930
Conversation
👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @abhi3315! In case you missed it, we'd love to have you join us in our Slack community, where we hold regularly weekly meetings open to anyone to coordinate with each other. If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information. |
@abhi3315 Thank you for the PR. I have looped in @tellthemachines who has implemented labels like this before and may have a view. I think it's safe to shorten the toggle text to just |
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.
Thanks for picking this up! I left some suggestions below.
const showIconLabels = useSelect( | ||
( select ) => | ||
select( preferencesStore ).get( | ||
'core/edit-post', |
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 block editor component, so it gets used across both post and site editors. Unfortunately the text label settings are specific to each editor, so using edit-post
preferences here means that if the preference is set differently in the site editor, this component won't reflect it 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.
Great spot @tellthemachines. Some more context on @abhi3315. Basically the block editor package is designed to be used standalone outside of "WordPress". Therefore we can't query anything like core
store or even preferences namespaces.
To work around this we often create editor "settings" which we:
- set in the editor instances (
post
,widgets
andsite
) - passing through to the block editor component - consume within the block editor package (e.g. here in Link Control) to access the data
And example of this can be found in
packages/edit-site/src/components/block-editor/index.js
If you do it like this you could have a single setting for the text labels passed into the block editor. Then you could consume that value.
Does that sound suitable @tellthemachines?
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.
Thanks @getdave @tellthemachines for explaining to me thoroughly. 🙇🏻♂️
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.
In this case we don't need to create an editor setting, because the classname we hook the styles onto is being applied to the interface component in both the post and the site editor, so we can make this change just by adding some CSS ✨
@@ -283,7 +294,9 @@ function LinkControl( { | |||
<div | |||
tabIndex={ -1 } | |||
ref={ wrapperNode } | |||
className="block-editor-link-control" | |||
className={ classnames( 'block-editor-link-control', { |
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.
The classname doesn't need to be added here, because it's already added at the top level of the interface skeleton.
Instead, I'd suggest re-structuring the CSS below so it takes advantage of that top-level classname, similarly to the block toolbar CSS.
Thanks, @tellthemachines for the feedback. |
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.
Thanks for the update, it's working well now! Just a little niggle about the CSS structure, but otherwise looks OK!
@@ -22,6 +23,22 @@ $preview-image-height: 140px; | |||
width: 90vw; | |||
max-width: $modal-min-width; | |||
} | |||
|
|||
.show-icon-labels & { | |||
#{$root}__tools { |
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 don't need it to be this specific, it's fine to nest .components-button.has-icon
directly under .show-icon-labels &
. The decreased specificity also has the advantage that if we ever add another icon button to the link control, text label should just work for it out of the box 🙂
@tellthemachines I have made the changes. Please review it again. |
The way I do this is.
|
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.
In this shape the code of the PR is great. Tested and works 🚢 it
Re-running the failed e2e tests here. I'd like to be sure that we didn't introduce any regressions especially as the failures were regarding modal focus management. There's an outside chance that adding the slot may have caused an unexcepted knock on effect. Let's see. Would also be good to get a 👍 on this from @tellthemachines. |
Looks like test failures should be fixed by #48236. Let's rebase against trunk again to bring this one in and see if it fixes the test for us. |
065eae1
to
9f2673e
Compare
@getdave I have rebased the branch. |
@getdave All the tests are cleared. 🎉 |
Congratulations on your first merged pull request, @abhi3315! We'd like to credit you for your contribution in the post announcing the next WordPress release, but we can't find a WordPress.org profile associated with your GitHub account. When you have a moment, visit the following URL and click "link your GitHub account" under "GitHub Username" to link your accounts: https://profiles.wordpress.org/me/profile/edit/ And if you don't have a WordPress.org account, you can create one on this page: https://login.wordpress.org/register Kudos! |
Congrats on this PR @abhi3315 👏 You can check |
What?
Shows the text labels only in the Link Control popover.
Why?
#47545
When the
Show button text labels
toggle is enabled from the Gutenberg preferences, LinkControl is only showing the setting icon. This PR will display the text label or icon in LinkControl according to preferences.How?
showIconLabels
from the preferences data store.show-icon-labels
CSS class to the component accordingly to hide or display the icon/text.Testing Instructions
Show button text labels
.Testing Instructions for Keyboard
Screenshots or screencast