@@ -45,6 +45,7 @@ import NumberFormat from "@ui5/webcomponents-localization/dist/NumberFormat.js";
4545import StepInputCss from "./generated/themes/StepInput.css.js" ;
4646import getCachedLocaleDataInstance from "@ui5/webcomponents-localization/dist/getCachedLocaleDataInstance.js" ;
4747import getLocale from "@ui5/webcomponents-base/dist/locale/getLocale.js" ;
48+ import { attachLanguageChange , detachLanguageChange } from "@ui5/webcomponents-base/dist/locale/languageChange.js" ;
4849
4950// Spin variables
5051const INITIAL_WAIT_TIMEOUT = 500 ; // milliseconds
@@ -301,6 +302,10 @@ class StepInput extends UI5Element implements IFormInputElement {
301302
302303 _formatter ?: NumberFormat ;
303304
305+ _languageChangeHandler ?: ( lang : string ) => Promise < void > ;
306+
307+ _languageChanged ?: boolean = false ;
308+
304309 @i18n ( "@ui5/webcomponents" )
305310 static i18nBundle : I18nBundle ;
306311
@@ -363,6 +368,11 @@ class StepInput extends UI5Element implements IFormInputElement {
363368 }
364369
365370 get _displayValue ( ) {
371+ if ( this . _languageChanged ) {
372+ this . _languageChanged = false ;
373+ this . valueState = ValueState . None ; // to reset the value state visual
374+ return this . _formatNumber ( this . value ) ;
375+ }
366376 // For the cases when there is set value precision but the input value is not with correct precision we don't need to format it
367377 const value = this . input ?. value && ! this . _isValueWithCorrectPrecision ? this . input . value : this . _formatNumber ( this . value ) ;
368378 if ( ( this . value === 0 ) || ( Number . isInteger ( this . value ) ) ) {
@@ -394,6 +404,34 @@ class StepInput extends UI5Element implements IFormInputElement {
394404 onBeforeRendering ( ) {
395405 this . _setButtonState ( ) ;
396406 }
407+ onEnterDOM ( ) {
408+ this . _setupLanguageChangeHandler ( ) ;
409+ }
410+
411+ onExitDOM ( ) {
412+ this . _cleanupLanguageChangeHandler ( ) ;
413+ }
414+
415+ _setupLanguageChangeHandler ( ) {
416+ if ( this . _languageChangeHandler ) {
417+ return ;
418+ }
419+
420+ this . _languageChangeHandler = ( ) => {
421+ this . _formatter = undefined ;
422+ this . _languageChanged = true ;
423+
424+ return Promise . resolve ( ) ;
425+ } ;
426+ attachLanguageChange ( this . _languageChangeHandler ) ;
427+ }
428+
429+ _cleanupLanguageChangeHandler ( ) {
430+ if ( this . _languageChangeHandler ) {
431+ detachLanguageChange ( this . _languageChangeHandler ) ;
432+ this . _languageChangeHandler = undefined ;
433+ }
434+ }
397435
398436 get formatter ( ) : NumberFormat {
399437 if ( ! this . _formatter ) {
@@ -563,16 +601,15 @@ class StepInput extends UI5Element implements IFormInputElement {
563601 }
564602
565603 get _isValueWithCorrectPrecision ( ) {
604+ const localeData = getCachedLocaleDataInstance ( getLocale ( ) ) ;
605+ // gets either "." or "," as delimiter which is based on locale, and splits the number by it
606+ const delimiter = localeData . getNumberSymbol ( "decimal" ) || "." ;
566607 // check if the value will be displayed with correct precision
567608 // _displayValue has special formatting logic
568- if ( this . valuePrecision === 0 && ( ( this . value === 0 ) || ( Number . isInteger ( this . value ) ) ) ) {
609+ if ( this . valuePrecision === 0 && ! this . input ?. value . includes ( delimiter ) && ( ( this . value === 0 ) || ( Number . isInteger ( this . value ) ) ) ) {
569610 // integers and zero will be formatted with toFixed, so thex y're always valid
570611 return true ;
571612 }
572-
573- const localeData = getCachedLocaleDataInstance ( getLocale ( ) ) ;
574- // gets either "." or "," as delimiter which is based on locale, and splits the number by it
575- const delimiter = localeData ?. getNumberSymbol ( "decimal" ) || "." ;
576613 const numberParts = this . input ?. value ?. split ( delimiter ) ;
577614 const decimalPartLength = numberParts ?. length > 1 ? numberParts [ 1 ] . length : 0 ;
578615
0 commit comments