Toast action supports forwarding actionProps to the underlying button (WEB-1181)
Version: 0.6.7 · Type: ✨ Feature
Problem
ToastActionConfig (a public type, re-exported from Toast.tsx) previously only accepted { label, onClick }, and the action button's variant / size were hardcoded inside ToastItem. Callers — for example AI Feedback toasts — could not customize the action button (custom variant, aria-label, data-testid, etc.).
Changed Files
packages/design/src/components/Toast/toast-manager.tspackages/design/src/components/Toast/ToastItem.tsxpackages/design/src/components/Toast/__tests__/Toast.test.tsx
Changes
- Added an optional
actionPropsfield toToastActionConfig, forwarded onto the underlyingButton:- Type:
Omit<ButtonProps, 'children' | 'onClick'> & { [key: `data-${string}`]: string | number | boolean | undefined }; thedata-*index signature follows the existing DialogokButtonPropsconvention. - Excludes
children(carried bylabel) andonClick(composed by Toast asonClick+ auto-close, and therefore not overridable).
- Type:
- In
ToastItem'srenderActionButton,{...config.actionProps}is spread after the defaultvariant/size(so callers can override them) but before the composedonClick(so the click + auto-close behavior can never be overridden). - Unit test: an
aiFeedbacktoast overrides the action tovariant="primary"+data-testidviaactionProps, asserting the class is applied andonClickstill fires.
Usage
toast.aiFeedback('...', {
action: {
label: 'Regenerate',
onClick: handleRegenerate,
actionProps: { variant: 'primary', 'aria-label': 'Regenerate', 'data-testid': 'ai-regenerate' },
},
});