Skip to content

Commit

Permalink
fix(TextField) number arrow not triggering change (#1099)
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlosLevir authored Oct 27, 2022
1 parent edc1da8 commit 51e5c8d
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions packages/matchbox/src/components/TextField/TextField.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useRef } from 'react';
import React, { ChangeEvent, useRef } from 'react';
import { tokens } from '@sparkpost/design-tokens';
import { compose, margin, MarginProps, maxWidth, MaxWidthProps } from 'styled-system';
import { omit } from '@styled-system/props';
Expand Down Expand Up @@ -26,7 +26,7 @@ const StyledInputWrapper = styled(Box)`
${focusOutline({ modifier: '&:focus-within', offset: '2px' })}
`;

const StyledInput = styled(Box)<BoxProps>`
const StyledInput = styled(Box) <BoxProps>`
outline: none;
&[type='number'],
&[type='number']::-webkit-inner-spin-button,
Expand All @@ -42,7 +42,7 @@ const StyledButton = styled.button<
cursor: pointer;
`;

const StyledNumberControls = styled(Box)<BoxProps & { $disabled?: boolean }>`
const StyledNumberControls = styled(Box) <BoxProps & { $disabled?: boolean }>`
padding: 0 6px;
position: absolute;
right: 0;
Expand Down Expand Up @@ -72,15 +72,17 @@ const FieldBox = React.forwardRef<HTMLInputElement, FieldBoxProps>(function Fiel
props,
userRef,
) {
const { hasError, disabled, height, type, lineHeight, required, py, ...rest } = props;
const { hasError, disabled, height, type, lineHeight, required, py, onChange, ...rest } = props;

const inputRef = useRef<HTMLInputElement>(null);

const increment = () => {
inputRef.current.stepUp();
onChange({ target: inputRef.current } as ChangeEvent<HTMLInputElement>);
};
const decrement = () => {
inputRef.current.stepDown();
onChange({ target: inputRef.current } as ChangeEvent<HTMLInputElement>);
};

return (
Expand All @@ -89,6 +91,7 @@ const FieldBox = React.forwardRef<HTMLInputElement, FieldBoxProps>(function Fiel
aria-invalid={!!hasError}
as="input"
px="400"
onChange={onChange}
{...rest}
type={type}
disabled={disabled}
Expand Down

0 comments on commit 51e5c8d

Please sign in to comment.