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

feat(NumberInput): add new component #1826

Merged
merged 37 commits into from
Nov 5, 2024
Merged
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
73af2c9
feat(NumberInput): added new component
DaryaLari Aug 28, 2024
e583ffe
chore(NumberInput): added stories
DaryaLari Aug 28, 2024
d54652c
test(NumberInput): added tests
DaryaLari Aug 28, 2024
724ce21
fix(NumberInput): endContent & controls
DaryaLari Sep 13, 2024
fa0ba06
chore(NumberInput): refactor stories
DaryaLari Sep 13, 2024
44b8ddd
fix(NumberInput): typo
DaryaLari Sep 13, 2024
6545bd2
chore(NumberInput): functional fixes
DaryaLari Sep 14, 2024
6a31cfa
docs(NumberInput): fix readme
DaryaLari Sep 14, 2024
9e0b465
test(NumberInput): visual tests added
DaryaLari Sep 16, 2024
c7ebde6
fix(NumberInput): fix displayed zeros with empty value
DaryaLari Sep 16, 2024
d459896
fixup! test(NumberInput): visual tests added
DaryaLari Sep 16, 2024
c8703df
fix(NumberInput): story item value update
DaryaLari Sep 16, 2024
a729aa7
fix(NumberInput): fix after rebase
DaryaLari Sep 18, 2024
971c829
fix(NumberInput): arrows width
DaryaLari Sep 19, 2024
baa6987
fix(NumberInput): inserting invalid string to the middle of number
DaryaLari Sep 19, 2024
ea8735d
chore(NumberInput): change value type to number and add clamping valu…
DaryaLari Sep 25, 2024
d00fa06
test: update snapshots
DaryaLari Sep 25, 2024
81c6e48
chore(NumberInput): move component to lab
DaryaLari Sep 26, 2024
0976903
fix(NumberInput): review fixes
DaryaLari Sep 27, 2024
f3588fb
docs(NumberInput): fix types in readme
DaryaLari Sep 30, 2024
71d2970
docs(NumberInput): add description of behaviour props to readme
DaryaLari Sep 30, 2024
2310174
fix(NumberInput): more review fixes
DaryaLari Sep 30, 2024
43e99ce
fix(NumberInput): duplicated arrows border style
DaryaLari Oct 1, 2024
3d31b0b
fix(NumberInput): add e.preventDefault, rename showControls, remove f…
DaryaLari Oct 2, 2024
d925f52
fix(NumberInput): fix clapting to step divisibles
DaryaLari Oct 2, 2024
b8cc572
fix(NumberInput): remove local step state
DaryaLari Oct 2, 2024
8fe03c0
chore(NumberInput): handle home/end btns press
DaryaLari Oct 2, 2024
1b28334
test(NumberInput): add tests on HOME/END press
DaryaLari Oct 3, 2024
510b110
fix(NumberInput): remove exporting default props from TextInput
DaryaLari Oct 3, 2024
400b324
fix(NumberInput): hide description&default columns from storybook con…
DaryaLari Oct 3, 2024
3853ffc
feat(NumberInput): support uncontrolled usage type
DaryaLari Oct 4, 2024
37fc976
chore(NumberInput): change input type in default story to uncontrolled
DaryaLari Oct 4, 2024
492b1a1
chore(NumberInput): change all other stiries' inputs to uncontrolled
DaryaLari Oct 4, 2024
6118814
fix(NumberInput): rename css-vars & add aria-hidden attr to arrows
DaryaLari Oct 29, 2024
463ef10
fix(NumberInput): fix formatting number on blur
DaryaLari Oct 29, 2024
b3496b0
fix(NumberInput): set inputMode to decimal with allowDecimal param
DaryaLari Oct 31, 2024
aed0787
fix(NumberInput): add rounding calculation result to step precision
DaryaLari Nov 1, 2024
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
Prev Previous commit
fix(NumberInput): add rounding calculation result to step precision
DaryaLari committed Nov 5, 2024
commit aed078724557488a18d9897684913cc43ed99635
Original file line number Diff line number Diff line change
@@ -113,7 +113,7 @@ describe('NumberInput input', () => {

it('removes redundant zeros on blur', async () => {
const handleUpdate = jest.fn();
render(<NumberInput allowDecimal onUpdate={handleUpdate} />);
render(<NumberInput allowDecimal step={0.1} onUpdate={handleUpdate} />);
const input = getInput();
input.focus();
fireEvent.change(getInput(), {target: {value: '00001.10000'}});
11 changes: 9 additions & 2 deletions src/components/lab/NumberInput/utils.ts
Original file line number Diff line number Diff line change
@@ -119,7 +119,8 @@ export function clampToNearestStepValue({
}) {
const base = originalMin || 0;
const min = originalMin ?? Number.MIN_SAFE_INTEGER;
let clampedValue = value;
let clampedValue = toFixedNumber(value, step);

if (clampedValue > max) {
clampedValue = max;
} else if (clampedValue < min) {
@@ -150,7 +151,8 @@ export function clampToNearestStepValue({
return greaterPossibleValue;
}
}
return clampedValue;

return toFixedNumber(clampedValue, step);
}

export function updateCursorPosition(
@@ -201,3 +203,8 @@ export function areStringRepresentationOfNumbersEqual(v1: string, v2: string) {
}
return false;
}

function toFixedNumber(value: number, baseStep: number): number {
const stepDecimalDigits = baseStep.toString().split('.')[1]?.length || 0;
return parseFloat(value.toFixed(stepDecimalDigits));
}
Loading