Skip to content

[Button] Bug: The onClick prop typing for the Button component is missing the MouseEvent #13999

@SomeBrujah

Description

@SomeBrujah

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 `

Image

`.

Steps to reproduce

Link to sandbox

  1. Instantiate a Button component in a TypeScript project.
  2. Pass a handler function to the onClick prop.
  3. Attempt to access the event object within the handler.
  4. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugSomething is broken and not working as intended in the system.untriaged

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions