Giter Club home page Giter Club logo

Comments (4)

fufupati avatar fufupati commented on August 15, 2024

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.

fufupati avatar fufupati commented on August 15, 2024

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.

melloware avatar melloware commented on August 15, 2024

@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.

melloware avatar melloware commented on August 15, 2024

I submitted a PR

from primereact.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.