jpmorganchase / salt-ds

React UI components built with a focus on accessibility, customization and ease-of-use
https://www.saltdesignsystem.com
Apache License 2.0
129 stars 91 forks source link

Make useButton work for non-button html elements #1964

Open ZarkoPernar opened 1 year ago

ZarkoPernar commented 1 year ago

Package name(s)

Core (@salt-ds/core)

Package version(s)

All

Description

It seems like useButton was primarily made to work for the native button html element. While making a div in to a button with useButton I encountered several issues that need to be addressed:

Steps to reproduce

function DivButton({disabled}) {
  const {buttonProps, active} = useButton({
    disabled,
    onClick: () => console.log("clicked"),
  });

  console.log({active})

  return <div {...buttonProps}>Fake Button</div>
}

Expected behavior

We should add a feature flag, or an elementType?: string option to useButton like react-aria does in order to change some of the default behaviours like the disabled/aria-disabled. Others should be simply patched.

Operating system

Browser

Are you a JPMorgan Chase & Co. employee?

james-nash commented 1 year ago

What's your use-case for faking a button with a div?

ZarkoPernar commented 1 year ago

@james-nash nested buttons are one example but there are other cases where you have complex layouts in a clickable element, there the native button won't suffice.