Skip to content

Conversation

@manzoorwanijk
Copy link
Member

@manzoorwanijk manzoorwanijk commented Dec 18, 2025

Related to #74090

What?

Enhances the Notice component's action buttons to support additional Button component features.

Why?

Notice action buttons were missing common Button features like disabled, etc. The openInNewTab prop existed in types but wasn't implemented, and onClick was ignored when url was provided.

How?

  • Updated NoticeAction types to allow disabled and onClick alongside url
  • Remove openInNewTab from the types.

Testing Instructions

  1. Check out this branch
  2. Run npm run storybook:dev
  3. Navigate to Components > Feedback > Notice
  4. Test the new stories:
    • ** With Disabled Action**: Verify the disabled button cannot be clicked
    • ** With Open In New Tab**: Verify link opens in new tab

Testing Instructions for Keyboard

  • Tab to action buttons and verify they receive focus
  • Press Enter/Space to activate buttons
  • Disabled buttons should still be focusable via keyboard

Screenshots

Screenshot 2025-12-18 at 2 59 46 PM Screenshot 2025-12-28 at 11 59 16 AM

@manzoorwanijk manzoorwanijk self-assigned this Dec 18, 2025
@manzoorwanijk manzoorwanijk added [Type] Enhancement A suggestion for improvement. [Package] Components /packages/components labels Dec 18, 2025
@github-actions
Copy link

github-actions bot commented Dec 18, 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: manzoorwanijk <[email protected]>
Co-authored-by: gmjuhasz <[email protected]>
Co-authored-by: aduth <[email protected]>
Co-authored-by: mirka <[email protected]>
Co-authored-by: SirLouen <[email protected]>
Co-authored-by: Mamaduka <[email protected]>
Co-authored-by: t-hamano <[email protected]>
Co-authored-by: ciampo <[email protected]>

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

@Mamaduka
Copy link
Member

I wonder if some of this was intentional to keep UI more or less consistent.

@manzoorwanijk
Copy link
Member Author

I wonder if some of this was intentional to keep UI more or less consistent.

Actions were added 7 years ago by @aduth and @gziolo and I couldn't find any mention of any intentions there, except this for future enhancements:

Most of our existing use of elements could be better served by a formal "actions" option (e.g., "View Post" on the save success) which is more future-compatible to notices design revisions.

As mentioned and explained in the linked issue, actions for those notices need to be versatile, it makes it hard to use them for real-world cases.

@manzoorwanijk manzoorwanijk requested a review from gziolo December 18, 2025 09:59
Copy link

@gmjuhasz gmjuhasz left a comment

Choose a reason for hiding this comment

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

Coming from Jetpack I also did find this Notice component lacking this functionality before, we even had our own Notice component to battle this. I think these changes still keep it simple, but a lot more versatile.

@github-actions
Copy link

github-actions bot commented Dec 18, 2025

Flaky tests detected in c71acc2.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/20552994612
📝 Reported issues:

@manzoorwanijk manzoorwanijk requested a review from aduth December 19, 2025 05:58
@t-hamano
Copy link
Contributor

t-hamano commented Dec 20, 2025

If you want to build a completely free UI, you can render it via the children prop:

<Notice status="info">
	<Flex justify="start" wrap>
		<Button variant="primary">Push Me</Button>
		<Button variant="primary" disabled>Push Me</Button>
		<Button variant="primary" isBusy>Push Me</Button>
		<Button variant="primary" size="small">Push Me</Button>
	</Flex>
</Notice>

I wonder if there is anything that can't be achieved without extending the actions property 🤔

@manzoorwanijk
Copy link
Member Author

If you want to build a completely free UI, you can render it via the children prop:

Yes, we can do that but having the actual component fixed is probably better and has no harm.

In future, I would expect the actions to be completely flexible by making them composable by directly rendering { actions } instead of looping through them.

@ciampo
Copy link
Contributor

ciampo commented Dec 22, 2025

Left some thoughts in #74090 (comment)

Comment on lines +59 to +62
actions?: Array<
Pick< NoticeAction, 'label' | 'url' | 'onClick' > & {
openInNewTab?: boolean;
}
Copy link
Member

Choose a reason for hiding this comment

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

Ugh I'm conflicted about this API divergence between Snackbar and Notice now. Snackbar added the feature through a openInNewTab prop, and swaps the Button for an ExternalLink in that case (#69905).

Actually I think that might be preferable to supporting rel and target directly, because one of the guidelines of the design system is to have consistent cues (visual and accessible) on links that open new tabs. ExternalLink has those cues, while Button does not.

The problem is that Snackbar only has to support variant="link" buttons, while Notice actions have a wider API surface that conflicts with ExternalLink, so the TypeScript/documentation complexity is probably not worth the trouble to make it work polymorphically.

This alone may be a good reason to support components directly in actions, for the @wordpress/ui version of Notice.

