Skip to content
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

Feat: Button groups in Typography tools should use ToggleGroupControl #64529

Merged
merged 4 commits into from
Aug 16, 2024

Conversation

hbhalodia
Copy link
Contributor

What?

Why?

  • To make use of components instead of ad hoc buttons.

How?

  • This PR changes the SegmentedTextControl component, to make use of ToggleGroupControl and ToggleGroupControlOptionIcon to render the same logic as it did with buttons.

Testing Instructions

  1. Open any post/page.
  2. Add any paragraph.
  3. Open typography controls in block.
  4. Check for letter case, orientation, and decoration, it should work as is.

Testing Instructions for Keyboard

  • NIL

Screenshots or screencast

Screenshot 2024-08-15 at 10 44 27 AM

@hbhalodia hbhalodia requested a review from ellatrix as a code owner August 15, 2024 05:15
Copy link

github-actions bot commented Aug 15, 2024

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: hbhalodia <hbhalodia@git.wordpress.org>
Co-authored-by: t-hamano <wildworks@git.wordpress.org>
Co-authored-by: mirka <0mirka00@git.wordpress.org>
Co-authored-by: ciampo <mciampini@git.wordpress.org>
Co-authored-by: tyxla <tyxla@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@shail-mehta shail-mehta added [Type] Enhancement A suggestion for improvement. [Package] Components /packages/components labels Aug 15, 2024
@t-hamano t-hamano linked an issue Aug 15, 2024 that may be closed by this pull request
@t-hamano t-hamano self-requested a review August 15, 2024 13:07
Copy link
Contributor

@t-hamano t-hamano 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 the PR!

It basically works fine, but there are a few things I think need to be addressed.

The labels are not aligned when placed next to a 40px item:

alignment

This is the effect of the padding here:

We can remove the following custom styles:

.block-editor-segmented-text-control__buttons {
// 4px of padding makes the row 40px high, same as an input.
padding: $grid-unit-05 0;
display: flex;
}
.components-button.has-icon {
margin-right: $grid-unit-05;
}

Additionally, if we just remove this style, the horizontal alignment of the 40px sized text field and button will not match:

image

This problem can be solved by adding __next40pxDefaultSize to the ToggleGroupControl component.

@hbhalodia
Copy link
Contributor Author

Thanks for the PR!

It basically works fine, but there are a few things I think need to be addressed.

The labels are not aligned when placed next to a 40px item:

alignment

This is the effect of the padding here:

We can remove the following custom styles:

.block-editor-segmented-text-control__buttons {
// 4px of padding makes the row 40px high, same as an input.
padding: $grid-unit-05 0;
display: flex;
}
.components-button.has-icon {
margin-right: $grid-unit-05;
}

Additionally, if we just remove this style, the horizontal alignment of the 40px sized text field and button will not match:

image

This problem can be solved by adding __next40pxDefaultSize to the ToggleGroupControl component.

Thanks @t-hamano, I would update the PR asap with the requested changes.

@t-hamano
Copy link
Contributor

While testing this PR, I noticed that when isDeselectable is true in the ToggleGroupControl component, the following behavior occurs:

  • Outline border doesn't appear when focused or hovered over
  • Focus is lost when pressing left or right arrow keys

I don't know if this is a bug or expected behavior, but I'll send a ping to the @WordPress/gutenberg-components team.

e34b1b640ceb395431711773de264e8e.mp4

@mirka
Copy link
Member

mirka commented Aug 15, 2024

While testing this PR, I noticed that when isDeselectable is true in the ToggleGroupControl component, the following behavior occurs:

Thanks for the ping! Yes, this is intended behavior. Enabling isDeselectable changes the underlying HTML from radio semantics to button semantics, so the keyboard navigation (and focus styling) changes accordingly.

Though there have been some discussions to change the visual design more substantially (#64439), so it would cause less confusion around it.

@mirka mirka requested a review from a team August 15, 2024 13:24
@hbhalodia hbhalodia requested a review from t-hamano August 15, 2024 13:35
@hbhalodia
Copy link
Contributor Author

Hi @t-hamano @mirka, The feedbacks have been addressed. Please take a look on the same.

Thank You,

/>
);
} ) }
</ToggleGroupControl>
</div>
</fieldset>
Copy link
Member

Choose a reason for hiding this comment

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

