Skip to content

Commit

Permalink
fix(ui-library): changed to develop code
Browse files Browse the repository at this point in the history
  • Loading branch information
ashk1996 committed Nov 29, 2024
1 parent 4a0cbd0 commit ade8d8f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const defaultParams: BlrInputFieldNumberType = {
sizeVariant: 'md',
stepperVariant: 'vertical',
placeholder: 'Placeholder-text',
value: undefined,
value: 0,
decimals: 0,
leadingZeros: 0,
unit: undefined,
Expand All @@ -44,7 +44,6 @@ const defaultParams: BlrInputFieldNumberType = {
stepDecreaseAriaLabel: '\u2212',
inputFieldNumberId: 'inputFieldNumberId',
name: 'inputFieldNumber',
isInitialized: false,
};

export default {
Expand Down
22 changes: 7 additions & 15 deletions packages/ui-library/src/components/input-field-number/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export class BlrInputFieldNumber extends LitElementCustom {

@property() accessor theme: ThemeType = 'Light_value';

@state() protected accessor currentValue: number | undefined;
@state() protected accessor currentValue = 0;
@state() protected accessor isFocused = false;

protected stepperUp(event: MouseEvent) {
Expand Down Expand Up @@ -106,9 +106,7 @@ export class BlrInputFieldNumber extends LitElementCustom {

connectedCallback() {
super.connectedCallback();
if (this.currentValue === undefined) {
this.currentValue = this.value !== undefined ? this.value : undefined;
}
this.currentValue = Number(this.currentValue) || Number(this.value) || 0;
}

protected handleFocus = (event: FocusEvent) => {
Expand Down Expand Up @@ -138,18 +136,12 @@ export class BlrInputFieldNumber extends LitElementCustom {
}

protected customFormat(cur: number, fractions: number, digits: number): string {
const numberValue = isNaN(Number(cur)) ? 0 : Number(cur);

if (typeof numberValue !== 'number' || isNaN(numberValue)) {
return '0';
}

const formattedNumber = numberValue.toFixed(fractions);
const formattedNumber = cur.toFixed(fractions);
const [integerPart, fractionPart] = formattedNumber.split('.');

let paddedInteger = integerPart;
if (digits > 0) {
paddedInteger = '0'.repeat(digits - integerPart.length) + integerPart;
paddedInteger = '0'.repeat(digits) + integerPart;
}
return `${paddedInteger}${fractionPart ? `.${fractionPart}` : ''}`;
}
Expand Down Expand Up @@ -329,9 +321,9 @@ export class BlrInputFieldNumber extends LitElementCustom {
id="${this.inputFieldNumberId}"
class="${inputClasses}"
type="number"
.value=${!this.currentValue && this.currentValue !== 0
? ''
: this.customFormat(Number(this.currentValue), this.decimals || 0, this.leadingZeros || 0)}
.value=${this.currentValue != 0
? this.customFormat(this.currentValue || 0, this.decimals || 0, this.leadingZeros || 0)
: ''}
step="${this.step !== undefined ? this.step : 1}"
?disabled="${this.disabled}"
?readonly="${this.readonly}"
Expand Down

0 comments on commit ade8d8f

Please sign in to comment.