-
Notifications
You must be signed in to change notification settings - Fork 128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reset the state of the component and its inputs when a different props.value is passed in #155
base: master
Are you sure you want to change the base?
Conversation
changes also include upgrading the package-lock.json file for the latest version of npm (7.24.0)
there is a direct import from prop-types in ReactCodeInput.js
prevents this error after upgrade to storybook v5: webpack/webpack#8082
no more need to add sass loader manually by extending the webpack config
Array.prototype.map() won’t early return if you return true, but Array.prototype.some() will
also, fix naming typo from chart → char
cleans up the code where that variable is used and ensures the value being used is always a number (e.g. in the else condition of the ternary for determining the index within this.textInput when assigning newTarget)
• fixes 40818419#62 (reproducible in chrome and safari also) • removes need for special keydown handling for ↑/↓/E keys • removes need for styling to remove default input type="number" browser styles • leaves filtering of non-numeric values to existing logic in handleChange (works for pasted text and keyboard entry)
when using maxLength, if user has "623 293" and pastes it into an input with fields={6}, the last digit (“3”) won’t be pasted because the max length on the focused input is 6 digits
better to check that the rendered input is disabled rather than that state has { disabled: true }
Codecov Report
@@ Coverage Diff @@
## master #155 +/- ##
==========================================
+ Coverage 96.55% 96.99% +0.44%
==========================================
Files 2 2
Lines 145 133 -12
Branches 41 36 -5
==========================================
- Hits 140 129 -11
+ Misses 5 4 -1
Continue to review full report at Codecov.
|
also, remove empty string default for props.value to enable alternating between passing undefined and empty string as props.value to clear the component input values (because {value: undefined} no longer gets defaulted to empty string)
also, add getValueFromProps util to handle props.forceUppercase and null | undefined
…#129 makes it possible to reset ReactCodeInput’s internal state and the values it renders in its inputs by passing in an updated this.props.value
note that this branch was branched off of #154 and will be easier to review in isolation from those changes.
this PR simplifies component state handling and updates
state.value
andstate.input
whenprops.value
changes to enable resetting the component’s state as requested in #129 (also provides a better solution for #69). it also adds fallbacks and checks to work with props.value beingnull
orundefined
. these changes enable the following pattern, which i added as a new “With Reset” story to the docs:commits are atomic and explain in detail what changes are contained in the PR.