Comments (5)
Or alternatively, you could include your own useEffect hook to detect changes to initial value, which would probably be more optimal.
from react-pin-input.
For anyone else that needs to do something like this, after reviewing the source code, this is the solution I came up with:
React.useEffect(() => {
if(ref && ref?.current){
const valueArr = (value || '').toString().split('');
// No changes necessary, short circuit.
if(isEqual(valueArr, ref.current.values))
return;
// Iterate over each digit updating from valueArray item
for(let i = 0; i < ref.current.elements.length; i++){
ref.current.elements[i].update(valueArr[i] || '', true);
}
}
},[value])
Not sure if its what the maintainer would have recommended, but it works for me.
from react-pin-input.
@aintHuman Thank you for the suggestion and solution. Will look into this.
from react-pin-input.
Also, can you expose the onFocus / onBlur callbacks as arguments in the constructor (which get passed down to each PinItem, and called after your own internal usage), so that I can detect from my parent component, when an individual field has been entered / left.
I need this for a touchpad where there is no keyboard and therefore need to have a up/down button to step the value up / down, or make a keypad to enter the values by touch.
from react-pin-input.
@aintHuman Sure. Will consider.
from react-pin-input.
Related Issues (20)
- Disabled is missing from PinInput interface
- Placeholder for inputs HOT 6
- input type when use secret
- Changing input length does not re-render the component with new input length HOT 3
- Issue understanding how to clear PinInput fields after invalid attempt HOT 1
- Can you update react into [email protected] ? HOT 1
- ReferenceError: window is not defined after update to 1.1.0 version HOT 3
- PinInput cannot be used as JSX element HOT 2
- autoComplete={'off'} in <input> is ignored HOT 2
- Detect enter keypress HOT 2
- Add manual attributes to Pin Input HOT 1
- Cant loose Focus programatically
- Cannot be used as a JSX component HOT 3
- Unable to use asterisk (*) in place of dots(.)
- Update sandbox example with latest version of react-pin-input HOT 2
- 在鸿蒙系统下显示不正常是什么原因? HOT 1
- Unable to manipulate CSS/styling for the placeholder HOT 1
- From Messages paste only pasting the first number HOT 1
- Transform to functional component HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-pin-input.