Sorry @manzoorwanijk, this aspect was a bit more complicated that expected. We can probably merge this PR faster if we punt this rel/target forwarding part out of scope 😅 (The type fix here for openInNewTab where you moved it out from Notice and into Snackbar is good though.)

Copy link
Member Author

Choose a reason for hiding this comment

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

The issue here was that openInNewTab was only defined in the type but not implemented. So, it was unused anyway.

So, I replaced it with target and rel to have better control.

As you rightly said, here we have to support different variants and thus it makes more sense to have it this way.

Copy link
Member

Choose a reason for hiding this comment

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

The problem is that:

  • We don't really want to allow tab-opening links without the visual/accessible cues like ExternalLink has.
  • It's not good that Snackbar actions and Notice actions have different APIs to achieve the same thing.

We can solve these cleanly in a new API in @wordpress/ui, but it's hard to do this in @wordpress/components.

Copy link
Member Author

@manzoorwanijk manzoorwanijk Dec 27, 2025

Choose a reason for hiding this comment

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

So what do we want to do here? Maybe we can close this PR, live with what we have for now, and hope to resolve the issues in @wordpress/ui?

Copy link
Member

@SirLouen SirLouen Dec 27, 2025

Choose a reason for hiding this comment

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

It's not good that Snackbar actions and Notice actions have different APIs to achieve the same thing.

Why not replicate then? It shouldn't be too difficult. Maybe something like the Cover Block cover/shared.js could work here?

Copy link
Member

Choose a reason for hiding this comment

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

Like Marco said in #74090 (comment), "quick wins and fixes" are fine, but we don't want to introduce new features that add maintenance/migration cost to these soon-to-be-deprecated componentry.

The onClick and disabled are quick fixes, but openInNewTab turned out to be on the level of a "new feature" that does indeed add to the future cost. So I'd prefer we remove the openInNewTab feature from the scope of this PR, given that we can support it cleaner in the new @wordpress/ui package.

Copy link
Member Author

Choose a reason for hiding this comment

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

openInNewTab was already defined there (in types) before this PR but was not implemented.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, it's messed up but let's leave it as is, unimplemented. I haven't looked into whether the types can be corrected easily so a Notice action won't accept an onInNewTab property, but that doesn't have to be done in this PR if it isn't simple.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done. Thanks.

Copy link
Member Author

@manzoorwanijk manzoorwanijk Dec 31, 2025

Choose a reason for hiding this comment

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

The types for Notice are now clean and straightforward.

@SirLouen
Copy link
Member

So what do we want to do here? Maybe we can close this PR, live with what we have for now, and hope to resolve the issues in @wordpress/ui?

@manzoorwanijk my conclusion reading through the whole convo is the following: limit the scope of this PR, by removing the open in new tab elements (alas, we missed rel & target). You will be able to push at least something in this PR, but not entirely.

Replaces the 'target' and 'rel' props with a boolean 'openInNewTab' prop for Notice action buttons, which, if true, forces to render the ExternalLink
@manzoorwanijk manzoorwanijk requested review from aduth and mirka December 28, 2025 06:37
@manzoorwanijk manzoorwanijk changed the title Components: Enhance Notice actios with missing Button props Components: Enhance Notice actions to allow more props like disabled and openInNewTab Dec 28, 2025
@manzoorwanijk
Copy link
Member Author

I have updated the PR (along with the description) to reduce the scope to do only three things:

  • Allow disabled prop for buttons.
  • Allow onClick alongside url.
  • Wire up openInNewTab to render ExternalLink when it's true.

@SirLouen
Copy link
Member

SirLouen commented Dec 29, 2025

I have updated the PR (along with the description) to reduce the scope to do only three things:

  • Allow disabled prop for buttons.
  • Allow onClick alongside url.
  • Wire up openInNewTab to render ExternalLink when it's true.

👍 Looking better to me, I would like to test a bit, but want to see what others think now.

@SirLouen SirLouen added the Needs Testing Needs further testing to be confirmed. label Dec 29, 2025
@mirka
Copy link
Member

mirka commented Dec 30, 2025

I'm afraid I can't enthusiastically greenlight the openInNewTab part, but everything else is good on my end.

@manzoorwanijk manzoorwanijk changed the title Components: Enhance Notice actions to allow more props like disabled and openInNewTab Components: Enhance Notice actions to allow more props like disabled and onClick with url Dec 31, 2025
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.

Looks good, thanks for your patience here 🙏

@manzoorwanijk manzoorwanijk enabled auto-merge (squash) December 31, 2025 12:10
@manzoorwanijk manzoorwanijk merged commit f12350d into trunk Dec 31, 2025
39 checks passed
@manzoorwanijk manzoorwanijk deleted the enhance/notice-component-actions branch December 31, 2025 12:21
@github-actions github-actions bot added this to the Gutenberg 22.4 milestone Dec 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs Testing Needs further testing to be confirmed. [Package] Components /packages/components [Type] Enhancement A suggestion for improvement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants