Skip to content

Commit 4892f02

Browse files
fix: type fix for onActionButtonClick in Notification component #19986 (#20262)
* fix: type fix for onActionButtonClick in Notification component #19986 * fix: type fix for onActionButtonClick in Notification component #19986 * fix: type fix for onActionButtonClick in Notification component #19986 * fix: prop type in the source components to keep a single source of truth
1 parent 17cfa17 commit 4892f02

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

packages/react/src/components/Notification/Notification.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import React, {
1414
useEffect,
1515
useRef,
1616
useState,
17+
type ComponentProps,
1718
} from 'react';
1819
import { deprecate } from '../../prop-types/deprecate';
1920
import cx from 'classnames';
@@ -89,7 +90,7 @@ export interface NotificationActionButtonProps extends ButtonProps<'button'> {
8990
/**
9091
* Optionally specify a click handler for the notification action button.
9192
*/
92-
onClick?(): void;
93+
onClick?: ComponentProps<typeof Button>['onClick'];
9394
}
9495

9596
export function NotificationActionButton({
@@ -882,7 +883,9 @@ export interface ActionableNotificationProps
882883
/**
883884
* Provide a function that is called when the action is clicked
884885
*/
885-
onActionButtonClick?(): void;
886+
onActionButtonClick?: ComponentProps<
887+
typeof NotificationActionButton
888+
>['onClick'];
886889

887890
/**
888891
* Provide a function that is called when menu is closed.
@@ -1287,7 +1290,9 @@ export interface CalloutProps extends HTMLAttributes<HTMLDivElement> {
12871290
/**
12881291
* Provide a function that is called when the action is clicked
12891292
*/
1290-
onActionButtonClick?(): void;
1293+
onActionButtonClick?: ComponentProps<
1294+
typeof NotificationActionButton
1295+
>['onClick'];
12911296

12921297
/**
12931298
* Provide a description for "status" icon that can be read by screen readers

packages/react/src/components/Notification/__tests__/Notification-test.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright IBM Corp. 2016, 2023
2+
* Copyright IBM Corp. 2016, 2025
33
*
44
* This source code is licensed under the Apache-2.0 license found in the
55
* LICENSE file in the root directory of this source tree.
@@ -397,6 +397,9 @@ describe('Callout', () => {
397397
});
398398
await userEvent.click(closeButton);
399399
expect(onActionButtonClick).toHaveBeenCalledTimes(1);
400+
expect(onActionButtonClick.mock.calls).toEqual([
401+
[expect.objectContaining({ type: 'click' })],
402+
]);
400403
});
401404

402405
it('interpolates matching className based on kind prop', () => {

packages/react/src/components/Notification/stories/ActionableNotification.stories.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright IBM Corp. 2016, 2023
2+
* Copyright IBM Corp. 2016, 2025
33
*
44
* This source code is licensed under the Apache-2.0 license found in the
55
* LICENSE file in the root directory of this source tree.
@@ -27,6 +27,7 @@ export default {
2727
statusIconDescription: 'notification',
2828
onClose: action('onClose'),
2929
onCloseButtonClick: action('onCloseButtonClick'),
30+
onActionButtonClick: action('onActionButtonClick'),
3031
},
3132
};
3233

0 commit comments

Comments
 (0)