Skip to content

Commit

Permalink
fix(InputWrapper): should only show invalid variant when field is inv…
Browse files Browse the repository at this point in the history
…alid (#502)
  • Loading branch information
framitdavid authored Jun 6, 2023
1 parent 69d74b2 commit 556515c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
28 changes: 28 additions & 0 deletions packages/react/src/components/_InputWrapper/InputWrapper.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,34 @@ describe('InputWrapper', () => {
'aria-describedby',
);
});

it('should display error variant when character-limit exceeds', () => {
render({
label: 'Comment',
value: 'Hello',
characterLimit: {
maxCount: 2,
label: (count: number) => `${count} signs left`,
srLabel: '2 signs allowed',
},
});

expect(screen.queryByTestId('input-icon-error')).toBeInTheDocument();
});

it('should not display error variant when 0 characters left', () => {
render({
label: 'Comment',
value: 'He',
characterLimit: {
maxCount: 2,
label: (count: number) => `${count} signs left`,
srLabel: '2 signs allowed',
},
});

expect(screen.queryByTestId('input-icon-error')).not.toBeInTheDocument();
});
});
});

Expand Down
3 changes: 2 additions & 1 deletion packages/react/src/components/_InputWrapper/InputWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,12 @@ export const InputWrapper = ({
? autoCharLimitIdGenerated
: undefined;
const currentInputValue = value ? value.toString() : '';

const { variant, iconVariant } = getVariant({
disabled,
isSearch,
isValid: characterLimit
? currentInputValue.length < characterLimit.maxCount && isValid
? currentInputValue.length <= characterLimit.maxCount && isValid
: isValid,
readOnly,
});
Expand Down

0 comments on commit 556515c

Please sign in to comment.