Skip to content

Commit f08b17d

Browse files
RocssrmanolesnowystingerLFDanLu
authored
feat: add support for Devanagari & Bengali decimal numbering systems (#6715)
* feat: add support for Devanagari & Bengali decimal numbering systems * Update docs & tests * Update packages/react-aria-components/docs/NumberField.mdx Co-authored-by: Robert Snow <[email protected]> --------- Co-authored-by: rmanole <[email protected]> Co-authored-by: Robert Snow <[email protected]> Co-authored-by: Daniel Lu <[email protected]>
1 parent 791f9c5 commit f08b17d

File tree

7 files changed

+36
-4
lines changed

7 files changed

+36
-4
lines changed

packages/@internationalized/number/src/NumberParser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ interface Symbols {
2323
}
2424

2525
const CURRENCY_SIGN_REGEX = new RegExp('^.*\\(.*\\).*$');
26-
const NUMBERING_SYSTEMS = ['latn', 'arab', 'hanidec'];
26+
const NUMBERING_SYSTEMS = ['latn', 'arab', 'hanidec', 'deva', 'beng'];
2727

2828
/**
2929
* A NumberParser can be used to perform locale-aware parsing of numbers from Unicode strings,

packages/@internationalized/number/test/NumberParser.test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,14 @@ describe('NumberParser', function () {
424424

425425
expect(new NumberParser('en-US', {style: 'decimal'}).getNumberingSystem('一二')).toBe('hanidec');
426426
expect(new NumberParser('en-US', {style: 'decimal'}).getNumberingSystem('一二.五')).toBe('hanidec');
427+
428+
expect(new NumberParser('en-US', {style: 'decimal'}).getNumberingSystem('१२३४')).toBe('deva');
429+
expect(new NumberParser('en-US', {style: 'decimal'}).getNumberingSystem('१२४,२')).toBe('deva');
430+
expect(new NumberParser('en-US', {style: 'decimal'}).getNumberingSystem('२.३५१')).toBe('deva');
431+
432+
expect(new NumberParser('en-US', {style: 'decimal'}).getNumberingSystem('১২৩')).toBe('beng');
433+
expect(new NumberParser('en-US', {style: 'decimal'}).getNumberingSystem('১.২৫৩')).toBe('beng');
434+
expect(new NumberParser('en-US', {style: 'decimal'}).getNumberingSystem('১২৮,৪')).toBe('beng');
427435
});
428436
});
429437
});

packages/@react-spectrum/numberfield/test/NumberField.test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2020,6 +2020,28 @@ describe('NumberField', function () {
20202020
expect(textField).toHaveAttribute('value', formatter.format(21));
20212021
});
20222022

2023+
it.each(locales)('%s can have devanagari numerals entered', async (locale) => {
2024+
let {textField} = renderNumberField({onChange: onChangeSpy, formatOptions: {style: 'currency', currency: 'USD'}}, {locale});
2025+
2026+
act(() => {textField.focus();});
2027+
await user.keyboard('२१');
2028+
act(() => {textField.blur();});
2029+
2030+
let formatter = new Intl.NumberFormat(locale + '-u-nu-deva', {style: 'currency', currency: 'USD'});
2031+
expect(textField).toHaveAttribute('value', formatter.format(21));
2032+
});
2033+
2034+
it.each(locales)('%s can have bengali numerals entered', async (locale) => {
2035+
let {textField} = renderNumberField({onChange: onChangeSpy, formatOptions: {style: 'currency', currency: 'USD'}}, {locale});
2036+
2037+
act(() => {textField.focus();});
2038+
await user.keyboard('২১');
2039+
act(() => {textField.blur();});
2040+
2041+
let formatter = new Intl.NumberFormat(locale + '-u-nu-beng', {style: 'currency', currency: 'USD'});
2042+
expect(textField).toHaveAttribute('value', formatter.format(21));
2043+
});
2044+
20232045
describe('beforeinput', () => {
20242046
let getTargetRanges = InputEvent.prototype.getTargetRanges;
20252047
beforeEach(() => {

packages/dev/docs/pages/react-aria/home/I18n.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,8 @@ export function I18n() {
186186
<SelectItem id="latn">Latin</SelectItem>
187187
<SelectItem id="arab">Arabic</SelectItem>
188188
<SelectItem id="hanidec">Hanidec</SelectItem>
189+
<SelectItem id="deva">Devanagari</SelectItem>
190+
<SelectItem id="beng">Bengali</SelectItem>
189191
</Select>
190192
<Select label="Number Format" selectedKey={numberFormat} onSelectionChange={updateNumberFormat}>
191193
<SelectItem id="decimal">Decimal</SelectItem>

packages/dev/docs/pages/react-aria/index.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ import {A11y} from './home/A11y';
414414

415415
<Section className="orange-gradient-background">
416416
<h2><GradientText>Ready for an</GradientText> <span className="bg-clip-text bg-gradient-to-b from-yellow-500 to-orange-600">international</span> <GradientText>audience.</GradientText></h2>
417-
<p>React Aria is engineered for internationalization out of the box, including translations in over 30 languages, localized date and number formatting and parsing, support for 13 calendar systems, 3 numbering systems, right-to-left layout, and more.</p>
417+
<p>React Aria is engineered for internationalization out of the box, including translations in over 30 languages, localized date and number formatting and parsing, support for 13 calendar systems, 5 numbering systems, right-to-left layout, and more.</p>
418418
<LearnMoreLink href="internationalization.html" className="text-orange-700 dark:text-orange-600 hover:bg-orange-400/[15%]" />
419419

420420
```tsx snippet

packages/react-aria-components/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Over 40 components with built-in behavior, adaptive interactions, top-tier acces
77
* 🎨 **Styleable** – React Aria is style-free out of the box, allowing you to build custom designs to fit your application or design system using any styling and animation solution. Each component is broken down into individual parts with built-in states, render props, and slots that make styling a breeze.
88
* 📱 **Adaptive** – React Aria ensures a great experience for users, no matter their device. All components are optimized for mouse, touch, keyboard, and screen reader interactions, with a meticulous attention to detail that makes your app feel responsive and natural on every platform.
99
* ♿️ **Accessible** – React Aria is designed with accessibility as a top priority, and battle tested in production applications. All components are built to work across a wide variety of devices and assistive technologies to ensure the best experience possible for all users.
10-
* 🌍 **International** – React Aria is engineered for internationalization out of the box, including translations in over 30 languages, localized date and number formatting and parsing, support for 13 calendar systems, 3 numbering systems, right-to-left layout, and more.
10+
* 🌍 **International** – React Aria is engineered for internationalization out of the box, including translations in over 30 languages, localized date and number formatting and parsing, support for 13 calendar systems, 5 numbering systems, right-to-left layout, and more.
1111
* ⚙️ **Customizable** – React Aria offers a flexible and scalable API that lets you dive as deep into the details as you like. Start with high-level components with a built-in DOM structure and simple styling API, compose custom patterns with contexts, and for the ultimate control, drop down to the low-level Hook-based API. Mix and match as needed.
1212

1313
## Documentation

packages/react-aria-components/docs/NumberField.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ the stepper buttons. `NumberField` helps achieve accessible number fields that s
128128
formatting options and can be styled as needed.
129129

130130
* **Customizable formatting** – Support for internationalized number formatting and parsing including decimals, percentages, currency values, and units. Multiple currency formats are supported, including symbol, code, and name in standard or accounting notation.
131-
* **International** – Support for the Latin, Arabic, and Han positional decimal numbering systems in [over 30 locales](internationalization.html#supported-locales). The numbering system is automatically detected from user input, and input method editors such as Pinyin are supported.
131+
* **International** – Support for the Latin, Arabic, Devanagari, Bengali, and Han positional decimal numbering systems in [over 30 locales](internationalization.html#supported-locales). The numbering system is automatically detected from user input, and input method editors such as Pinyin are supported.
132132
* **Validation** – Keyboard input is validated as the user types so that only numeric input is accepted, according to the locale and numbering system. Values are automatically rounded and clamped according to configurable decimal, minimum, maximum, and step values. Custom client and server-side validation is also supported.
133133
* **Mobile friendly** – An appropriate software keyboard is automatically selected based on the allowed values for ease of use.
134134
* **Accessible** – Follows the [spinbutton](https://www.w3.org/WAI/ARIA/apg/patterns/spinbutton/) ARIA pattern, with support for arrow keys, scroll wheel, and stepper buttons to increment and decrement the value. Extensively tested across many devices and [assistive technologies](accessibility.html#testing) to ensure announcements and behaviors are consistent.

0 commit comments

Comments
 (0)