cloudscape-design / components

React components for Cloudscape Design System
https://cloudscape.design/
Apache License 2.0
2.34k stars 152 forks source link

[Bug]: Original onChange and all other events are being suppressed inside the Input component #1174

Closed afzaalahmad closed 1 year ago

afzaalahmad commented 1 year ago

Browser

Chrome, Safari, Firefox, Edge

Package version

v3.0.302

React version

v18

Description

I need original event from input onChange and onBlur and other events to modify the formatting of input but I don't have originalEvent available in onChange of Input component.

Source code

No response

Reproduction

No response

Code of Conduct

taheramr commented 1 year ago

Hello Afzaal,

This is not supported by our Input component, it would be great if you shared with us what is your use-case?

afzaalahmad commented 1 year ago

Hi @taheramr, I am using a hook called usePhoneInput from react-international-phone to format the phone. This library requires the original onChange input event as a parameter in handlePhoneChangeValue method coming from the hook.

image

Library owner is using preventDefault, inputType from event.nativeEvent, selectionStart from event.target and setSelectionRange from inputRef.

If we can export these, it'd be enough for my use-case. But my opinion is that originalEvent should be available.

afzaalahmad commented 1 year ago

@taheramr I can see that cloudscape team have suppressed events in onChange, onBlur and other event callbacks which doesn't make any sense to me because event callbacks are listeners and data flow is outward. Either I am missing something where you suggested that events can be misused and abused. But my point is that you are neither ejecting original events in events callback nor in inputRef. So, as a user, let's say that it is very critical for me to get the originalEvent for many other purposes. Now you've suppressed the events in the library but that doesn't mean that you can stop me as a user to get the event. I can use the very bad approach of getting the element using window.getElementById and put an addEventListener on it in useEffect. So, by wrapping up and suppressing the events, you are forcing a legit and good user to use sub-standard techniques and bad workarounds to get the task done.

IMO, whole orignal event should be available as a second argument in onChange, and onBlur.

taheramr commented 1 year ago

As of now we are not supporting the original event to be passed down through the onChange and onBlur events.

What I'm hearing from your request is that the external library is basically masking the input to handle phone input types.

If you want to render a Cloudscape-styled phone input, use your own styles with addition of our design tokens.

just-boris commented 1 year ago

The comment above contains our latest recommendation.

We have no plans of exposing native events through our API, because it would expose unwanted implementation details. No more actions on our end, resolving