preact-material-components icon indicating copy to clipboard operation
preact-material-components copied to clipboard

Standard API for major event handlers in 2.0

Open prateekbh opened this issue 6 years ago • 6 comments

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

prateekbh avatar Mar 04 '19 07:03 prateekbh

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

cromefire avatar Mar 04 '19 08:03 cromefire

But that's a good idea

cromefire avatar Mar 04 '19 08:03 cromefire

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 ☺️

prateekbh avatar Mar 04 '19 16:03 prateekbh

I guess this is done is'nt it?

cromefire avatar Jul 18 '19 15:07 cromefire

Tabs are remaining. 1 last one i guess

prateekbh avatar Jul 18 '19 16:07 prateekbh

Possible

cromefire avatar Jul 18 '19 16:07 cromefire