axa-ch-webhub-cloud / pattern-library

AXA CH UI component library. Please share, comment, create issues and work with us!
https://axa-ch-webhub-cloud.github.io/plib-feature/develop
126 stars 18 forks source link

input-text react TS type for onChange now too restrictive #2381

Closed MarekLacoAXA closed 1 year ago

MarekLacoAXA commented 1 year ago

onChange prop type can be improved to better describe event argument.

 onChange?: (event: InputEvent, invalidFormat: Boolean) => void;

Problem: event: InputEvent is after recent change too restrictive: it's target is nullable and doesn't contain value attribute.

https://github.com/axa-ch-webhub-cloud/pattern-library/commit/942543d7a50862f55cfe243e05a50ad48e9841c5#diff-5fa5795977e2a41f9937c26c73663c24ae4770a2a4ecaab42e1835c87dfb6a48R29

MKaHead commented 1 year ago

Hi @MarekLacoAXA The best would if be provide a better type similar to React SyntheticEvent with it's generic.

For now you could cast the target to HTMLInputElement, or do like preact they have same Problem, see here.

MKaHead commented 1 year ago

@MarekLacoAXA Would that work for you, for the Start? export interface AXAChangeEvent<T = HTMLElement> extends InputEvent { target: EventTarget & T; }

MKaHead commented 1 year ago

You can import now AXAInputTextChangeEvent in newest release input-text@6.3.1

MarekLacoAXA commented 1 year ago

You can import now AXAInputTextChangeEvent in newest release input-text@6.3.1

Thanks Marco for providing solution so quickly! Works great!