-
Notifications
You must be signed in to change notification settings - Fork 23
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
feat(components/core): allow currencyDisplay
to be specified for SkyNumericOptions
#2817
base: main
Are you sure you want to change the base?
feat(components/core): allow currencyDisplay
to be specified for SkyNumericOptions
#2817
Conversation
☁️ Nx Cloud ReportCI is running/has finished running commands for commit d87be91. As they complete they will appear below. Click to see the status, the terminal output, and the build insights. 📂 See all runs for this CI Pipeline Execution ✅ Successfully ran 2 targetsSent with 💌 from NxCloud. |
@@ -32,7 +32,7 @@ export class SkyNumberFormatUtility { | |||
style: SkyIntlNumberFormatStyle, | |||
digits?: string | null, | |||
currency: string | null = null, | |||
currencyAsSymbol = false, | |||
currencyDisplay: 'code' | 'symbol' | 'narrowSymbol' | 'name' = 'symbol', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The previous default of false
would have set the currencyDisplay
to code
. Can we update this default to match the previous behavior?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit surprised this isn't failing any unit tests. The percent pipe does not send a default for currencyAsSymbol
which would have resulted in code
under the current code. But with this - the percent pipe would now end up with symbol
if I'm reading everything correctly. I would like to maintain the current defaults if possible (where the percent pipe uses code
and the numeric service defaults to symbol
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason all the tests show it working as expected is because currency display options don't impact the percent pipe. But I can see the benefit in drawing the consistency a bit tighter in the code. I'll make a couple of tweaks.
currencyDisplay
to be specified for SkyNumericOptions
Internally, the SkyNumericPipe and SkyNumericService use Intl to format number as currency. When the language locale specified, such as en-CA, does not naturally line up with the ISO4217 currency code's locale, such as USD, the default behavior is to format the currency using an unambiguous currency symbol, US$.
In certain scenarios, this more verbose display is not desired. The current default inside skyux is to use the 'symbol' notation, which drives this behavior. However, Intl provides an alternative display setting, 'narrowSymbol', which would only display $ in this scenario.
Currently, consumers are not able to choose this option.
The scope of this PR is to expose currencyDisplay directly on SkyNumberOptions to give consumers the ability to choose this alternate display option.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#narrowsymbol