Skip to content
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

[Issue]: How to format number in NumberInput #922

Open
alamenai opened this issue Jan 22, 2024 · 6 comments
Open

[Issue]: How to format number in NumberInput #922

alamenai opened this issue Jan 22, 2024 · 6 comments
Assignees
Labels
Type: Enhancement Small enhancement to existing component or feature

Comments

@alamenai
Copy link

Tremor Version

latest

Link to minimal reproduction

.

Steps to reproduce

I have a NumberInput and I want the German number format. In German, they use comma , instead of . fr their float numbers.

Code

 const handleNumberInputChange = (property: string, value: number) => {

   // Currently, the user enters numbers in this format 1.1 | 2.2
  // However, I want him that format 1,1 | 2,2
    dispatch(updatePanelMeasures({ ...measures, [property]: value }))
  }

 <NumberInput
          icon={TextQuote}
          placeholder='1.1'
          max={1}
          min={0.1}
          step={0.1}
          className='mt-2 min-h-11'
          value={measures.border}
          onValueChange={(border) => handleNumberInputChange("border", border)}
        />

What is expected?

.

What is actually happening?

.

What browsers are you seeing the problem on?

No response

Any additional comments?

No response

@christopherkindl christopherkindl added the Type: Enhancement Small enhancement to existing component or feature label Jan 23, 2024
@CoHarsh
Copy link

CoHarsh commented Feb 18, 2024

This looks interesting.
I am wondering whether to extend this to German number format or make this general. @christopherkindl

@hikinine
Copy link

Would be awesome if we receive as optional props an "formatter" which represents Intl.NumberFormat constructor
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat

So we separate the render value from the reference value

return (
   <NumberInput  
        defaultValue={123456.79}
        formatter={ new Intl.NumberFormat('en-US', { style: 'currency', currency: "USD" }) } 
    />
)

  DISPLAY VALUE:  '$123,456.79'
  REF VALUE:   123456.79

I am available to work on this if needed.

@severinlandolt
Copy link
Member

Hi! @hikinine, this feature would be awesome! I assigned you to this, let me know if you need any help!

@hikinine
Copy link

Hi! @hikinine, this feature would be awesome! I assigned you to this, let me know if you need any help!

Wonderful, i'll keep you posted

@agustinzamar
Copy link

Hi! @hikinine I would love to have this feature, do you have any updates? Need an extra pair of hands to work on this?

@hikinine
Copy link

hikinine commented Aug 8, 2024

Hi! @hikinine I would love to have this feature, do you have any updates? Need an extra pair of hands to work on this?

Hey, would be good.
I open a pull request with a initial try to implement it. Take a look. #1111
I got some problems with UX to do it in the best way possible (which is edit the formatted value like editing a number... something like we used to do with regex to represente some number pattern as string)

Implemented some work around which is not the best UX solution, but works.

Lets move the discussion to #1111

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Enhancement Small enhancement to existing component or feature
Projects
None yet
Development

No branches or pull requests

6 participants