The ToggleGroupControl usage looks good, thank you!

However, the outer fieldset and div are now completely unnecessary, and this SegmentedTextControl component is also unnecessary, as consumers can just use ToggleGroupControl directly. There is nothing that this component adds on top of ToggleGroupControl itself.

Ideally, we would clean that up in this PR, but if you prefer, we can split out the refactoring work to a separate PR. At minimum, I think we should to remove the fieldset and div before landing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can update on this PR itself, let me know what suits better. I am open to both.

Thanks

Copy link
Contributor

@ciampo ciampo Aug 15, 2024

Choose a reason for hiding this comment

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

Probably better to have those updates as part of this PR, if you don't mind. Thank you 🙏

Copy link
Contributor

Choose a reason for hiding this comment

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

The SegmentedTextControl component is a wrapper component introduced in #60841 to make the same code common.

We should be able to simply replace the SegmentedTextControl component with the ToggleGroupControl component.
Also, since the SegmentControl component is not exposed, it is safe to delete it 👍

Copy link
Member

@mirka mirka Aug 15, 2024

Choose a reason for hiding this comment

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

And thank you @t-hamano for apparently having done the work (#60841) to consolidate all the instances into this unified component 🙏 I had assumed that they were all separate implementations as I had seen before, but pleasantly surprised to see that they were actually consolidated now 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi Team, apologies, I would be updating these feedbacks by tomorrow. ✨

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @mirka @t-hamano @ciampo, Have updated the PR with the requested changes.

Thank You,

@mirka
Copy link
Member

mirka commented Aug 15, 2024

Focus is lost when pressing left or right arrow keys

@t-hamano Sorry, I misinterpreted this part. Focus loss is indeed strange, and I can't repro on the major three browsers on Mac. Could it be a Windows thing? It's supposed to move through the options with Tab, but arrow keys shouldn't cause focus loss.

Or do you have some kind of special mode enabled? I noticed in your screen recording that the arrow key moved a text cursor into the label 😳 I've never seen that before.

Screenshot from posted repro video

@t-hamano
Copy link
Contributor

Or do you have some kind of special mode enabled? I noticed in your screen recording that the arrow key moved a text cursor into the label

After researching this problem, I found that it has to do with the "text cursor mode" of the Chrome browser:

Use a text cursor to navigate and select text - Google Accessibility Help

This means that we can move text with the left and right keys regardless of whether the element is focusable or not. I assumed that this behavior was the default behavior of the Windows OS, but it seems to be a Chrome-specific feature 😅

This feature can be disabled with the F7 key. So what I mentioned may not be a bug.

81445d75b947d5174259f4776daf8ab3.mp4

@mirka
Copy link
Member

mirka commented Aug 15, 2024

After researching this problem, I found that it has to do with the "text cursor mode" of the Chrome browser

Interesting 😳 Thanks for looking into it!

@hbhalodia hbhalodia requested review from mirka and ciampo August 16, 2024 04:11
Copy link
Member

@tyxla tyxla left a comment

Choose a reason for hiding this comment

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

I just gave this a round of testing, and it works/looks great!

Not much to add to the prior feedback, but I just wanted to thank you @hbhalodia for the great work utilizing the right @wordpress/components and cleaning up unnecessary deviation 🚀

@ciampo
Copy link
Contributor

ciampo commented Aug 16, 2024

I just wanted to thank you @hbhalodia for the great work

Absolutely! Thank you @hbhalodia for your great work. It would be great to continue the collaboration, in case you had more capacity!

Code is looking good on my end, but I'll let @t-hamano and @mirka give the final approval as they've been reviewing the PR from the start.

@hbhalodia
Copy link
Contributor Author

Thank You, @ciampo @tyxla ❤️.

It would be great to continue the collaboration, in case you had more capacity!

Sure, I would love to continue the collaboration 🚀.

Copy link
Member

@mirka mirka left a comment

Choose a reason for hiding this comment

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

Beautiful, thank you for the cleanup! 🚀

@mirka mirka merged commit c459a7b into WordPress:trunk Aug 16, 2024
64 checks passed
@mirka mirka removed the [Package] Components /packages/components label Aug 16, 2024
@t-hamano
Copy link
Contributor

@hbhalodia Thank you for your great work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Block editor /packages/block-editor [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Button groups in Typography tools should use ToggleGroupControl
6 participants