gutenberg icon indicating copy to clipboard operation
gutenberg copied to clipboard

Avatar: Refactor settings panel to use ToolsPanel

Open Infinite-Null opened this issue 1 year ago • 7 comments

Part of: https://github.com/WordPress/gutenberg/issues/67813

What?

Refactored Avatar Block code to include ToolsPanel instead of PanelBody.

Screenshots:

Before After
image image

Infinite-Null avatar Dec 13 '24 07:12 Infinite-Null

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: Infinite-Null <[email protected]>
Co-authored-by: t-hamano <[email protected]>
Co-authored-by: Mamaduka <[email protected]>
Co-authored-by: fabiankaegy <[email protected]>

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

github-actions[bot] avatar Dec 16 '24 05:12 github-actions[bot]

Hi, @Infinite-Null

Do you have time to follow up on this PR?

Mamaduka avatar May 28 '25 15:05 Mamaduka

Sure @Mamaduka

Infinite-Null avatar May 28 '25 15:05 Infinite-Null

Hi @Mamaduka and @t-hamano , I’ve made the necessary changes and moved the conditional addition of settings to the very end so that it matches the expected order. Please let me know if there’s anything else I should update!

image

Infinite-Null avatar May 30 '25 15:05 Infinite-Null

moved the conditional addition of settings to the very end so that it matches the expected order.

I don't think this is an ideal solution. This may be a problem that should be fixed on the ToolsPanel component side.

For now, I personally prefer to accept this issue and prioritize the migration to the TooslPanel component. See https://github.com/WordPress/gutenberg/issues/67813#issuecomment-2907556825

@Mamaduka @fabiankaegy What do you think?

t-hamano avatar May 31 '25 08:05 t-hamano

Sure @t-hamano, I have reverted my refactor changes 😄

Infinite-Null avatar Jun 02 '25 07:06 Infinite-Null

Sure @t-hamano 🎉

Infinite-Null avatar Jun 02 '25 07:06 Infinite-Null

For now, I personally prefer to accept this issue and prioritize the migration to the TooslPanel component

Makes sense. Retaining correct ordering is a general SlotFill issue.

Mamaduka avatar Jun 12 '25 11:06 Mamaduka

A small interesting observation regarding ComboboxControl. I noticed that resetting the userId value to undefined doesn't clear out the combobox selection. It works if I change the reset value to null.

This could be an intentional side-effect or a bug. I think it's worth investigating separately, if we can reproduce the same problem in isolation. cc @WordPress/gutenberg-components

Screencast

https://github.com/user-attachments/assets/0ae33c71-6487-40b6-86b7-eec4abf56a98

Mamaduka avatar Jun 12 '25 12:06 Mamaduka

@Mamaduka I'd have to look deeper into the code to let you know whether this is working as intended or a bug — but, at least philosophically, it does follow the controlled/uncontrolled pattern that we've implementing rencently on some component: when a component is controlled, "no value" should be expressed with null (and not undefined).

ciampo avatar Jun 24 '25 17:06 ciampo

it does follow the controlled/uncontrolled pattern that we've implementing rencently on some component: when a component is controlled, "no value" should be expressed with null (and not undefined).

After looking into this, it seems like this is indeed intentional behavior.

The ComboboxControl component uses the useControlledValue hook internally. In the useControlledValue hook, if the value is undefined, it is considered to be in an "uncontrolled state":

https://github.com/WordPress/gutenberg/blob/386df007aa1bf7bee05584d4cb1c45a32ece0d68/packages/components/src/utils/hooks/use-controlled-value.ts#L26

Related PRs:

  • https://github.com/WordPress/gutenberg/pull/33039
  • https://github.com/WordPress/gutenberg/pull/42403

t-hamano avatar Jun 25 '25 01:06 t-hamano

That makes sense, thank you both for the feedback.

Mamaduka avatar Jun 25 '25 05:06 Mamaduka