Summary
The onClick prop typing for the Button component is missing the MouseEvent
Expected behavior
The onClick prop's type definition should include React.MouseEvent<HTMLButtonElement> as an argument to the callback function. This is standard and expected behavior for event handlers in React.
The expected type should be: onClick?: (event: React.MouseEvent<HTMLButtonElement>) => void;.
Actual behavior
Currently, the type definition for the onClick prop on the Button component does not provide the MouseEvent object to the handler function. The type is likely defined as onClick?: () => unknown;.
This prevents developers from accessing standard event properties and methods like event.preventDefault(), event.stopPropagation(), or `
`.
Steps to reproduce
Link to sandbox
- Instantiate a
Button component in a TypeScript project.
- Pass a handler function to the
onClick prop.
- Attempt to access the
event object within the handler.
- TypeScript will throw an error because the
event parameter is not defined in the function's signature.
Are you using React components?
Yes
Polaris version number
^13.5.0
Browser
Chrome Version 139.0.7258.128
Device
Macbook Air M2
Summary
The
onClickprop typing for theButtoncomponent is missing theMouseEventExpected behavior
The
onClickprop's type definition should includeReact.MouseEvent<HTMLButtonElement>as an argument to the callback function. This is standard and expected behavior for event handlers in React.The expected type should be:
onClick?: (event: React.MouseEvent<HTMLButtonElement>) => void;.Actual behavior
Currently, the type definition for the
onClickprop on theButtoncomponent does not provide theMouseEventobject to the handler function. The type is likely defined asonClick?: () => unknown;.This prevents developers from accessing standard event properties and methods like
event.preventDefault(),event.stopPropagation(), or ``.
Steps to reproduce
Link to sandbox
Buttoncomponent in a TypeScript project.onClickprop.eventobject within the handler.eventparameter is not defined in the function's signature.Are you using React components?
Yes
Polaris version number
^13.5.0
Browser
Chrome Version 139.0.7258.128
Device
Macbook Air M2