Skip to content
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

Fix/number input #841

Merged
merged 4 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ export const { tokenizedLight: StepperComboLight, tokenizedDark: StepperComboDar
padding: 0;

background-color: ${StepperButton.Container.BackgroundColor.Rest};
color: ${StepperButton.Icon.IconColor.Rest}
color: ${StepperButton.Icon.IconColor.Rest};

&:hover:not(:disabled) {
background-color: ${StepperButton.Container.BackgroundColor.Hover};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ const sharedStyles = html`
`;

const defaultParams: BlrNumberInputType = {
theme: 'Light',
size: 'md',
stepperVariant: 'vertical',
placeholder: 'Placeholder-text',
value: undefined,
fractionDigits: 0,
totalDigits: 0,
decimals: 0,
leadingZeros: 0,
prependUnit: true,
unit: 'kg',
step: 1,
Expand All @@ -41,7 +42,6 @@ const defaultParams: BlrNumberInputType = {
errorMessage: '',
errorIcon: undefined,
numberInputId: 'test-id',
theme: 'Light',
};

export default {
Expand All @@ -55,6 +55,13 @@ export default {
onBlur: () => action('onBlur'),
},
argTypes: {
theme: {
options: Themes,
control: { type: 'select' },
table: {
category: 'Appearance',
},
},
size: {
name: 'sizeVariant',
description: ' Choose size of the component. ',
Expand Down Expand Up @@ -95,7 +102,7 @@ export default {
category: 'Content / Settings',
},
control: {
type: 'text',
type: 'number',
label: 'Enter Text',
},
},
Expand Down Expand Up @@ -322,13 +329,6 @@ export default {
category: 'Events',
},
},
theme: {
options: Themes,
control: { type: 'select' },
table: {
category: 'Appearance',
},
},
},
parameters: {
design: {
Expand Down Expand Up @@ -544,7 +544,7 @@ export const Readonly = () => {
label: 'Readonly',
readonly: true,
labelAppendix: undefined,
fractionDigits: 1,
decimals: 1,
value: 20.2,
})}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,22 @@ describe('blr-number-input', () => {

expect(className).to.contain('sm');
});

it('correctly formats the value when leading zeros are set', async () => {
const element = await fixture(BlrNumberInputRenderFunction({ ...sampleParams, leadingZeros: 2 }));

const input = querySelectorDeep('input', element.getRootNode() as HTMLElement);
const numberValue = input?.value;

expect(numberValue).to.be.equal('004');
});

it('correctly formats the value when decimal places are set', async () => {
const element = await fixture(BlrNumberInputRenderFunction({ ...sampleParams, decimals: 2 }));

const input = querySelectorDeep('input', element.getRootNode() as HTMLElement);
const numberValue = input?.value;

expect(numberValue).to.be.equal('4.00');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ export class BlrNumberInput extends LitElement {

let paddedInteger = integerPart;
if (digits > 0) {
const padding = Math.max(digits - integerPart.length, 0);
paddedInteger = '0'.repeat(padding) + integerPart;
paddedInteger = '0'.repeat(digits) + integerPart;
}
return `${paddedInteger}${fractionPart ? `.${fractionPart}` : ''}`;
}
Expand Down
Loading