soywod / react-pin-field

📟 React component for entering PIN codes.
https://soywod.github.io/react-pin-field/
MIT License
412 stars 24 forks source link

[bug] Reactive props update the web component root, not to the child inputs. #44

Closed devjoseluis closed 2 years ago

devjoseluis commented 3 years ago

Description

On the initial render of ReactPinField, the props passed are transmitted to the child inputs and removed from the root element, but when the props value gets updated, the root element gets synced, but the child inputs do not.

Expected Behavior

The props should be synced to the child inputs and removed from the root element.

Actual Behavior

The props updates only apply to the root element.

Possible Fix

Maybe listen for the props changes in the attributeChangedCallback of the https://github.com/soywod/pin-field web component: https://github.com/soywod/pin-field/blob/d398dc287c606fe4eefd57a5c79abc439cc9c092/src/index.ts#L124

And do something like in the connectedCallback, pass the props to the child inputs and remove them from the root element: https://github.com/soywod/pin-field/blob/d398dc287c606fe4eefd57a5c79abc439cc9c092/src/index.ts#L155-L162.

Steps to Reproduce

  1. Add a dynamic prop to the ReactPinField component. (ex. className={someDynamicState}).
  2. Update the dynamic prop value.
  3. The prop is updated in the <swd-pin-field> component.
  4. The prop isn't transmitted to the child inputs.

The demo in the repository shows the bug: https://github.com/soywod/react-pin-field/blob/133b5a5ed4de523f9572117229e80989eed65aa4/src/demo/index.tsx#L51-L53

Screen Recording

Environment

soywod commented 2 years ago

The native web component was a big mistake, it led to so many issues… I ended up rolling back to v1 state, without web component (pure React implementation). The issue should be fixed starting from the v3.0.11.