Skip to content

NumberField decrement converts negative to positive #9059

@patrik-csak

Description

@patrik-csak

Provide a general summary of the issue here

When setting signDisplay to "never", <NumberField>'s decrement button converts negative values to positive, resulting in an incorrect post-decrement value

🤔 Expected Behavior?

Negative values should remain negative

😯 Current Behavior

Negative values are converted to positive

💁 Possible Solution

No response

🔦 Context

No response

🖥️ Steps to Reproduce

https://stackblitz.com/edit/vitejs-vite-xxqht6jk?file=src%2FApp.jsx

import { useState } from 'react';
import {
  NumberField,
  Label,
  Group,
  Input,
  Button,
} from 'react-aria-components';

function App() {
  const [showSign, setShowSign] = useState(true);
  const [value, setValue] = useState(0);

  return (
    <>
      <div>
        <input
          id="show-sign"
          type="checkbox"
          checked={showSign}
          onChange={(event) => setShowSign(event.target.checked)}
        />
        <label htmlFor="show-sign">Show sign</label>
      </div>
      <hr />
      <NumberField
        formatOptions={{ signDisplay: showSign ? 'auto' : 'never' }}
        onChange={setValue}
        value={value}
      >
        <Label>Value: {value}</Label>
        <Group>
          <Button slot="decrement">-</Button>
          <Input />
          <Button slot="increment">+</Button>
        </Group>
      </NumberField>
    </>
  );
}

export default App;

To reproduce:

  1. Set value to 0
  2. Check 'Show sign'
  3. Decrement value twice
    • Notice that value decrements in the negative direction correctly: 0-1-2
  4. Set value to 0
  5. Uncheck 'Show sign'
  6. Decrement value twice
    • Notice that value is not correctly decremented: 0-10

Version

[email protected]

What browsers are you seeing the problem on?

Safari

If other, please specify.

No response

What operating system are you using?

macOS Tahoe 26.1

🧢 Your Company/Team

No response

🕷 Tracking Issue

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions