Skip to content

Conversation

@dhananjaykuber
Copy link
Contributor

@dhananjaykuber dhananjaykuber commented Jun 23, 2025

Fixes

What?

This PR makes the label above the Archives block dropdown editable by introducing a TextControl field in the block’s settings panel.

Why?

Currently, when the Archives block is set to display as a dropdown, there is an option to show a label above it. However, this label is hardcoded as "Archives" and cannot be customized by the user.

How?

  1. Added a new label attribute to the block with a default value of "Archives":
"label": {
  "type": "string",
  "default": "Archives"
}
  1. Updated the edit function to include a TextControl UI component in the sidebar settings:
<TextControl
  __nextHasNoMarginBottom
  __next40pxDefaultSize
  label={ __( 'Label' ) }
  value={ label }
  onChange={ ( value ) => setAttributes( { label: value } ) }
  placeholder={ __( 'Archives' ) }
/>

Testing Instructions

  1. Open the post or page editor.
  2. Add the "Archives" block.
  3. In the block settings sidebar, enable "Display as dropdown".
  4. Enable "Show label".
  5. Confirm that a TextControl appears allowing you to edit the label.

Screenshots or screencast

Screenshot 2025-06-23 at 7 37 55 PM

Screenshot 2025-06-23 at 1 53 22 PM

@github-actions
Copy link

github-actions bot commented Jun 23, 2025

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: dhananjaykuber <dhananjaykuber@git.wordpress.org>
Co-authored-by: fabiankaegy <fabiankaegy@git.wordpress.org>
Co-authored-by: t-hamano <wildworks@git.wordpress.org>

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

Copy link
Member

Choose a reason for hiding this comment

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

These changes in this file seem unrelated to the PR 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed unrelated changes

Comment on lines 84 to 103
{ showLabel && (
<ToolsPanelItem
label={ __( 'Label' ) }
isShownByDefault
hasValue={ () => !! label }
onDeselect={ () =>
setAttributes( { label: '' } )
}
>
<TextControl
__nextHasNoMarginBottom
__next40pxDefaultSize
label={ __( 'Label' ) }
value={ label }
onChange={ ( value ) =>
setAttributes( { label: value } )
}
placeholder={ __( 'Archives' ) }
/>
</ToolsPanelItem>
Copy link
Member

Choose a reason for hiding this comment

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

Instead of having this control live in the Inspector I would much rather see the actual text label in the editor canvas use a RichText component to actually allow for inline editing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added RichText component in canvas

@fabiankaegy fabiankaegy added [Type] Enhancement A suggestion for improvement. [Block] Archives Affects the Archives Block labels Jun 23, 2025
},
"label": {
"type": "string",
"default": "Archives"
Copy link
Contributor

Choose a reason for hiding this comment

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

We cannot hard-code the default label here, as it is not translatable.

@dhananjaykuber
Copy link
Contributor Author

@fabiankaegy @t-hamano I've made the mentioned changes

@t-hamano
Copy link
Contributor

I've been researching this a bit more and have come across a few things to note.

@dhananjaykuber
Copy link
Contributor Author

I've been researching this a bit more and have come across a few things to note.

Yes @t-hamano, I'll work on converting this block to dynamic block.

@t-hamano
Copy link
Contributor

I'll work on converting this block to dynamic block.

It would be great if we could refactor it to just JS rendering. However, this might be technically quite difficult, as all of the logic in the wp_get_archives() function would have to be implemented in JS. The wp_get_archives() function contains hard-coded SQL statements.

Personally, I would like to propose thoroughly discussing the direction and approach in #57528.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Block] Archives Affects the Archives Block [Type] Enhancement A suggestion for improvement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants