Comments (4)
I've debugged a little and in the InputNumber OnInputKeyDown function switch statement's default case:
default:
event.preventDefault();
let char = event.key;
console.log(event)
if (char) {
const _isDecimalSign = isDecimalSign(char);
const _isMinusSign = isMinusSign(char);
if ((event.code && (event.code.startsWith('Digit') || event.code.startsWith('Numpad')) && Number(char) >= 0 && Number(char) <= 9) || _isMinusSign || _isDecimalSign) {
insert(event, char, { isDecimalSign: _isDecimalSign, isMinusSign: _isMinusSign });
}
}
break;
The event.code is checked if it starts with 'Digit', this is problematic because for me when I press zero the event.code = "Backquote", so the condition will fail. In previous builds this wasn't a problem because not the event.code was checked but instead the event.keyCode which should be preferred.
Proposed solution:
default:
event.preventDefault();
let char = event.key;
console.log(event)
if (char) {
const _isDecimalSign = isDecimalSign(char);
const _isMinusSign = isMinusSign(char);
const isDigit = event.keyCode >= 48 && event.keyCode <= 57;
const isNumpadDigit = event.keyCode >= 96 && event.keyCode <= 105;
if ((event.code && (isDigit || isNumpadDigit) && Number(char) >= 0 && Number(char) <= 9) || _isMinusSign || _isDecimalSign) {
insert(event, char, { isDecimalSign: _isDecimalSign, isMinusSign: _isMinusSign });
}
}
break;
from primereact.
Just read that the keyCode property is deprecated (https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keyCode), so instead I think the best solution is to just omit the (event.code.startsWith('Digit') || event.code.startsWith('Numpad'))
part from the condition as I don't see if it adds any value, the Number(char) >= 0 && Number(char) <= 9)
part already checking if it's a number. I tested it and it seems to work fine now and I can write '0'.
from primereact.
@fufupati please submit a PR. IT looks like that is what PrimeVue is doing: https://github.com/primefaces/primevue/blob/401dd225677796f05321b0c98ac68b51f3487de6/components/lib/inputnumber/InputNumber.vue#L547C13-L549C14
from primereact.
I submitted a PR
from primereact.
Related Issues (20)
- Stepper: Unstyled mode preview HOT 1
- InputNumber: Incorrect default value for minFractionDigits when set to null
- Toast: Becomes unstyled on mouse hover
- InputOtp: Type not Working with Sample Template HOT 1
- Tree: Dragging tree nodes that do not have a dragdropScope explicitly set cause lowercase conversion for checks to fail. HOT 1
- DataTable: Subheader row group with sorting
- A TypeError is encountered when attempting to collapse any row after using the “Expand All” button in a table with expanded rows and row group mode
- Dialog: Add defaultVisible property HOT 13
- DataTable: Empty "globalFilter" doesn't trigger onFilter on lazy mode HOT 3
- TabView scrollable previousButton vs prevButton
- Password: iconField pt not passing through
- DataTable: width is not working for column and event onColumnResizeEnd don't fire on reduce size of column HOT 15
- TreeSelect is missing onNodeClick and onNodeDoubleClick callbacks HOT 1
- DataTable: Multiple column sort does not work with lazy loading HOT 7
- Issue with Data Table Editable Cells and Single Selection Mode
- Calendar: Manual Typing doesn't update the year on the top
- DataTable Passthrough: rowExpansion className not set in DOM HOT 1
- Dropdown: visual glitch
- Toast and message onRemove argument is not a ToastMessage type when it has _pId HOT 8
- InputMask: Can't escape character '9' HOT 1
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 primereact.