fixed use_intl_number_format fraction digits option

This commit is contained in:
Maccesch 2024-01-21 18:32:12 +00:00
parent 3a75c73767
commit 07f592b222
2 changed files with 21 additions and 14 deletions

View file

@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixes 🍕 ### Fixes 🍕
- Fixed `use_geolocation` SSR compile issue - Fixed `use_geolocation` SSR compile issue
- Fixed `use_intl_number_format` maximum fraction digits option
### Changes 🔥 ### Changes 🔥

View file

@ -659,10 +659,12 @@ pub struct UseIntlNumberFormatOptions {
maximum_fraction_digits: Option<u8>, maximum_fraction_digits: Option<u8>,
/// The minimum number of significant digits to use. Possible values are from 1 to 21; the default is 1. /// The minimum number of significant digits to use. Possible values are from 1 to 21; the default is 1.
minimum_significant_digits: u8, #[builder(into)]
minimum_significant_digits: Option<u8>,
/// The maximum number of significant digits to use. Possible values are from 1 to 21; the default is 21. /// The maximum number of significant digits to use. Possible values are from 1 to 21; the default is 21.
maximum_significant_digits: u8, #[builder(into)]
maximum_significant_digits: Option<u8>,
} }
impl UseIntlNumberFormatOptions { impl UseIntlNumberFormatOptions {
@ -700,8 +702,8 @@ impl Default for UseIntlNumberFormatOptions {
minimum_integer_digits: 1, minimum_integer_digits: 1,
minimum_fraction_digits: None, minimum_fraction_digits: None,
maximum_fraction_digits: None, maximum_fraction_digits: None,
minimum_significant_digits: 1, minimum_significant_digits: None,
maximum_significant_digits: 21, maximum_significant_digits: None,
} }
} }
} }
@ -785,16 +787,20 @@ impl From<UseIntlNumberFormatOptions> for js_sys::Object {
); );
} }
let _ = Reflect::set( if let Some(minimum_significant_digits) = options.minimum_significant_digits {
&obj, let _ = Reflect::set(
&"minimumSignificantDigits".into(), &obj,
&options.minimum_significant_digits.into(), &"minimumSignificantDigits".into(),
); &minimum_significant_digits.into(),
let _ = Reflect::set( );
&obj, }
&"maximumSignificantDigits".into(), if let Some(maximum_significant_digits) = options.maximum_significant_digits {
&options.maximum_significant_digits.into(), let _ = Reflect::set(
); &obj,
&"maximumSignificantDigits".into(),
&maximum_significant_digits.into(),
);
}
obj obj
} }