prateekbh / preact-material-components

preact wrapper for "Material Components for the web"
https://material.preactjs.com
MIT License
553 stars 81 forks source link

Standard API for major event handlers in 2.0 #1293

Open prateekbh opened 5 years ago

prateekbh commented 5 years ago

While we're writing components for 2.0, we should standardize the API got event handlers.

Currently with props all event handlers are native event handlers. E.g: onChange of a checkbox is the native onChange of input type=checkbox This leads to some problems, mdc-web introduce some additional properties on top of native controls. E.g. checkbox has a indeterminate state, select has selectedIndex etc.

Getting these values from native event handlers which just pass the Event, is tricky and most times requires creating a ref.

In order to solve this we can send added details to major event handlers(not necessarily all) like onChange for checkbox, select, onClick for button etc.

Current TS definition:

onClick: (e:Event) => void;

Updated version:

onChange:(e:Event, object: {
  MDComponent: MaterialComponent;
  checked: boolean;
  indeterminate: boolean;
}) => void

The additional object makes sure that it is not counter intuitive to users if 1.0

cromefire commented 5 years ago

There currently carnival were I am, so I'm not available today

cromefire commented 5 years ago

But that's a good idea

prateekbh commented 5 years ago

No worries... It isn't something to be fixed immediately. That's just something we confirm to as we update all the components.. Enjoy the carnival ☺️

cromefire commented 5 years ago

I guess this is done is'nt it?

prateekbh commented 5 years ago

Tabs are remaining. 1 last one i guess

cromefire commented 5 years ago

Possible