Skip to content

Notices: Type NoticeAction.onClick as a mouse event handler - #81859

Open
swissspidy wants to merge 2 commits into
trunkfrom
claude/gutenberg-patches-upstream-ypl8i9-notices
Open

Notices: Type NoticeAction.onClick as a mouse event handler#81859
swissspidy wants to merge 2 commits into
trunkfrom
claude/gutenberg-patches-upstream-ypl8i9-notices

Conversation

@swissspidy

Copy link
Copy Markdown
Member

What?

Types NoticeAction.onClick in @wordpress/notices as MouseEventHandler< HTMLAnchorElement | HTMLButtonElement > instead of VoidFunction, and documents that url takes precedence over onClick.

Why?

A notice action's callback is handed straight to a Button, so React calls it with the click event:

// packages/components/src/notice/index.tsx
<Button href={ url } onClick={ onClick }  />

@wordpress/components has always described its own NoticeAction.onClick as a mouse event handler. The store's copy of the type declared it as VoidFunction, so a handler that reads the event failed to type check even though the event is there at runtime:

createNotice( 'info', 'Saved', {
	actions: [
		{
			label: 'Undo',
			// Type '(event: MouseEvent<…>) => void' is not assignable to type 'VoidFunction'.
			onClick: ( event ) => {  },
		},
	],
} );

The precedence note mirrors what NoticeProps in @wordpress/components already documents: when both url and onClick are provided, url wins and the action renders as an anchor.

How?

One type widened in packages/notices/src/store/types.ts, plus a doc comment. @wordpress/notices already depends on @wordpress/components and already imports React types elsewhere, so the react type import adds no new dependency. No runtime change.

Note this only widens what callers may pass; the existing narrower handlers stay assignable, and the store's Notice type remains assignable to what NoticeList expects.

Testing Instructions

  1. npm run typecheck passes.
  2. npx wp-scripts test-unit-js --config test/unit/jest.config.js packages/notices passes.

Testing Instructions for Keyboard

N/A — no user interface changes.

Use of AI Tools

This pull request was authored by Claude Code (Opus) under my direction and review. I reviewed the diff and confirmed the type check and unit tests locally before opening it. I take responsibility for the change.


Generated by Claude Code

A notice action's callback is handed to a `Button`, so React calls it
with the click event. The type declared it as `VoidFunction`, so a
handler that reads the event failed to type check even though the
`Notice` component's own action type has always described it as a mouse
event handler.

Also note on `url` that it takes precedence over `onClick`, matching what
the component documents.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EQTrVy89daPN74LMo9FKNN
Copilot AI balanced review requested due to automatic review settings August 20, 2026 08:24
@swissspidy
swissspidy requested a review from ajitbohra as a code owner August 20, 2026 08:24

Copilot AI left a comment

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions github-actions Bot added the [Package] Notices /packages/notices label Aug 20, 2026
@github-actions

Copy link
Copy Markdown

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.

Unlinked Accounts

The following contributors have not linked their GitHub and WordPress.org accounts: @claude.

Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases.

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

Unlinked contributors: claude.


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

@swissspidy swissspidy added the [Type] Code Quality Issues or PRs that relate to code quality label Aug 20, 2026
@github-actions

Copy link
Copy Markdown

Size Change: 0 B

Total Size: 7.74 MB

compressed-size-action

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

Labels

[Package] Notices /packages/notices [Type] Code Quality Issues or PRs that relate to code quality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants