Skip to content

SiteTitle: Add bold and italic toolbar buttons for convenience#46489

Closed
sejas wants to merge 21 commits intoWordPress:trunkfrom
sejas:add/site-title-bold-italic-styles
Closed

SiteTitle: Add bold and italic toolbar buttons for convenience#46489
sejas wants to merge 21 commits intoWordPress:trunkfrom
sejas:add/site-title-bold-italic-styles

Conversation

@sejas
Copy link
Copy Markdown
Contributor

@sejas sejas commented Dec 13, 2022

What?

Add Font face control to the SiteTitle toolbar where users can use Bold and Italic text styles:

Screenshot 2023-02-24 at 14 26 45

Why?

The SiteTitle style 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 + B to make the text bold and Ctrl + I to make it italic.

How?

I've added two new Toolbar buttons to the SiteTitle block. I'm using the attribtues.style as 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

  1. Go to Appearance > Editor.
  2. Click on Edit.
  3. Select your SiteTitle block.
  4. Observe that there are a new Typography button on the Toolbar, click it and observe the dropdown with the Bold and Italic options.
  5. Click on the Bold button.
  6. Observe the text transforms to bold.
  7. Click on the Italic button.
  8. Observe the text transforms to italic.
  9. Observe that the Appearance select in the inner settings has changed too. The toolbar and the select are in sync.
  10. Save the template.
  11. Observe the Frontend of the site shows the correct styles.

Testing Instructions for Keyboard

  1. Select the SiteTitle block
  2. Press Ctrl + B or ⌘ + B
  3. Observe the text gets bold.
  4. Press Ctrl + I or ⌘ + I
  5. Observe the text gets italic.

Screenshots or screencast

Before After
site-title-before Screenshot 2023-02-24 at 14 38 04
site-title-bold-italic-different-group.mp4

The Typography icon was updated here #46489 (comment)

@sejas sejas requested a review from ajitbohra as a code owner December 13, 2022 03:10
@github-actions github-actions bot added the First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository label Dec 13, 2022
@github-actions
Copy link
Copy Markdown

👋 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.

Copy link
Copy Markdown
Member

@danielbachhuber danielbachhuber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome work, @sejas !

Overall, the buttons and keyboard shortcuts seem to work well.

I noticed a couple UX inconsistencies...

  1. If the Site Title is already italicized, then it's not possible to remove the italicization:

image

  1. When you have some partially selected text, clicking "Bold" makes the entire text bold:

image

  1. 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.

@sejas
Copy link
Copy Markdown
Contributor Author

sejas commented Dec 13, 2022

@danielbachhuber, thanks for testing it and adding your feedback.

  1. If the Site Title is already italicized, then it's not possible to remove the italicization:

Did you add "Additional CSS" to your theme?
The user can add external CSS that modifies the appearance of any block. I think we shouldn't worry about it. If you add the same external CSS rule to a Paragraph, Can you undo the italicization using the toolbar buttons?.

  1. When you have some partially selected text, clicking "Bold" makes the entire text bold:

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.

  1. Seen above, if you click "Bold", the inherited italicization is reverted.

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 regular too.
Screenshot 2022-12-13 at 17 18 48
The buttons behave identically as the "Appearance selector" does. This behavior already exists on SiteTitle, and this PR did not introduce it.
From my point of view, if the user/theme adds external CSS rules, then the behavior of the block can be compromised. Similar to point 1.
If you think it's necessary, I'm happy to revisit it or make a bigger refactor on the SiteTitle block.

@danielbachhuber
Copy link
Copy Markdown
Member

Did you add "Additional CSS" to your theme? The user can add external CSS that modifies the appearance of any block. I think we shouldn't worry about it.

@sejas I didn't, no. I agree that we don't need to worry about it.

The buttons behave identically as the "Appearance selector" does. This behavior already exists on SiteTitle, and this PR did not introduce it.
From my point of view, if the user/theme adds external CSS rules, then the behavior of the block can be compromised. Similar to point 1.

Ah, ok. That's fine, then.

@danielbachhuber danielbachhuber changed the title SiteTitle: Add bold and italic controls SiteTitle: Add bold and italic toolbar buttons for convenience Dec 13, 2022
@danielbachhuber danielbachhuber self-requested a review December 13, 2022 20:02
Copy link
Copy Markdown
Contributor

@aaronrobertshaw aaronrobertshaw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@sejas
Copy link
Copy Markdown
Contributor Author

sejas commented Dec 14, 2022

@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 supports.typography to show the new toolbar buttons. Other core blocks could use them just by enabling them. If we go this way, I will need to investigate how to add the shortcuts.

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
	}
}

@aaronrobertshaw
Copy link
Copy Markdown
Contributor

I'm considering adding new keys to the supports.typography to show the new toolbar buttons. Other core blocks could use them just by enabling them. If we go this way, I will need to investigate how to add the shortcuts.

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.

@sejas sejas requested a review from ellatrix as a code owner December 15, 2022 17:13
@sejas
Copy link
Copy Markdown
Contributor Author

sejas commented Dec 15, 2022

Might I suggest, though, that you move that exploration to a follow-up PR?

I agree. Let's finish this PR first 👌.

I've updated this PR with the following changes:

  • Renamed the hook to useFontAppearanceStyles and moved to block-editor/src/hooks. I've decided to create a separate file. Another good place could be inside font-appearance.js.
  • I'm consuming the hook with the prefix __experimental.
  • font-appearance-control and the new hook use the same variables for Bold and Italic.
  • Moved the keydown/shotrcut logic inside the hook.

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)

Copy link
Copy Markdown
Contributor

@aaronrobertshaw aaronrobertshaw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

@sejas
Copy link
Copy Markdown
Contributor Author

sejas commented Dec 20, 2022

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 👌

@kozer
Copy link
Copy Markdown
Contributor

kozer commented Dec 20, 2022

@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:

  1. If the Site Title is already italicized, then it's not possible to remove the italicization
  2. When you have some partially selected text, clicking "Bold" makes the entire text bold (This is not happening in the Custom link block for example)
  3. If you click "Bold", the inherited italicization is reverted.

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!

@sejas sejas force-pushed the add/site-title-bold-italic-styles branch from 27dfa75 to dcddcf9 Compare February 20, 2023 18:29
@jameskoster
Copy link
Copy Markdown
Contributor

Thanks for the update @sejas, are you using the typography icon from the WordPress Icons package? It looks a bit different.

@sejas
Copy link
Copy Markdown
Contributor Author

sejas commented Feb 24, 2023

Thanks for the update @sejas, are you using the typography icon from the WordPress Icons package? It looks a bit different.

Oh!, I used formatUppercase icon.
Fixed here fa2b28b 👌.
@jameskoster, Thanks for catching the mistake.

Screenshot 2023-02-24 at 12 37 24

@jameskoster
Copy link
Copy Markdown
Contributor

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.

@jasmussen
Copy link
Copy Markdown
Contributor

Happy to try this and revisit.

@jameskoster
Copy link
Copy Markdown
Contributor

I just took this for a spin:

Screenshot 2023-02-27 at 11 54 29

Bold doesn't appear to be working, could that be something on my local setup?

I'm not sure we need to the 'toggled' state on the toolbar button when styles are selected.

@sejas
Copy link
Copy Markdown
Contributor Author

sejas commented Feb 27, 2023

@jameskoster

Bold doesn't appear to be working, could that be something on my local setup?

Does the Bold style work for you when using the original "Typography panel" ?

Screenshot 2023-02-27 at 12 30 41

I'm not sure we need to the 'toggled' state on the toolbar button when styles are selected.

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 B I icons, so I went for the toggled versions with black background.

@jameskoster
Copy link
Copy Markdown
Contributor

Does the Bold style work for you when using the original "Typography panel" ?

No. I guess that's an issue on my local :)

Happy to remove it if needed

Yeah I don't think it's really necessary.

Copy link
Copy Markdown
Member

@danielbachhuber danielbachhuber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, just saw that @aaronrobertshaw is already reviewing this PR :)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

@aaronrobertshaw aaronrobertshaw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

  1. Removing the toggled state for the block toolbar's typography dropdown.
  2. Now we have the capability to lock and unlock experimental 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.
  3. (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 FontAppearanceControl to 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. ✨

@sejas
Copy link
Copy Markdown
Contributor Author

sejas commented Oct 2, 2024

Closing this PR, since I won't focus on it in the short time. Thank y'all!

@sejas sejas closed this Oct 2, 2024
@sejas sejas deleted the add/site-title-bold-italic-styles branch October 2, 2024 11:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Block] Site Title Affects the Site Title Block First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Site Title Block: Add a toolbar shortcut to italicize the text

7 participants