SiteTitle: Add bold and italic toolbar buttons for convenience#46489
SiteTitle: Add bold and italic toolbar buttons for convenience#46489sejas wants to merge 21 commits intoWordPress:trunkfrom
Conversation
|
👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @sejas! 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. |
danielbachhuber
left a comment
There was a problem hiding this comment.
Awesome work, @sejas !
Overall, the buttons and keyboard shortcuts seem to work well.
I noticed a couple UX inconsistencies...
- If the Site Title is already italicized, then it's not possible to remove the italicization:
- When you have some partially selected text, clicking "Bold" makes the entire text bold:
- Seen above, if you click "Bold", the inherited italicization is reverted.
The first UX inconsistency isn't new in this pull request, so I don't think we need to address it.
I personally think the second UX inconsistency is acceptable because the toolbar buttons are a UX enhancement for the majority of use cases. But, I wanted to call it out so it's stated.
The third UX inconsistency should probably be addressed.
packages/block-library/src/site-title/edit/use-typography-style.js
Outdated
Show resolved
Hide resolved
|
@danielbachhuber, thanks for testing it and adding your feedback.
Did you add "Additional CSS" to your theme?
Yes, that's right. The Bold and Italic buttons add inline CSS to the whole block changing the appearance/style of the entire text. We don't support partial bold or italic as RichText does because we would need to add HTML tags to the site title, changing the semantics and conflicting with the current Appearance selector that already exists.
I've tested it using the original SiteTitle, and I have experienced the same behavior. If I add external CSS to the theme, and I choose Bold using the "Appearance selector" the italicization is reverted to |
@sejas I didn't, no. I agree that we don't need to worry about it.
Ah, ok. That's fine, then. |
aaronrobertshaw
left a comment
There was a problem hiding this comment.
Excellent work on this @sejas 👍
✅ Everything tests as advertised for me.
The generally low prominence of the font appearance control was by design. There’s some history in #35604, but given the direction on the original issue, I'd say the block toolbar additions and current behaviour are appropriate.
I don’t see any of the floated UX issues as blockers for this PR. They are potential opportunities to iterate further on the typography block supports in follow-ups.
If the Site Title is already italicized, then it's not possible to remove the italicization:
The italic style should be able to be removed by selecting the "Regular" option in the font appearance control within the block inspector's typography panel.
Do other blocks hard-code the bold value in this way?
Given how tightly coupled a lot of this is to the typography block support, I wonder if it would be better to move some of this, such as the useTypographyStyles hook, to the typography block support and consume it from there.
It might also avoid duplicating/syncing the bold value while allowing other blocks to potentially adopt the same feature as has been added to the Site Title block in this PR.
While exploring that option, perhaps it might be helpful to rename the hook to something more reflective of the subset of typography styles it is returning, e.g. useFontAppearanceStyles.
packages/block-library/src/site-title/edit/use-typography-style.js
Outdated
Show resolved
Hide resolved
|
@aaronrobertshaw, It's very smart to move the hook to the typography block support and share the bold/italic values to avoid future differences 👍 . Thanks for the suggestion 🙌. I'm considering adding new keys to the For example: "supports": {
...
"typography": {
"fontSize": true,
"lineHeight": true,
"__experimentalFontFamily": true,
"__experimentalTextTransform": true,
"__experimentalTextDecoration": true,
"__experimentalFontStyle": true,
"__experimentalFontWeight": true,
"__experimentalLetterSpacing": true,
"__experimentalDefaultControls": {
"fontSize": true,
"lineHeight": true,
"fontAppearance": true,
+ "fontAppearanceToolbar": true, // <- NEW. It would also check if `__experimentalFontStyle` or/and `__experimentalFontWeight` are enabled.
"letterSpacing": true,
"textTransform": true
}
} |
That sounds like a logical next step to me 👍 Might I suggest, though, that you move that exploration to a follow-up PR? That way, the great work already done in this PR can land sooner and won't get bogged down by discussions around how best to fit the proposed change into the shape of the block supports, what blocks could or should benefit from it etc. |
I agree. Let's finish this PR first 👌. I've updated this PR with the following changes:
I still need to change the icons to differentiate them from the RichText buttons. I'll post some design suggestions in the issue: #45854 (comment) |
aaronrobertshaw
left a comment
There was a problem hiding this comment.
Thank you for the continued iterations on this PR @sejas 👍
It is still testing well for me.
The one thing I'm not certain about is the introduction of the __experimental API. I'm aware that there's a concerted effort to avoid introducing experimental APIs as they previously had a habit of working their way into core.
Recently, a new approach to managing experiments was merged via #43386. I get the feeling that might be overkill for this particular case, though.
Perhaps we could get additional reviews and input on this PR to avoid the experimental stage for the new custom hook altogether. This might also be able to occur while we're waiting on the new bold and italic icons for the toolbar buttons.
What do you think?
Yes, I think it would be a great idea to avoid the experimental stage for the new hook 👌 |
|
@sejas very nice work!!! Everything looks nice. Really loved the constants that you used for bold, italic etc.. As @danielbachhuber , I have the same UI inconsistencies:
I also noticed that by changing the style back to "Regular", the italics are being removed. and pressing the button again, we end up in the 1 case. Again, nice work! |
…rdpress/block-editor
27dfa75 to
dcddcf9
Compare
|
Thanks for the update @sejas, are you using the |
Oh!, I used |
|
Thanks for changing that detail :) The icon isn't the perfect one, but I'm struggling to think of a better one right now. For me it's probably okay to continue moving forwards with this one, and circle back to explore a new icon later. But I'd appreciate another set of eyes from @WordPress/gutenberg-design in case I'm missing an obvious option. |
|
Happy to try this and revisit. |
Does the Bold style work for you when using the original "Typography panel" ?
Happy to remove it if needed. I intended to make clear that some state is applied inside. The heading and paragraph buttons use the Value Icon to represent this state. But we can't use the |
No. I guess that's an issue on my local :)
Yeah I don't think it's really necessary. |
danielbachhuber
left a comment
There was a problem hiding this comment.
Works well to my testing!
CleanShot.2023-02-27.at.14.16.14.mp4
FYI - I merged trunk.
Probably outside the scope of this PR, but it might be cool if the icon reflected the font appearance (e.g. appeared as bolded when "Bold" was selected, italicized when "Italic" was selected, etc.)
I'll defer to the @WordPress/gutenberg-core folks for final approval on the code.
| InspectorControls, | ||
| BlockControls, | ||
| useBlockProps, | ||
| __experimentalUseFontAppearanceStyles as useFontAppearanceStyles, |
There was a problem hiding this comment.
Any reason for this to leave in the block editor if it's only used in the site-title block?
Maybe folks working on block tools can shed more light on this new toolbar. cc @aaronrobertshaw @andrewserong @jasmussen
There was a problem hiding this comment.
Ok, just saw that @aaronrobertshaw is already reviewing this PR :)
There was a problem hiding this comment.
👍 Re-reviewing this PR is on my radar for the next couple of days.
The logic behind the hook living in the block-editor package was that it is so closely tied to the typography block supports in that package. There's also the potential for it to be re-used across other blocks leveraging the font weight and style supports.
There was a problem hiding this comment.
Maybe we can start with it being "private" unless we're certain that it's an API we want to offer to third-party devs.
aaronrobertshaw
left a comment
There was a problem hiding this comment.
Thanks for continuing to iterate on this one @sejas 👍
In its current state, the PR is testing very nicely for me. Great work!
Before landing this, there are a couple more things we should probably address.
- Removing the toggled state for the block toolbar's typography dropdown.
- Now we have the capability to
lockandunlockexperimental APIs, I think the best and quickest path to landing this will be to leverage that as @youknowriad suggested. You can find more info on this in the coding guidelines. - (Optional) If the intent is for more than just the Site Title block to eventually offer the block toolbar control for font appearance, moving the new
FontAppearanceControlto a component alongside the hook so it can be reused might make sense. If doing this, it should be locked as private/experimental as well.
With the above tweaks addressed, I think this PR will be in good shape. ✨
|
Closing this PR, since I won't focus on it in the short time. Thank y'all! |






What?
Add Font face control to the SiteTitle toolbar where users can use
BoldandItalictext styles:Why?
The
SiteTitlestyle options are difficult to access. I propose adding the bold and italic buttons to the toolbar allowing users to edit the text style easily.In addition, we improve the accessibility of the block by allowing the shortcuts
Ctrl + Bto make the text bold andCtrl + Ito make it italic.How?
I've added two new Toolbar buttons to the SiteTitle block. I'm using the
attribtues.styleas the source of truth of the bold and style state. For this reason, the new buttons and the Appearance Selector are in sync. Check the screencast to see it in action.Testing Instructions
Edit.SiteTitleblock.Testing Instructions for Keyboard
SiteTitleblockCtrl + Bor⌘ + BCtrl + Ior⌘ + IScreenshots or screencast
site-title-bold-italic-different-group.mp4